From 98d55ce82f43aec2c2e577a842b89e15bd8c5119 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 3 Jan 2023 13:54:20 -0800 Subject: [PATCH] Avoid rebuilding with each commit We shouldn't include the kicad_build_info.h outside of the wrapper build_info.h. Also adds an error directive to prevent re-introduction of define dependencies --- cmake/BuildSteps/WriteVersionHeader.cmake | 4 +++ common/build_version.cpp | 32 ++++++++++++++++++++- common/dialog_about/dialog_about.cpp | 13 +++++---- common/pgm_base.cpp | 13 ++++----- include/build_version.h | 30 ++++++++++++++++++- kicad/cli/command_version.cpp | 8 +++--- kicad/kicad_cli.cpp | 4 +-- kicad/kicad_manager_frame.cpp | 35 ++++++++++++----------- kicad/pcm/pcm.cpp | 6 ++-- pcbnew/python/swig/version.i | 6 ++-- 10 files changed, 108 insertions(+), 43 deletions(-) diff --git a/cmake/BuildSteps/WriteVersionHeader.cmake b/cmake/BuildSteps/WriteVersionHeader.cmake index b0e7bab236..8cf59b24bd 100644 --- a/cmake/BuildSteps/WriteVersionHeader.cmake +++ b/cmake/BuildSteps/WriteVersionHeader.cmake @@ -67,6 +67,10 @@ set( _wvh_new_version_text #ifndef __KICAD_VERSION_H__ #define __KICAD_VERSION_H__ +#ifndef INCLUDE_KICAD_VERSION +#error Do not include kicad_build_version.h directly. Include build_version.h instead. +#endif + #define KICAD_COMMIT_HASH \"${KICAD_COMMIT_HASH}\" #define KICAD_VERSION_FULL \"${KICAD_VERSION_FULL}\" #define KICAD_SEMANTIC_VERSION \"${KICAD_SEMANTIC_VERSION}\" diff --git a/common/build_version.cpp b/common/build_version.cpp index d8483f7feb..5abce079c7 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -29,6 +29,8 @@ #include #include +#include + // kicad_curl.h must be included before wx headers, to avoid // conflicts for some defines, at least on Windows // kicad_curl.h can create conflicts for some defines, at least on Windows @@ -46,8 +48,9 @@ extern std::string GetCurlLibVersion(); // The include file version.h is always created even if the repo version cannot be // determined. In this case KICAD_VERSION_FULL will default to the KICAD_VERSION // that is set in KiCadVersion.cmake. +#define INCLUDE_KICAD_VERSION #include - +#undef INCLUDE_KICAD_VERSION wxString GetPlatformGetBitnessName() { @@ -65,6 +68,12 @@ wxString GetPlatformGetBitnessName() } +bool IsNightlyVersion() +{ + return !!KICAD_IS_NIGHTLY; +} + + wxString GetBuildVersion() { wxString msg = wxString::Format( wxT( "%s" ), wxT( KICAD_VERSION_FULL ) ); @@ -93,6 +102,27 @@ wxString GetMajorMinorVersion() } +wxString GetCommitHash() +{ + wxString msg = wxString::Format( wxT( "%s" ), wxT( KICAD_COMMIT_HASH ) ); + return msg; +} + + +wxString GetMajorMinorPatchVersion() +{ + wxString msg = wxString::Format( wxT( "%s" ), wxT( KICAD_MAJOR_MINOR_PATCH_VERSION ) ); + return msg; +} + +const std::tuple& GetMajorMinorPatchTuple() +{ + static std::tuple retval = KICAD_MAJOR_MINOR_PATCH_TUPLE; + + return retval; +} + + wxString GetVersionInfoData( const wxString& aTitle, bool aHtml, bool aBrief ) { wxString aMsg; diff --git a/common/dialog_about/dialog_about.cpp b/common/dialog_about/dialog_about.cpp index acb0c47967..e8fd8bd9c9 100644 --- a/common/dialog_about/dialog_about.cpp +++ b/common/dialog_about/dialog_about.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include @@ -79,11 +79,12 @@ DIALOG_ABOUT::DIALOG_ABOUT( EDA_BASE_FRAME *aParent, ABOUT_APP_INFO& aAppInfo ) else { wxIcon icon; -#if KICAD_IS_NIGHTLY - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) ); -#else - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) ); -#endif + + if( IsNightlyVersion() ) + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) ); + else + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) ); + SetIcon( icon ); m_bitmapApp->SetBitmap( icon ); } diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index c2a0dc95c6..24bdeabb3f 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -68,7 +68,7 @@ #include #include #include -#include +#include #endif /** @@ -325,11 +325,10 @@ void PGM_BASE::sentryInit() sentry_options_set_symbolize_stacktraces( options, true ); sentry_options_set_auto_session_tracking( options, false ); -#if !KICAD_IS_NIGHTLY - sentry_options_set_release( options, KICAD_SEMANTIC_VERSION ); -#else - sentry_options_set_release( options, KICAD_COMMIT_HASH ); -#endif + if( IsNightlyVersion() ) + sentry_options_set_release( options, GetSemanticVersion().ToStdString().c_str() ); + else + sentry_options_set_release( options, GetCommitHash().ToStdString().c_str() ); sentry_init( options ); @@ -337,7 +336,7 @@ void PGM_BASE::sentryInit() sentry_value_set_by_key( user, "id", sentry_value_new_string( m_sentryUid.c_str() ) ); sentry_set_user( user ); - sentry_set_tag( "kicad.version", KICAD_VERSION_FULL ); + sentry_set_tag( "kicad.version", GetBuildVersion().ToStdString().c_str() ); } } diff --git a/include/build_version.h b/include/build_version.h index 17dcbf2700..c0b5d419d5 100644 --- a/include/build_version.h +++ b/include/build_version.h @@ -27,8 +27,9 @@ #ifndef KICAD_BUILD_VERSION_H #define KICAD_BUILD_VERSION_H -class wxString; +#include +class wxString; /** * Get the full KiCad version string. This string contains platform-specific information @@ -59,6 +60,14 @@ wxString GetSemanticVersion(); */ wxString GetMajorMinorVersion(); +/** + * Get the major, minor and patch version in a string major.minor.patch + * This is extracted by CMake from the KICAD_SEMANTIC_VERSION variable. + * + * @return the major.minor.patch version as a string + */ +wxString GetMajorMinorPatchVersion(); + /** * Get the build date as a string. * @@ -66,6 +75,25 @@ wxString GetMajorMinorVersion(); */ wxString GetBuildDate(); +/** + * Get the commit hash as a string. + * + * @return the commit hash string + */ +wxString GetCommitHash(); + +/** + * Get the build version numbers as a tuple + * + * @return A tuple with three ints for major/minor/patch revisions + */ +const std::tuple& GetMajorMinorPatchTuple(); + +/** + * Check if the build is meant to be nightly + * @return true if running nightly build + */ +bool IsNightlyVersion(); /** * Create a version info string for bug reports and the about dialog diff --git a/kicad/cli/command_version.cpp b/kicad/cli/command_version.cpp index 0067563ad0..0a1ef70ff5 100644 --- a/kicad/cli/command_version.cpp +++ b/kicad/cli/command_version.cpp @@ -21,7 +21,7 @@ #include "command_version.h" #include #include -#include +#include #include #include @@ -41,11 +41,11 @@ int CLI::VERSION_COMMAND::doPerform( KIWAY& aKiway ) wxString format = FROM_UTF8( m_argParser.get( ARG_FORMAT ).c_str() ); if( format == wxS( "plain" ) ) { - wxPrintf( KICAD_MAJOR_MINOR_PATCH_VERSION ); + wxPrintf( GetMajorMinorPatchVersion() ); } else if( format == wxS( "commit" ) ) { - wxPrintf( KICAD_COMMIT_HASH ); + wxPrintf( GetCommitHash() ); } else if( format == wxS( "about" ) ) { @@ -59,4 +59,4 @@ int CLI::VERSION_COMMAND::doPerform( KIWAY& aKiway ) } return 0; -} \ No newline at end of file +} diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index b046e44141..ee53f018a1 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -43,7 +43,7 @@ #include "pgm_kicad.h" #include "kicad_manager_frame.h" -#include +#include #include #include @@ -289,7 +289,7 @@ bool PGM_KICAD::OnPgmInit() int PGM_KICAD::OnPgmRun() { - argparse::ArgumentParser argParser( std::string( "kicad-cli" ), KICAD_MAJOR_MINOR_VERSION, + argparse::ArgumentParser argParser( std::string( "kicad-cli" ), GetMajorMinorVersion().ToStdString(), argparse::default_arguments::none ); argParser.add_argument( "-v", ARG_VERSION ) diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 118e88a32b..34c1cd976f 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include @@ -141,21 +141,24 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl wxIcon icon; wxIconBundle icon_bundle; -#if KICAD_IS_NIGHTLY - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) ); - icon_bundle.AddIcon( icon ); - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_32 ) ); - icon_bundle.AddIcon( icon ); - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_16 ) ); - icon_bundle.AddIcon( icon ); -#else - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) ); - icon_bundle.AddIcon( icon ); - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_32 ) ); - icon_bundle.AddIcon( icon ); - icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_16 ) ); - icon_bundle.AddIcon( icon ); -#endif + if( IsNightlyVersion()) + { + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) ); + icon_bundle.AddIcon( icon ); + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_32 ) ); + icon_bundle.AddIcon( icon ); + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_16 ) ); + icon_bundle.AddIcon( icon ); + } + else + { + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) ); + icon_bundle.AddIcon( icon ); + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_32 ) ); + icon_bundle.AddIcon( icon ); + icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_16 ) ); + icon_bundle.AddIcon( icon ); + } SetIcons( icon_bundle ); diff --git a/kicad/pcm/pcm.cpp b/kicad/pcm/pcm.cpp index 9b38ebd06e..82689775bd 100644 --- a/kicad/pcm/pcm.cpp +++ b/kicad/pcm/pcm.cpp @@ -24,7 +24,7 @@ #include #include "core/wx_stl_compat.h" -#include "kicad_build_version.h" +#include "build_version.h" #include "paths.h" #include "pcm.h" #include "pgm_base.h" @@ -45,7 +45,7 @@ const std::tuple PLUGIN_CONTENT_MANAGER::m_kicad_version = - KICAD_MAJOR_MINOR_PATCH_TUPLE; + GetMajorMinorPatchTuple(); class THROWING_ERROR_HANDLER : public nlohmann::json_schema::error_handler @@ -199,7 +199,7 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER( PACKAGE_VERSION version; version.version = "0.0"; version.status = PVS_STABLE; - version.kicad_version = KICAD_MAJOR_MINOR_VERSION; + version.kicad_version = GetMajorMinorVersion(); entry.package.versions.emplace_back( version ); diff --git a/pcbnew/python/swig/version.i b/pcbnew/python/swig/version.i index a2a2d76fe9..c8e394b255 100644 --- a/pcbnew/python/swig/version.i +++ b/pcbnew/python/swig/version.i @@ -24,15 +24,15 @@ #pragma SWIG nowarn=305 -%include kicad_build_version.h +%include build_version.h %pythoncode %{ def Version(): """Return the semantic version of KiCad""" - return KICAD_SEMANTIC_VERSION + return GetSemanticVersion() def FullVersion(): """Return the full, git-based version of KiCad""" - return KICAD_VERSION_FULL + return GetBuildVersion() %} \ No newline at end of file