diff --git a/genesis-openembedded/build b/genesis-openembedded/build index 375bd6f..fb9938e 100755 --- a/genesis-openembedded/build +++ b/genesis-openembedded/build @@ -22,6 +22,7 @@ use XCAT::BuildUtils qw( ); use XCAT::GenesisRelease qw( architectures + oe_source_dir deb_package_name minimum_release_version rpm_package_name @@ -62,9 +63,8 @@ my %requested = map { $_ => 1 } @requested_architectures; umask(0022); $xcat_source = abs_path($xcat_source) or die "Cannot resolve xcat-core source\n"; -for my $path (qw(Version xCAT-genesis-builder/oe/build xCAT-genesis-builder/oe/export)) { - die "xcat-core source is missing $path\n" unless -f "$xcat_source/$path"; -} +die "xcat-core source is missing Version\n" unless -f "$xcat_source/Version"; +my $oe_dir = oe_source_dir($xcat_source); die "xcat-core checkout is not clean\n" if capture_command('git', '-C', $xcat_source, 'status', '--porcelain') ne ''; @@ -79,7 +79,7 @@ if ($xcat_ref ne '') { unless $revision eq $expected; } if ($requested{s390x}) { - my $architecture_reporter = "$xcat_source/xCAT-genesis-builder/oe/build"; + my $architecture_reporter = "$xcat_source/$oe_dir/build"; my $probe_work = tempdir('xcat-genesis-capabilities.XXXXXX', TMPDIR => 1, CLEANUP => 1); my $supported_output; { @@ -133,7 +133,7 @@ local $ENV{XCAT_GENESIS_WORK_DIR} = $oe_work; { local $ENV{TMPDIR} = $oe_tmp; make_path($oe_tmp); - run_command("$xcat_source/xCAT-genesis-builder/oe/build", @requested_architectures); + run_command("$xcat_source/$oe_dir/build", @requested_architectures); } my $effective_deploy = "$oe_tmp/deploy"; die "Invalid OpenEmbedded deploy directory: $effective_deploy\n" @@ -143,7 +143,7 @@ for my $architecture (@requested_architectures) { my $export = "$work/exports/$architecture"; make_path(dirname($export)); run_command( - "$xcat_source/xCAT-genesis-builder/oe/export", + "$xcat_source/$oe_dir/export", $architecture, $effective_deploy, $export, ); diff --git a/lib/XCAT/GenesisRelease.pm b/lib/XCAT/GenesisRelease.pm index b05f9a1..a2ca910 100644 --- a/lib/XCAT/GenesisRelease.pm +++ b/lib/XCAT/GenesisRelease.pm @@ -8,6 +8,7 @@ use XCAT::BuildUtils qw(digest_file read_lines relative_files); our @EXPORT_OK = qw( architectures + oe_source_dir deb_package_prefix deb_package_name minimum_release_version @@ -35,6 +36,25 @@ my %RELEASE_ARCHITECTURES = ( 2 => \@RELEASE_V2_ARCHITECTURES, ); +# xcat-core 2a7364476 renamed xCAT-genesis-builder to xCAT-genesis-base. A dep build +# serves both: the released core still carries the old name, and master carries the new +# one. Take whichever the checkout has, and name both when it has neither. +my @OE_SOURCE_DIRS = qw(xCAT-genesis-base/oe xCAT-genesis-builder/oe); + +sub oe_source_dir { + my ($xcat_source, @required) = @_; + @required = qw(build export) unless @required; + + my @missing; + foreach my $dir (@OE_SOURCE_DIRS) { + my @absent = grep { !-f "$xcat_source/$dir/$_" } @required; + return $dir unless @absent; + push(@missing, map { "$dir/$_" } @absent); + } + die "xcat-core source has no OpenEmbedded Genesis builder: missing " + . join(', ', @missing) . "\n"; +} + sub architectures { return @ARCHITECTURES; } diff --git a/t/genesis_oe_source_dir.t b/t/genesis_oe_source_dir.t new file mode 100644 index 0000000..546caf0 --- /dev/null +++ b/t/genesis_oe_source_dir.t @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use Test::More; + +use XCAT::GenesisRelease qw(oe_source_dir); + +# xcat-core 2a7364476 renamed xCAT-genesis-builder to xCAT-genesis-base. A dep build +# serves a released core that still carries the old name and a master that carries the +# new one, so it must take either. +# oe_source_dir dies when it resolves nothing. Report that as a failed assertion rather +# than letting it abort the file: a die emits no TAP, so prove reports "no plan found" and +# names nothing, which reads as a harness problem instead of the defect it is. +sub resolved { + my @args = @_; + my $dir = eval { oe_source_dir(@args) }; + return defined($dir) ? $dir : "died: $@"; +} + +sub core_with { + my (@paths) = @_; + my $root = tempdir(CLEANUP => 1); + foreach my $path (@paths) { + my ($dir) = $path =~ m{^(.*)/[^/]+$}; + make_path("$root/$dir"); + open(my $fh, '>', "$root/$path") or die "cannot create $path: $!"; + close($fh); + } + return $root; +} + +is(resolved(core_with(qw(xCAT-genesis-base/oe/build xCAT-genesis-base/oe/export))), + 'xCAT-genesis-base/oe', 'a renamed checkout resolves to the new directory'); + +is(resolved(core_with(qw(xCAT-genesis-builder/oe/build xCAT-genesis-builder/oe/export))), + 'xCAT-genesis-builder/oe', 'a checkout from before the rename still resolves'); + +is(resolved(core_with(qw( + xCAT-genesis-base/oe/build xCAT-genesis-base/oe/export + xCAT-genesis-builder/oe/build xCAT-genesis-builder/oe/export))), + 'xCAT-genesis-base/oe', 'a checkout carrying both prefers the new directory'); + +# Half a directory is not a directory: the build runs both scripts, so one without the +# other must fail here rather than at the second run_command. +is(resolved(core_with(qw(xCAT-genesis-base/oe/build xCAT-genesis-builder/oe/build + xCAT-genesis-builder/oe/export))), + 'xCAT-genesis-builder/oe', 'a new directory missing export falls back to the complete one'); + +my $half = core_with(qw(xCAT-genesis-base/oe/build)); +ok(!eval { oe_source_dir($half); 1 }, 'a checkout with no complete directory dies'); +like($@, qr{xCAT-genesis-base/oe/export}, 'the error names what the new directory lacks'); +like($@, qr{xCAT-genesis-builder/oe/build}, 'the error names the old directory too'); + +my $empty = core_with(); +ok(!eval { oe_source_dir($empty); 1 }, 'a checkout with neither directory dies'); +like($@, qr{no OpenEmbedded Genesis builder}, 'the error says what is missing'); + +# The caller asks for the two scripts it runs; a caller that needs one gets one. +is(resolved(core_with(qw(xCAT-genesis-base/oe/build)), 'build'), + 'xCAT-genesis-base/oe', 'a caller may require a subset'); + +done_testing();