mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-05 04:27:55 +00:00
87c8a7c0dd
An xCAT installed from these debs could report no version at all: `lsxcatd -v`
printed a bare "Version" and there was no /opt/xcat/share/xcat/version to
consult.
xCAT::Version ships with #XCATVERSIONSUBHERE / #XCATSVNBUILDSUBHERE
placeholders that perl-xCAT/debian/rules fills by calling modifyUtils with the
version and the commit. It takes the commit from ../Gitinfo, falling back to
`git log`. Neither Debian builder wrote Gitinfo -- buildrpms.pl does, which is
why only the deb side was affected -- so a tree without a readable .git left
that argument empty. modifyUtils then hit `if [ -z "$2" ]` and returned 0
WITHOUT substituting, and neither caller checks the status, so the placeholders
shipped.
Two independent things had to be wrong for this to be silent, and both are
fixed:
modifyUtils now exits non-zero on a missing argument, so a build that cannot
stamp a version fails instead of producing one that cannot identify itself. Its
message was also wrong -- it checked $2 and complained about the version, which
is $1 -- so each argument now names itself.
builddebs.pl writes Gitinfo, as buildrpms.pl already does. BuildUtils::
git_revision prefers the checkout, falls back to an existing Gitinfo (a source
export carries the real revision that way, and overwriting it with a
placeholder would discard the only provenance the tree has), and only then
returns "unknown" -- never the empty string modifyUtils ignores.
"unknown" is now warned about rather than stamped quietly. The cause is usually
not a missing .git but git refusing one it considers dubiously owned: the tree
belongs to another user and the safe.directory exception sits in a config that
the build's own HOME override hides. That is exactly how this went unnoticed.
Not a regression -- build-ubunturepo produces byte-identical unsubstituted
placeholders in the same .git-less tree, verified by running it there. It is a
pre-existing hole that CD masks by writing Gitinfo in the pipeline.
Verified on xcat-master-ub: with a readable checkout the deb carries
'Version ' . '2.19.0' . ' (git commit 0030133c89)';
without one it carries '(git commit unknown)' and the build prints the warning
naming the tree, the command to run and the HOME to run it under. Nine
assertions drive modifyUtils itself -- stamping both forms, and each missing
argument -- and dropping either sed, or restoring the silent exit, reddens it.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
96 lines
3.5 KiB
Perl
96 lines
3.5 KiB
Perl
#!/usr/bin/env perl
|
|
# modifyUtils stamps the version and commit into xCAT::Version.
|
|
#
|
|
# It is run, not read: the script is copied into a scratch tree with a stand-in
|
|
# Version.pm carrying the real placeholders, and the assertions are about the file
|
|
# that comes out. The behaviour that matters is the failure path -- modifyUtils used
|
|
# to return 0 when handed no commit, doing nothing, and neither caller
|
|
# (perl-XCAT/debian/rules, perl-xCAT.spec) checks the status, so the package shipped
|
|
# with its placeholders intact and `lsxcatd -v` printed a bare "Version".
|
|
use strict;
|
|
use warnings;
|
|
|
|
use File::Copy qw(copy);
|
|
use File::Path qw(make_path);
|
|
use File::Spec;
|
|
use File::Temp qw(tempdir);
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/../lib";
|
|
use Test::More;
|
|
|
|
use XCAT::Test::File qw(repo_path);
|
|
|
|
my $script = repo_path('perl-xCAT/modifyUtils');
|
|
plan skip_all => 'modifyUtils not found' unless -r $script;
|
|
|
|
# The real placeholders, as xCAT::Version ships them.
|
|
my $TEMPLATE = <<'PM';
|
|
sub Version
|
|
{
|
|
my $version = shift;
|
|
if ($version eq 'short')
|
|
{
|
|
$version = '' #XCATVERSIONSUBHERE ;
|
|
}
|
|
else
|
|
{
|
|
$version = 'Version ' #XCATVERSIONSUBHERE #XCATSVNBUILDSUBHERE ;
|
|
}
|
|
return $version;
|
|
}
|
|
PM
|
|
|
|
# modifyUtils picks its target from /etc/debian_version, which differs between the
|
|
# build hosts and CI. Stage BOTH candidates so the test asserts the same behaviour
|
|
# wherever it runs, and read back whichever one it chose.
|
|
sub run_modify {
|
|
my (@args) = @_;
|
|
my $dir = tempdir(CLEANUP => 1);
|
|
copy($script, "$dir/modifyUtils") or die "cannot stage modifyUtils: $!";
|
|
chmod 0755, "$dir/modifyUtils";
|
|
for my $rel ('xCAT', 'debian/perl-xcat/opt/xcat/lib/perl/xCAT') {
|
|
make_path("$dir/$rel");
|
|
open my $fh, '>', "$dir/$rel/Version.pm" or die $!;
|
|
print {$fh} $TEMPLATE;
|
|
close $fh;
|
|
}
|
|
|
|
my $out = qx(cd \Q$dir\E && ./modifyUtils @{[ join ' ', map { "'$_'" } @args ]} 2>&1);
|
|
my $rc = $? >> 8;
|
|
|
|
my $stamped = '';
|
|
for my $rel ('xCAT', 'debian/perl-xcat/opt/xcat/lib/perl/xCAT') {
|
|
open my $fh, '<', "$dir/$rel/Version.pm" or next;
|
|
my $text = do { local $/; <$fh> };
|
|
close $fh;
|
|
$stamped = $text if $text !~ /XCATVERSIONSUBHERE/;
|
|
}
|
|
return { rc => $rc, out => $out, stamped => $stamped };
|
|
}
|
|
|
|
# ------------------------------------------------------------------ the happy path --
|
|
my $ok = run_modify('2.19.0', 'abc123def456');
|
|
is( $ok->{rc}, 0, 'a version and a commit are stamped without error' );
|
|
like( $ok->{stamped}, qr/\Q'Version '\E\s*\. '2\.19\.0' \. ' \(git commit abc123def456\)'/,
|
|
'the long form carries the version and the commit it was built from' );
|
|
like( $ok->{stamped}, qr/\$version = ''\s*\. '2\.19\.0'/,
|
|
"and the 'short' form carries the bare version" );
|
|
unlike( $ok->{stamped}, qr/XCATVERSIONSUBHERE|XCATSVNBUILDSUBHERE/,
|
|
'no placeholder survives a successful stamp' );
|
|
|
|
# -------------------------------------------------------------- the failure path --
|
|
# The whole point: a missing argument must stop the build, not pass silently.
|
|
my $no_commit = run_modify('2.19.0', '');
|
|
isnt( $no_commit->{rc}, 0,
|
|
'a missing commit fails instead of shipping an unstamped package' );
|
|
like( $no_commit->{out}, qr/git commit/,
|
|
'and says which argument is missing' );
|
|
is( $no_commit->{stamped}, '',
|
|
'and stamps nothing, so the failure cannot be mistaken for a partial write' );
|
|
|
|
my $no_version = run_modify('', 'abc123def456');
|
|
isnt( $no_version->{rc}, 0, 'a missing version fails too' );
|
|
like( $no_version->{out}, qr/version/, 'and says so' );
|
|
|
|
done_testing();
|