mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-04 20:17:55 +00:00
refactor(build): reuse the shared git revision and epoch helpers
buildrpms.pl derived the git revision and SOURCE_DATE_EPOCH with its own inline backticks while BuildUtils.pm already provided git_revision() and source_date_epoch() for builddebs.pl. Both did the same thing, and the copies in buildrpms.pl were the weaker ones: neither fell back to the tracked Gitinfo and Gitepoch files, so a build from a source tarball with no git history recorded the revision as "unknown" and stamped the current time as the build epoch, losing reproducibility exactly where it matters most. Verified that the helper returns the same revision and epoch as the code it replaces on a checkout with history. buildrpms.pl now loads BuildUtils.pm from its own directory, so the source-only test stages the module into its sandbox alongside Version. That test copies the builder rather than running it in the checkout, because it rewrites Gitinfo and creates $HOME/rpmbuild before it looks at its arguments. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
+4
-13
@@ -42,6 +42,8 @@ use File::Path qw(make_path remove_tree);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir tempfile);
|
||||
use FindBin qw($Bin);
|
||||
use lib $Bin;
|
||||
use BuildUtils qw(git_revision source_date_epoch);
|
||||
use Fcntl qw(:flock); # per-target build lock (concurrency guard; see main())
|
||||
use Getopt::Long qw(GetOptions);
|
||||
use POSIX qw(strftime);
|
||||
@@ -71,21 +73,10 @@ my @XCAT_PROBE_HELPERS = qw(
|
||||
chomp($VERSION);
|
||||
|
||||
# Gitinfo is regenerated at each run with the current git revision.
|
||||
my $GITINFO = `git rev-parse HEAD 2>/dev/null`;
|
||||
chomp($GITINFO);
|
||||
$GITINFO = "unknown" unless $GITINFO;
|
||||
my $GITINFO = git_revision();
|
||||
write_text("Gitinfo", "$GITINFO\n");
|
||||
|
||||
my $SOURCE_DATE_EPOCH;
|
||||
if (-f "Gitepoch") {
|
||||
$SOURCE_DATE_EPOCH = read_text("Gitepoch");
|
||||
chomp($SOURCE_DATE_EPOCH);
|
||||
}
|
||||
unless ($SOURCE_DATE_EPOCH && $SOURCE_DATE_EPOCH =~ /^\d+$/) {
|
||||
$SOURCE_DATE_EPOCH = `git log -1 --format=%ct HEAD 2>/dev/null`;
|
||||
chomp($SOURCE_DATE_EPOCH);
|
||||
}
|
||||
$SOURCE_DATE_EPOCH = time() unless $SOURCE_DATE_EPOCH =~ /^\d+$/;
|
||||
my $SOURCE_DATE_EPOCH = source_date_epoch();
|
||||
$ENV{SOURCE_DATE_EPOCH} = $SOURCE_DATE_EPOCH;
|
||||
|
||||
sub os_release {
|
||||
|
||||
@@ -140,9 +140,10 @@ ok( !grep( { $_ eq 'buildpkgs' } @{ stages_for(1) } ),
|
||||
# buildrpms.pl rewrites the tracked Gitinfo in its working directory and creates
|
||||
# $HOME/rpmbuild. Running it in place left the developer's tree dirty and reached
|
||||
# into their home for a test that only exercises argument parsing. Version is
|
||||
# staged because the same file-scope code reads it and dies without it.
|
||||
# staged because the same file-scope code reads it and dies without it, and
|
||||
# BuildUtils.pm because buildrpms.pl loads it from its own directory.
|
||||
my $sandbox = tempdir(CLEANUP => 1);
|
||||
for my $needed (qw(buildrpms.pl Version)) {
|
||||
for my $needed (qw(buildrpms.pl Version BuildUtils.pm)) {
|
||||
my $from = repo_path($needed);
|
||||
BAIL_OUT("$needed is missing from the repository") unless -r $from;
|
||||
File::Copy::copy($from, File::Spec->catfile($sandbox, $needed))
|
||||
|
||||
Reference in New Issue
Block a user