From fd498ddfff325df75edb7ce1693a36cd61ed0fad Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 31 Dec 2019 14:14:52 +0000 Subject: [PATCH] catacomb-import-update: --import: Write .mk file This provides some variables that will be used by secnet's makefiles to arrange that we run --convert at the right times. Signed-off-by: Ian Jackson --- catacomb-import-update | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/catacomb-import-update b/catacomb-import-update index 7c41c96..367609c 100755 --- a/catacomb-import-update +++ b/catacomb-import-update @@ -33,6 +33,7 @@ my $DONOR_REVISION = "UNKNOWN"; my $DONOR_DIR; my $DONOR_IMPORT_DIR = "catacomb-import"; my $RECIP_DIR = 'cat'; +my $MAKEFILE_FRAGMENT = "secnet-import.auto.mk"; (my $PROG = $0) =~ s{^.*/}{}; @@ -47,11 +48,16 @@ my %DONOR_PATH_MAP = (); my %DONOR_REV_MAP = (); my %RECIP_CACHE = (); my @RENAME_LIST; +my %RECIP_LIST = (); sub note_path ($$) { my ($donor, $recip) = @_; - return if $DOCONVERT; + $RECIP_LIST{$recip}=1 if defined $recip; + if ($DOCONVERT) { + $DONOR_REV_MAP{$donor} = ''; + return; + } my $recip_rev = capturex "git", "rev-list", "--max-count=1", "HEAD", "--", "$DONOR_IMPORT_DIR/$donor"; chomp $recip_rev; @@ -91,6 +97,19 @@ sub note_path ($$) { $DONOR_REV_MAP{$donor} = $donor_rev; } +sub write_makefile_fragment ($) { + my ($to_t) = @_; + open my $out, ">", "$to_t"; + print $out "# autogenerated by $PROG, do not edit\n"; + foreach my $donor (sort keys %DONOR_REV_MAP) { + print $out "CATACOMB_IMPORT_DONORS += $donor\n"; + } + foreach my $recip (sort keys %RECIP_LIST) { + print $out "CATACOMB_IMPORT_RECIPS += $recip\n"; + } + close $out; +} + sub commit_changes () { my $msg = ""; my $any_changes = 0; @@ -103,6 +122,10 @@ sub commit_changes () { my @paths = sort keys %DONOR_REV_MAP; runx 'rsync', '-Rc', (map { "$DONOR_DIR/./$_" } @paths), $DONOR_IMPORT_DIR; + + my $mff = "$DONOR_IMPORT_DIR/$MAKEFILE_FRAGMENT"; + write_makefile_fragment("$mff.new"); + rename "$mff.new", "$mff"; ## Stage updated files for commit. runx "git", "add", "-A", $dir; @@ -142,6 +165,7 @@ sub commit_changes () { $msg .= "\nDetailed list of changes:\n"; my @lpaths; my @roots; for my $path (sort keys %changed) { + if ($path eq $MAKEFILE_FRAGMENT) { $msg .= " Updated $path.\n"; next; } if (!exists $DONOR_REV_MAP{$path}) { $msg .= " Deleted $path.\n"; next; } my $rev = $DONOR_REV_MAP{$path}; if (defined $rev) { push @lpaths, $path; push @roots, $rev; } -- 2.30.2