From 9568fc082ff8e76d56cd6cb8548a50cbb01fdc6f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jul 2020 14:59:36 +0200 Subject: [PATCH 1/4] [calamares] Try to reduce compile-churn with version header - Very rarely do we need the full-git-version of Calamares, so split that into a separate header with a little trickery. - In the "normal" version header, drop the full-git-version values. --- CMakeLists.txt | 6 +++++- src/calamares/CalamaresVersion.h.in | 2 +- src/calamares/CalamaresVersionX.h.in | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/calamares/CalamaresVersionX.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b6f03fea..43ca1bc56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -537,7 +537,11 @@ if( CALAMARES_VERSION_RC ) set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} ) endif() -# additional info for non-release builds +# Additional info for non-release builds. The "extended" version information +# with date and git information (commit, dirty status) is used only +# by CalamaresVersionX.h, which is included by consumers that need a full +# version number with all that information; normal consumers can include +# CalamaresVersion.h with more stable numbers. if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" ) include( CMakeDateStamp ) set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" ) diff --git a/src/calamares/CalamaresVersion.h.in b/src/calamares/CalamaresVersion.h.in index 4ac7ee1d1..54a44888a 100644 --- a/src/calamares/CalamaresVersion.h.in +++ b/src/calamares/CalamaresVersion.h.in @@ -4,7 +4,7 @@ #cmakedefine CALAMARES_ORGANIZATION_NAME "${CALAMARES_ORGANIZATION_NAME}" #cmakedefine CALAMARES_ORGANIZATION_DOMAIN "${CALAMARES_ORGANIZATION_DOMAIN}" #cmakedefine CALAMARES_APPLICATION_NAME "${CALAMARES_APPLICATION_NAME}" -#cmakedefine CALAMARES_VERSION "${CALAMARES_VERSION}" +#cmakedefine CALAMARES_VERSION "${CALAMARES_VERSION_SHORT}" #cmakedefine CALAMARES_VERSION_SHORT "${CALAMARES_VERSION_SHORT}" #cmakedefine CALAMARES_VERSION_MAJOR "${CALAMARES_VERSION_MAJOR}" diff --git a/src/calamares/CalamaresVersionX.h.in b/src/calamares/CalamaresVersionX.h.in new file mode 100644 index 000000000..75b124c11 --- /dev/null +++ b/src/calamares/CalamaresVersionX.h.in @@ -0,0 +1,13 @@ +// Same as CalamaresVersion.h, but with a full-git-extended VERSION +// rather than the short (vM.m.p) semantic version. +#ifndef CALAMARES_VERSION_H + +// On purpose, do not define the guard, but let CalamaresVersion.h do it +// #define CALAMARES_VERSION_H + +#include "CalamaresVersion.h" + +#undef CALAMARES_VERSION +#cmakedefine CALAMARES_VERSION "${CALAMARES_VERSION}" + +#endif // CALAMARES_VERSION_H From 38b347f8f2c1d36063db564c6fdf12dd9c0d557a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jul 2020 14:58:43 +0200 Subject: [PATCH 2/4] [libcalamares] Take ownership of the versioning headers - The sources were in src/calamares but processed and generated in libcalamares, which is weird at best. - Generate an "extended" version header. - Use the extended version in the logger and nowhere else. - While here, minor coding style cleanups The overall change here means that after running CMake, only Logger.cpp needs to be rebuilt (if the extended version has changed) and not a handful of other files that don't need the full version number, but do happen to include CalamaresVersion.h --- src/libcalamares/CMakeLists.txt | 4 +++- .../CalamaresVersion.h.in | 0 .../CalamaresVersionX.h.in | 0 src/libcalamares/utils/Logger.cpp | 14 ++++++-------- 4 files changed, 9 insertions(+), 9 deletions(-) rename src/{calamares => libcalamares}/CalamaresVersion.h.in (100%) rename src/{calamares => libcalamares}/CalamaresVersionX.h.in (100%) diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 56bacb32a..8e209f8a3 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -27,8 +27,10 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CalamaresConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresConfig.h ) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../calamares/CalamaresVersion.h.in +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h ) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersionX.h.in + ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersionX.h ) set( OPTIONAL_PRIVATE_LIBRARIES "" ) set( OPTIONAL_PUBLIC_LIBRARIES "" ) diff --git a/src/calamares/CalamaresVersion.h.in b/src/libcalamares/CalamaresVersion.h.in similarity index 100% rename from src/calamares/CalamaresVersion.h.in rename to src/libcalamares/CalamaresVersion.h.in diff --git a/src/calamares/CalamaresVersionX.h.in b/src/libcalamares/CalamaresVersionX.h.in similarity index 100% rename from src/calamares/CalamaresVersionX.h.in rename to src/libcalamares/CalamaresVersionX.h.in diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 72885d53f..5a2149f44 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -3,6 +3,7 @@ * SPDX-FileCopyrightText: 2010-2011 Christian Muehlhaeuser * SPDX-FileCopyrightText: 2014 Teo Mrnjavac * SPDX-FileCopyrightText: 2017 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later * * * Calamares is free software: you can redistribute it and/or modify @@ -18,15 +19,12 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . * - * SPDX-License-Identifier: GPL-3.0-or-later - * License-Filename: LICENSE - * */ #include "Logger.h" -#include -#include +#include "CalamaresVersionX.h" +#include "utils/Dirs.h" #include #include @@ -35,10 +33,10 @@ #include #include -#include "CalamaresVersion.h" -#include "utils/Dirs.h" +#include +#include -#define LOGFILE_SIZE 1024 * 256 +static constexpr const int LOGFILE_SIZE = 1024 * 256; static std::ofstream logfile; static unsigned int s_threshold = From bfa1f618c7aade57bd2c51b11293ecf4931c765e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jul 2020 17:36:10 +0200 Subject: [PATCH 3/4] CMake: Improve RCC version-checking Previously, we check for RCC support every single time CMake runs. This is slightly wasteful, and it wasn't being done right anyway. But it's moot because: - Calamares supports back to Qt 5.9 - Qt 5.9's version of rcc (at least, 5.9.7) **does** support the command-line argument `--format-version 1` - Everything newer does too. Simplify translations a little, too: just use autorcc rather than building things by hand. --- CMakeModules/CalamaresAddTranslations.cmake | 36 ++------------------- src/calamares/CMakeLists.txt | 4 +-- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/CMakeModules/CalamaresAddTranslations.cmake b/CMakeModules/CalamaresAddTranslations.cmake index bb15fb122..88992faf5 100644 --- a/CMakeModules/CalamaresAddTranslations.cmake +++ b/CMakeModules/CalamaresAddTranslations.cmake @@ -22,46 +22,14 @@ include( CMakeParseArguments ) -if( NOT _rcc_version_support_checked ) - set( _rcc_version_support_checked TRUE ) - - # Extract the executable name - get_property( _rcc_executable - TARGET ${Qt5Core_RCC_EXECUTABLE} - PROPERTY IMPORTED_LOCATION - ) - if( NOT _rcc_executable ) - # Weird, probably now uses Qt5::rcc which is wrong too - set( _rcc_executable ${Qt5Core_RCC_EXECUTABLE} ) - endif() - - # Try an empty RCC file with explicit format-version - execute_process( - COMMAND echo "" - COMMAND ${Qt5Core_RCC_EXECUTABLE} --format-version 1 --list - - RESULT_VARIABLE _rcc_version_rv - ERROR_VARIABLE _rcc_version_dump - ) - if ( _rcc_version_rv EQUAL 0 ) - # Supported: force to the reproducible version - set( _rcc_version_support --format-version 1 ) - else() - # Older Qt versions (5.7, 5.8) don't support setting the - # rcc format-version, so won't be reproducible if they - # default to version 2. - set( _rcc_version_support "" ) - endif() - unset( _rcc_version_rv ) - unset( _rcc_version_dump ) -endif() - - # Internal macro for adding the C++ / Qt translations to the # build and install tree. Should be called only once, from # src/calamares/CMakeLists.txt. macro(add_calamares_translations language) list( APPEND CALAMARES_LANGUAGES ${ARGV} ) + set( _rcc_version_support --format-version 1 ) + set( calamares_i18n_qrc_content "\n" ) # calamares and qt language files diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index b632567b8..ff91904e2 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -34,9 +34,8 @@ include_directories( # Translations include( CalamaresAddTranslations ) add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) -qt5_add_resources( calamaresRc calamares.qrc ) -add_executable( calamares_bin ${calamaresSources} ${calamaresRc} ${trans_outfile} ) +add_executable( calamares_bin ${calamaresSources} calamares.qrc ${trans_outfile} ) target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} ) set_target_properties(calamares_bin PROPERTIES @@ -45,6 +44,7 @@ set_target_properties(calamares_bin ) calamares_automoc( calamares_bin ) calamares_autouic( calamares_bin ) +calamares_autorcc( calamares_bin ) target_link_libraries( calamares_bin PRIVATE From afb0b36f586e262824ea9754300f903b0e93a808 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 29 Jul 2020 10:01:49 +0200 Subject: [PATCH 4/4] CMake: simplify QRC generation Use configure_file() to avoid stomping on timestamps: if the list of translations doesn't change, we don't need to rebuild the translated QRC. --- CMakeModules/CalamaresAddTranslations.cmake | 25 +++++---------------- lang/calamares_i18n.qrc.in | 5 +++++ 2 files changed, 10 insertions(+), 20 deletions(-) create mode 100644 lang/calamares_i18n.qrc.in diff --git a/CMakeModules/CalamaresAddTranslations.cmake b/CMakeModules/CalamaresAddTranslations.cmake index 88992faf5..5015301d2 100644 --- a/CMakeModules/CalamaresAddTranslations.cmake +++ b/CMakeModules/CalamaresAddTranslations.cmake @@ -28,12 +28,9 @@ include( CMakeParseArguments ) macro(add_calamares_translations language) list( APPEND CALAMARES_LANGUAGES ${ARGV} ) - set( _rcc_version_support --format-version 1 ) - - set( calamares_i18n_qrc_content "\n" ) + set( calamares_i18n_qrc_content "" ) # calamares and qt language files - set( calamares_i18n_qrc_content "${calamares_i18n_qrc_content}\n" ) foreach( lang ${CALAMARES_LANGUAGES} ) foreach( tlsource "calamares_${lang}" "tz_${lang}" ) if( EXISTS "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) @@ -43,31 +40,19 @@ macro(add_calamares_translations language) endforeach() endforeach() - set( calamares_i18n_qrc_content "${calamares_i18n_qrc_content}\n" ) - set( calamares_i18n_qrc_content "${calamares_i18n_qrc_content}\n" ) - - file( WRITE ${CMAKE_BINARY_DIR}/lang/calamares_i18n.qrc "${calamares_i18n_qrc_content}" ) - - qt5_add_translation(QM_FILES ${TS_FILES}) - - ## HACK HACK HACK - around rcc limitations to allow out of source-tree building set( trans_file calamares_i18n ) - set( trans_srcfile ${CMAKE_BINARY_DIR}/lang/${trans_file}.qrc ) set( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc ) set( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx ) - # Copy the QRC file to the output directory - add_custom_command( - OUTPUT ${trans_infile} - COMMAND ${CMAKE_COMMAND} -E copy ${trans_srcfile} ${trans_infile} - MAIN_DEPENDENCY ${trans_srcfile} - ) + configure_file( ${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY ) + + qt5_add_translation(QM_FILES ${TS_FILES}) # Run the resource compiler (rcc_options should already be set) add_custom_command( OUTPUT ${trans_outfile} COMMAND "${Qt5Core_RCC_EXECUTABLE}" - ARGS ${rcc_options} ${_rcc_version_support} -name ${trans_file} -o ${trans_outfile} ${trans_infile} + ARGS ${rcc_options} --format-version 1 -name ${trans_file} -o ${trans_outfile} ${trans_infile} MAIN_DEPENDENCY ${trans_infile} DEPENDS ${QM_FILES} ) diff --git a/lang/calamares_i18n.qrc.in b/lang/calamares_i18n.qrc.in new file mode 100644 index 000000000..1f0ac1604 --- /dev/null +++ b/lang/calamares_i18n.qrc.in @@ -0,0 +1,5 @@ + + +@calamares_i18n_qrc_content@ + +