diff --git a/buildrpms.pl b/buildrpms.pl index 840787552..92d96014d 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -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 { diff --git a/xCAT-test/unit/buildrpms_source_only.t b/xCAT-test/unit/buildrpms_source_only.t index 14ef4b5e0..ebc58a98f 100644 --- a/xCAT-test/unit/buildrpms_source_only.t +++ b/xCAT-test/unit/buildrpms_source_only.t @@ -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))