diff --git a/build-utils/lib/XCAT/BuildUtils.pm b/build-utils/lib/XCAT/BuildUtils.pm index cba2401f0..e429f494e 100644 --- a/build-utils/lib/XCAT/BuildUtils.pm +++ b/build-utils/lib/XCAT/BuildUtils.pm @@ -26,7 +26,7 @@ use feature 'say'; our @EXPORT_OK = qw( source_date_epoch snap_release deb_version stage_probe_helpers XCAT_PROBE_HELPERS stage_genesis_base_sources - stage_xcat_probe_sources + stage_xcat_probe_sources stage_xcatsn_templates deb_package_arches dist_arches default_dists orig_tarball_name upstream_version resolve_dest pin_control_version rewrite_changelog_header @@ -476,6 +476,36 @@ sub stage_xcat_probe_sources { return $tarball; } +#------------------------------------------------------------------------------- + +=head3 stage_xcatsn_templates + +Descriptions: Write the templates archive that xCATsn.spec extracts into + %{prefix}/share/xcat. + +Arguments: + $checkout - the xcat-core source tree + $sources_dir - the staging directory of the xCATsn build + $epoch - SOURCE_DATE_EPOCH for the archive mtimes + +Returns: the path of the archive. + +=cut + +#------------------------------------------------------------------------------- +sub stage_xcatsn_templates { + my ($checkout, $sources_dir, $epoch) = @_; + die "stage_xcatsn_templates: no staging directory\n" + unless defined $sources_dir && -d $sources_dir; + + my $tarball = "$sources_dir/templates.tar.gz"; + sh_or_die(qq(tar --sort=name --owner=0 --group=0 --mtime="\@$epoch" ) + . qq(-czf "$tarball" -C "$checkout" xCAT/templates), + "Error creating $tarball") + unless -f $tarball; + return $tarball; +} + # deb_package_arches: the architectures to build a package for. # 'all' is a single arch-independent build; the three arch packages get one per arch. sub deb_package_arches { diff --git a/buildrpms.pl b/buildrpms.pl index 3de52ba0c..22a1542bd 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -55,7 +55,7 @@ use File::Temp qw(tempdir tempfile); use FindBin qw($Bin); use lib "$Bin/build-utils/lib"; use XCAT::BuildUtils qw(git_revision source_date_epoch sh sh_or_die usage buildinfo_text - prepare_build_sources_dir stage_xcat_probe_sources + prepare_build_sources_dir stage_xcat_probe_sources stage_xcatsn_templates stage_genesis_base_sources write_script read_line targetarch_from_target openeuler_build_target openeuler_repo_subdir); @@ -412,8 +412,7 @@ EOF system('build-utils/sync-xcat-apache-configs', '--stage', $SOURCES) == 0 or die "FATAL: unable to stage canonical Apache configurations\n"; cp "$pkg/xCATSN", $SOURCES; - # xCATsn.spec consumes templates from xCAT shared templates payload. - sh qq(tar --sort=name --owner=0 --group=0 --mtime="\@$SOURCE_DATE_EPOCH" -czf "$SOURCES/templates.tar.gz" xCAT/templates) unless -f "$SOURCES/templates.tar.gz"; + stage_xcatsn_templates(".", $SOURCES, $SOURCE_DATE_EPOCH); } elsif ($pkg eq "xCAT-probe") { stage_xcat_probe_sources(".", $SOURCES, $VERSION, $SOURCE_DATE_EPOCH); } else { diff --git a/xCAT-test/unit/xcatsn_templates_staged.t b/xCAT-test/unit/xcatsn_templates_staged.t new file mode 100644 index 000000000..5a7633768 --- /dev/null +++ b/xCAT-test/unit/xcatsn_templates_staged.t @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +# xCATsn.spec extracts templates.tar.gz in %{prefix}/share/xcat, so every member must +# start with templates/. +use strict; +use warnings; + +use Archive::Tar (); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use FindBin; +use lib "$FindBin::Bin/../../build-utils/lib"; +use Test::More; + +use XCAT::BuildUtils qw(stage_xcatsn_templates); + +my $epoch = 1600000000; +my $checkout = tempdir(CLEANUP => 1); +make_path("$checkout/xCAT/templates/install/rh"); +write_text("$checkout/xCAT/templates/install/rh/compute.tmpl", "first\n"); + +my $sources = tempdir(CLEANUP => 1); +my $tarball = stage_xcatsn_templates($checkout, $sources, $epoch); +is($tarball, "$sources/templates.tar.gz", 'the archive is the Source5 that xCATsn.spec names'); + +my @members = Archive::Tar->new($tarball)->list_files; +ok(scalar @members, 'the archive is not empty'); +is_deeply([grep { !m{^templates(/|$)} } @members], [], + 'every member is rooted at templates/, so it extracts to share/xcat/templates'); +is_deeply([grep { m{^xCAT/} } @members], [], + 'no member is rooted at xCAT/, which would extract to share/xcat/xCAT/templates'); +ok((grep { $_ eq 'templates/install/rh/compute.tmpl' } @members), + 'a template extracts to share/xcat/templates/install/rh'); + +# A staging directory survives between builds. A second build must ship the current templates. +write_text("$checkout/xCAT/templates/install/rh/compute.tmpl", "second\n"); +stage_xcatsn_templates($checkout, $sources, $epoch); +my ($file) = Archive::Tar->new($tarball)->get_files('templates/install/rh/compute.tmpl'); +is($file && $file->get_content, "second\n", 'a later build replaces the archive with the current templates'); + +done_testing;