mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-08 18:06:30 +00:00
fix(build): support Git commit hash injection for tarball-based package builds (#2266)
This commit is contained in:
committed by
GitHub
parent
600cc5f96d
commit
a3ac701c1a
@@ -33,6 +33,13 @@ while [[ $# -gt 0 ]]; do
|
||||
USE_SYSTEM_LIBS=true
|
||||
shift
|
||||
;;
|
||||
-commit-hash)
|
||||
# Inject build provenance for tarball builds (Homebrew, released source tarball, etc.)
|
||||
# where no .git directory is present. Passed through to pre-build.sh
|
||||
# via the exported env var GIT_COMMIT_HASH_OVERRIDE.
|
||||
export GIT_COMMIT_HASH_OVERRIDE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "Obtaining Git commit"
|
||||
commit=(`git rev-parse HEAD 2>/dev/null`)
|
||||
if [ -n "$GIT_COMMIT_HASH_OVERRIDE" ]; then
|
||||
commit="$GIT_COMMIT_HASH_OVERRIDE"
|
||||
echo "Using injected commit hash: $commit"
|
||||
else
|
||||
commit=(`git rev-parse HEAD 2>/dev/null`)
|
||||
fi
|
||||
if [ -z "$commit" ]; then
|
||||
echo "Git command not present, trying folder approach"
|
||||
if [ -d "../.git" ]; then
|
||||
|
||||
@@ -35,6 +35,13 @@ while [[ $# -gt 0 ]]; do
|
||||
USE_SYSTEM_LIBS=true
|
||||
shift
|
||||
;;
|
||||
-commit-hash)
|
||||
# Inject build provenance for tarball builds (Homebrew, released source tarball, etc.)
|
||||
# where no .git directory is present. Passed through to pre-build.sh
|
||||
# via the exported env var GIT_COMMIT_HASH_OVERRIDE.
|
||||
export GIT_COMMIT_HASH_OVERRIDE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#!/bin/bash
|
||||
echo "Obtaining Git commit"
|
||||
commit=(`git rev-parse HEAD 2>/dev/null`)
|
||||
if [ -n "$GIT_COMMIT_HASH_OVERRIDE" ]; then
|
||||
commit="$GIT_COMMIT_HASH_OVERRIDE"
|
||||
echo "Using injected commit hash: $commit"
|
||||
else
|
||||
commit=(`git rev-parse HEAD 2>/dev/null`)
|
||||
fi
|
||||
if [ -z "$commit" ]; then
|
||||
echo "Git command not present, trying folder approach"
|
||||
if [ -d "../.git" ]; then
|
||||
|
||||
@@ -21,18 +21,25 @@ set (CCEXTRACTOR_VERSION_MINOR 96)
|
||||
# Get project directory
|
||||
get_filename_component(BASE_PROJ_DIR ../ ABSOLUTE)
|
||||
|
||||
# Get the latest commit hash of the working branch
|
||||
IF(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
ELSE(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
set(GIT_BRANCH "Unknown")
|
||||
set(GIT_COMMIT_HASH "Unknown")
|
||||
ENDIF(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
# GIT_COMMIT_HASH can be injected via -DGIT_COMMIT_HASH=<value> for Homebrew
|
||||
# or any tarball-based build where no .git directory is present.
|
||||
# Source builds fall through to git rev-parse automatically.
|
||||
set(GIT_COMMIT_HASH "" CACHE STRING
|
||||
"Build provenance override for tarball-based builds (Homebrew, released source tarball)")
|
||||
|
||||
if(GIT_COMMIT_HASH STREQUAL "")
|
||||
IF(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
ELSE(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
set(GIT_BRANCH "Unknown")
|
||||
set(GIT_COMMIT_HASH "Unknown")
|
||||
ENDIF(EXISTS "${BASE_PROJ_DIR}/.git")
|
||||
endif()
|
||||
|
||||
#Get the date
|
||||
string(TIMESTAMP COMPILATION_DATE %Y-%m-%d)
|
||||
|
||||
Reference in New Issue
Block a user