fix: GIT_COMMIT_HASH forces full rebuilds and defeats compiler caching (#15537)

This commit is contained in:
Kris Austin
2026-09-05 12:08:38 -05:00
committed by GitHub
parent 0224741105
commit 2ad9c87dda
11 changed files with 100 additions and 37 deletions

View File

@@ -95,33 +95,6 @@ else ()
add_compile_definitions("$<$<CONFIG:Release>:WXINSPECTOR_DISABLE>")
endif ()
find_package(Git)
if(DEFINED ENV{git_commit_hash} AND NOT "$ENV{git_commit_hash}" STREQUAL "")
message(STATUS "Specified git commit hash: $ENV{git_commit_hash}")
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Convert the given hash to short hash
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short "$ENV{git_commit_hash}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
# No .git directory (e.g., Flatpak sandbox) — truncate directly
string(SUBSTRING "$ENV{git_commit_hash}" 0 7 GIT_COMMIT_HASH)
endif()
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
elseif(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Check current Git commit hash
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
endif()
if(DEFINED ENV{SLIC3R_STATIC})
set(SLIC3R_STATIC_INITIAL $ENV{SLIC3R_STATIC})
else()

View File

@@ -875,7 +875,7 @@ REM get_str_len <string> -> length in %ret%
echo ORCA_DEPS_CMAKE_ARGS Extra arguments for the deps configure
echo ORCA_SLICER_CMAKE_ARGS Extra arguments for the slicer configure
echo ORCA_UPDATER_SIG_KEY Update signing key baked into the slicer
echo git_commit_hash Revision to stamp, so a commit does not rebuild everything
echo git_commit_hash Revision to stamp into the build, as CI does
echo NINJA_STATUS Ninja progress format, if you want your own
echo debugscript Set to ON to trace this script
echo.

View File

@@ -9,6 +9,7 @@
#include <boost/format.hpp>
#include <mutex>
#include "git_commit_hash.h"
#include "libslic3r_version.h"
static std::string g_log_folder;
@@ -39,7 +40,7 @@ CBaseException::CBaseException(HANDLE hProcess, WORD wPID, LPCTSTR lpSymbolPath,
output_file->open(log_filename, std::ios::out | std::ios::app);
// Output app build info in crash log so we could look for the correct PDB files
OutputString(_T("%s\n\n"), _T(SLIC3R_APP_NAME " " SoftFever_VERSION " Build " GIT_COMMIT_HASH));
OutputString(_T("%s\n\n"), _T(SLIC3R_APP_NAME " " SoftFever_VERSION " Build " GIT_COMMIT_HASH GIT_COMMIT_SUFFIX));
}
}

View File

@@ -5,9 +5,6 @@
#define SLIC3R_APP_KEY "@SLIC3R_APP_KEY@"
#define SLIC3R_VERSION "@SLIC3R_VERSION@"
#define SoftFever_VERSION "@SoftFever_VERSION@"
#ifndef GIT_COMMIT_HASH
#define GIT_COMMIT_HASH "0000000" // 0000000 means uninitialized
#endif
#define SLIC3R_BUILD_ID "@SLIC3R_BUILD_ID@"
//#define SLIC3R_RC_VERSION "@SLIC3R_VERSION@"
#define BBL_INTERNAL_TESTING @BBL_INTERNAL_TESTING@

View File

@@ -63,6 +63,8 @@ set(SLIC3R_GUI_SOURCES
GUI/BitmapComboBox.hpp
GUI/BonjourDialog.cpp
GUI/BonjourDialog.hpp
GUI/BuildCommit.cpp
GUI/BuildCommit.hpp
GUI/CrealityDiscoveryDialog.cpp
GUI/CrealityDiscoveryDialog.hpp
GUI/calib_dlg.cpp
@@ -845,6 +847,18 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SLIC3R_GUI_SOURCES})
encoding_check(libslic3r_gui)
# Only BuildCommit.cpp includes the generated header, plus BaseException.cpp on
# Windows. Both build into libslic3r_gui, so the header only has to exist before
# that target builds.
set(_git_commit_hash_header "${CMAKE_CURRENT_BINARY_DIR}/git_commit_hash.h")
add_custom_target(git_commit_hash_header
BYPRODUCTS "${_git_commit_hash_header}"
COMMAND ${CMAKE_COMMAND}
"-DSOURCE_DIR=${CMAKE_SOURCE_DIR}"
"-DOUT_FILE=${_git_commit_hash_header}"
-P "${CMAKE_CURRENT_LIST_DIR}/GitCommitHash.cmake"
COMMENT "Resolving the git commit hash")
add_dependencies(libslic3r_gui git_commit_hash_header)
if(APPLE AND CMAKE_VERSION VERSION_GREATER_EQUAL "4.0")
set(_opengl_link_lib "")

View File

@@ -3,6 +3,7 @@
#include "libslic3r/Utils.hpp"
#include "libslic3r/Color.hpp"
#include "BuildCommit.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
@@ -245,7 +246,7 @@ AboutDialog::AboutDialog()
vesizer->Add(0, 0, 1, wxEXPAND, FromDIP(5));
auto version_string = std::string(SoftFever_VERSION); // _L("Orca Slicer ") + " " + std::string(SoftFever_VERSION);
wxStaticText* version = new wxStaticText(this, wxID_ANY, version_string.c_str(), wxDefaultPosition, wxDefaultSize);
wxStaticText* credits_string = new wxStaticText(this, wxID_ANY, wxString::Format("Build %s", std::string(GIT_COMMIT_HASH)), wxDefaultPosition, wxDefaultSize);
wxStaticText* credits_string = new wxStaticText(this, wxID_ANY, wxString::Format("Build %s", build_commit_label), wxDefaultPosition, wxDefaultSize);
credits_string->SetFont(_build_string_font);
wxFont version_font = GetFont();
version_font = version_font.Scaled(1.85f); // SetPointSize(20) not works on macOS because it uses a 72 PPI reference

View File

@@ -0,0 +1,9 @@
#include "BuildCommit.hpp"
#include "git_commit_hash.h"
namespace Slic3r { namespace GUI {
const char *const build_commit_hash = GIT_COMMIT_HASH;
const char *const build_commit_label = GIT_COMMIT_HASH GIT_COMMIT_SUFFIX;
}} // namespace Slic3r::GUI

View File

@@ -0,0 +1,15 @@
#pragma once
// Read these rather than including git_commit_hash.h, which changes with every
// commit and rebuilds everything that includes it.
namespace Slic3r { namespace GUI {
// The commit alone, safe to use in a commit URL.
extern const char *const build_commit_hash;
// The same, with "-dirty" when the build had uncommitted changes. Use this
// wherever the build is shown to a person.
extern const char *const build_commit_label;
}} // namespace Slic3r::GUI

View File

@@ -9,6 +9,7 @@
#include "slic3r/GUI/TaskManager.hpp"
#include "format.hpp"
#include "libslic3r_version.h"
#include "BuildCommit.hpp"
#include "Downloader.hpp"
#include <boost/chrono/duration.hpp>
#include <boost/log/detail/native_typeof.hpp>
@@ -2580,7 +2581,7 @@ void GUI_App::init_app_config()
set_log_path_and_level(log_filename, 3);
#endif
BOOST_LOG_TRIVIAL(info) << boost::format("gui mode, Current OrcaSlicer Version %1% build %2%") % SoftFever_VERSION % GIT_COMMIT_HASH;
BOOST_LOG_TRIVIAL(info) << boost::format("gui mode, Current OrcaSlicer Version %1% build %2%") % SoftFever_VERSION % build_commit_label;
//BBS: remove GCodeViewer as seperate APP logic
if (!app_config)

View File

@@ -1,6 +1,7 @@
#include "TroubleshootDialog.hpp"
#include "I18N.hpp"
#include "BuildCommit.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
@@ -137,9 +138,9 @@ TroubleshootDialog::TroubleshootDialog()
version->SetFont(version_font);
version->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#363636")));
auto build = new Button(this, wxString(GIT_COMMIT_HASH));
auto build = new Button(this, wxString(build_commit_label));
build->SetStyle(ButtonStyle::Regular, ButtonType::Window);
auto hash_url = "https://github.com/OrcaSlicer/OrcaSlicer/commit/" + wxString(GIT_COMMIT_HASH);
auto hash_url = "https://github.com/OrcaSlicer/OrcaSlicer/commit/" + wxString(build_commit_hash);
build->SetToolTip(hash_url);
build->Bind(wxEVT_BUTTON, [hash_url](wxCommandEvent &e) {
wxLaunchDefaultBrowser(hash_url);
@@ -371,7 +372,7 @@ wxString TroubleshootDialog::GetSysInfoAll()
{
wxString info;
info += "Version : " + wxString(SoftFever_VERSION) + "\n"
+ "Build : " + wxString(GIT_COMMIT_HASH) + "\n"
+ "Build : " + wxString(build_commit_label) + "\n"
+ "Package : " + GetPackageType() + "\n"
+ "Platform : " + GetOSinfo() + "\n"
+ "Processor : " + GetCPUinfo() + "\n"

View File

@@ -0,0 +1,51 @@
# Writes GIT_COMMIT_HASH and GIT_COMMIT_SUFFIX into a generated header.
# GIT_COMMIT_SUFFIX is "-dirty" for a build with uncommitted changes, and empty
# otherwise.
#
# A custom target runs this at the start of every build, which picks up a new
# commit without a reconfigure. The header is rewritten only when the value
# changes.
#
# Inputs: SOURCE_DIR, OUT_FILE.
find_package(Git QUIET)
set(HASH "")
set(SUFFIX "")
if (DEFINED ENV{git_commit_hash} AND NOT "$ENV{git_commit_hash}" STREQUAL "")
if (GIT_FOUND AND EXISTS "${SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short "$ENV{git_commit_hash}"
WORKING_DIRECTORY ${SOURCE_DIR} OUTPUT_VARIABLE HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
else ()
# No .git directory (e.g. Flatpak sandbox) - truncate directly
string(SUBSTRING "$ENV{git_commit_hash}" 0 7 HASH)
endif ()
elseif (GIT_FOUND AND EXISTS "${SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${SOURCE_DIR} OUTPUT_VARIABLE HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} diff --quiet HEAD
WORKING_DIRECTORY ${SOURCE_DIR} RESULT_VARIABLE DIRTY ERROR_QUIET)
if (DIRTY EQUAL 1)
set(SUFFIX "-dirty")
endif ()
endif ()
if (NOT HASH)
set(HASH "0000000") # uninitialized
endif ()
message(STATUS "Build commit: ${HASH}${SUFFIX}")
string(CONCAT CONTENT
"#pragma once\n"
"#define GIT_COMMIT_HASH \"${HASH}\"\n"
"#define GIT_COMMIT_SUFFIX \"${SUFFIX}\"\n")
set(OLD "")
if (EXISTS "${OUT_FILE}")
file(READ "${OUT_FILE}" OLD)
endif ()
if (NOT OLD STREQUAL CONTENT)
file(WRITE "${OUT_FILE}" "${CONTENT}")
endif ()