From ae4feb8b9d5049cf440d952510f714a65e00b218 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Fri, 28 Oct 2022 12:06:07 +0200 Subject: [PATCH] better management of nightly version to improve compile times --- src/common/CMakeLists.txt | 22 +++++++++++------- src/common/globals.cpp | 16 ++++++++++++- src/common/globals.h | 7 ++++++ src/common/meshlab-common.qrc | 3 ++- src/common/ml_document/mesh_model.cpp | 4 ++-- src/common/mlapplication.cpp | 2 +- src/common/resources/git_sha.txt | 0 .../{img => resources/images}/dummy.png | Bin src/common/utilities/load_save.cpp | 2 +- src/meshlab/main.cpp | 2 +- 10 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 src/common/resources/git_sha.txt rename src/common/{img => resources/images}/dummy.png (100%) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index bbe7f2930..cc9be2034 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -5,13 +5,14 @@ if (MESHLAB_IS_NIGHTLY_VERSION) # nightly version is in the form: # YYYY.mm[d]_nightly_GIT_SHA1 # YYYY and mm are computed by cmake and not read from file + # the GIT_SHA1 is stored in file, which will be read at runtime find_package(Git) execute_process(COMMAND "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=7 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_SHA1 ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - set(MESHLAB_VERSION "${MESHLAB_VERSION}_nightly_${GIT_SHA1}") + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/resources/git_sha.txt ${GIT_SHA1}) else() if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../ML_VERSION") # YYYY and mm are read from file @@ -19,18 +20,17 @@ else() endif() endif() -# if double precision version, "d" is inserted after 7 chars (YYYY.mmd*) if (BUILD_WITH_DOUBLE_SCALAR) - string(LENGTH ${MESHLAB_VERSION} MLV_LEN) - MATH(EXPR MLV_POSTFIX_LEN "${MLV_LEN}-7") # how many chars there are adter YYYY.mm - string(SUBSTRING ${MESHLAB_VERSION} 0 7 MLV_PREFIX) - string(SUBSTRING ${MESHLAB_VERSION} 7 ${MLV_POSTFIX_LEN} MLV_POSTFIX) - set(MESHLAB_VERSION "${MLV_PREFIX}d${MLV_POSTFIX}") + set(MESHLAB_VERSION "${MESHLAB_VERSION}d") endif() set(MESHLAB_VERSION ${MESHLAB_VERSION} PARENT_SCOPE) -message(STATUS "MeshLab version: ${MESHLAB_VERSION}") +if (MESHLAB_IS_NIGHTLY_VERSION) + message(STATUS "MeshLab version: ${MESHLAB_VERSION}_nightly_${GIT_SHA1}") +else() + message(STATUS "MeshLab version: ${MESHLAB_VERSION}") +endif() if (BUILD_WITH_DOUBLE_SCALAR) message(STATUS "Building with double precision") @@ -138,6 +138,12 @@ target_compile_definitions(meshlab-common MESHLAB_VERSION=${MESHLAB_VERSION} MESHLAB_SCALAR=${MESHLAB_SCALAR}) +if (MESHLAB_IS_NIGHTLY_VERSION) + target_compile_definitions(meshlab-common + PUBLIC + MESHLAB_IS_NIGHTLY) +endif() + target_include_directories(meshlab-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/common/globals.cpp b/src/common/globals.cpp index 5a7892951..c83afc3e3 100644 --- a/src/common/globals.cpp +++ b/src/common/globals.cpp @@ -124,7 +124,7 @@ QString meshlab::defaultShadersPath() QString meshlab::logDebugFileName() { static QString filename = QDir::homePath() + "/MeshLab" + - QString::fromStdString(meshlab::meshlabVersion()) + " " + + QString::fromStdString(meshlab::meshlabCompleteVersion()) + " " + QDateTime::currentDateTime().toString() + ".log"; return filename; } @@ -147,6 +147,20 @@ ActionSearcher& meshlab::actionSearcherInstance() return as; } +std::string meshlab::meshlabCompleteVersion() +{ + std::string ver = meshlabVersion(); +#ifdef MESHLAB_IS_NIGHTLY + QFile f(":/resources/git_sha.txt"); + if (f.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&f); + ver += "_nightly_" + in.readAll().toStdString(); + f.close(); + } +#endif + return ver; +} + pymeshlab::FunctionSet& pymeshlab::functionSetInstance() { static FunctionSet fs(meshlab::pluginManagerInstance()); diff --git a/src/common/globals.h b/src/common/globals.h index 1d073b931..daa86fd8b 100644 --- a/src/common/globals.h +++ b/src/common/globals.h @@ -28,6 +28,11 @@ #define mlstringify(a) #a #include +#ifdef MESHLAB_IS_NIGHTLY +#include +#include +#endif + #ifndef MESHLAB_VERSION #error "MESHLAB_VERSION needs to be defined!" #endif @@ -57,6 +62,8 @@ inline std::string meshlabVersion() return std::string(meshlab_xstr(MESHLAB_VERSION)); } +std::string meshlabCompleteVersion(); + inline bool builtWithDoublePrecision() { return std::string(meshlab_xstr(MESHLAB_SCALAR)) == std::string("double"); diff --git a/src/common/meshlab-common.qrc b/src/common/meshlab-common.qrc index e7301593c..2d3c3292e 100644 --- a/src/common/meshlab-common.qrc +++ b/src/common/meshlab-common.qrc @@ -1,5 +1,6 @@ - img/dummy.png + resources/images/dummy.png + resources/git_sha.txt diff --git a/src/common/ml_document/mesh_model.cpp b/src/common/ml_document/mesh_model.cpp index a9f1980aa..2a4841a1f 100644 --- a/src/common/ml_document/mesh_model.cpp +++ b/src/common/ml_document/mesh_model.cpp @@ -87,7 +87,7 @@ QString MeshModel::relativePathName(const QString& path) const * and these names will be mapped with the actual loaded image in the map * "textures". * - * When a texture is not found, a dummy texture will be used (":/img/dummy.png"). + * When a texture is not found, a dummy texture will be used (":/resources/images/dummy.png"). * * Returns the list of non-loaded textures that have been modified with * ":/img/dummy.png" in the contained mesh. @@ -99,7 +99,7 @@ std::list MeshModel::loadTextures( std::list unloadedTextures; for (std::string& textName : cm.textures){ if (textures.find(textName) == textures.end()){ - QImage img(":/img/dummy.png"); + QImage img(":/resources/images/dummy.png"); QFileInfo finfo(QString::fromStdString(textName)); try { img = meshlab::loadImage(finfo.absoluteFilePath(), log, cb); diff --git a/src/common/mlapplication.cpp b/src/common/mlapplication.cpp index 4e1297988..ecd1af201 100644 --- a/src/common/mlapplication.cpp +++ b/src/common/mlapplication.cpp @@ -42,7 +42,7 @@ bool MeshLabApplication::notify( QObject * rec, QEvent * ev ) const QString MeshLabApplication::appVer() { - return QString::fromStdString(meshlab::meshlabVersion()); + return QString::fromStdString(meshlab::meshlabCompleteVersion()); } const QString MeshLabApplication::compilerVersion() diff --git a/src/common/resources/git_sha.txt b/src/common/resources/git_sha.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/common/img/dummy.png b/src/common/resources/images/dummy.png similarity index 100% rename from src/common/img/dummy.png rename to src/common/resources/images/dummy.png diff --git a/src/common/utilities/load_save.cpp b/src/common/utilities/load_save.cpp index 5ff04a667..f0c6f69f9 100644 --- a/src/common/utilities/load_save.cpp +++ b/src/common/utilities/load_save.cpp @@ -339,7 +339,7 @@ QImage loadImage(const QString& filename, GLLogStream* log, vcg::CallBackPos* cb QImage getDummyTexture() { - return QImage(":/img/dummy.png"); + return QImage(":/resources/images/dummy.png"); } void saveImage( diff --git a/src/meshlab/main.cpp b/src/meshlab/main.cpp index 987e43ba2..399d60f22 100644 --- a/src/meshlab/main.cpp +++ b/src/meshlab/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) return 0; } if (versOpt1==argv[1] || versOpt2==argv[1]){ - std::cout << "MeshLab " << meshlab::meshlabVersion() << "\n"; + std::cout << "MeshLab " << meshlab::meshlabCompleteVersion() << "\n"; return 0; } }