chiark / gitweb /
nailing-cargo: Update mode: cope if Cargo.lock starts absent
[nailing-cargo.git] / nailing-cargo
1 #!/usr/bin/perl -w
2
3 #    nailing-cargo: wrapper to use unpublished local crates
4 #
5 #    Copyright (C) 2019-2020 Ian Jackson
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # example usages:
21 #   ../nailing-cargo/nailing-caretwgo make
22 #   ../nailing-cargo/nailing-cargo cargo build
23 #   CARGO='../nailing-cargo/nailing-cargo cargo' make
24
25 # Why do we need this ?
26 #
27 #  https://github.com/rust-lang/cargo/issues/6713
28 #  https://stackoverflow.com/questions/33025887/how-to-use-a-local-unpublished-crate
29 #  https://github.com/rust-lang/cargo/issues/1481
30
31 # Needs libtoml-perl
32
33 #: Cargo.nail:
34 #
35 #    [packages]
36 #    package = subdir
37 #    package = { subdir = ... }
38 #
39 #    [subdirs]
40 #    subdir
41
42 our $self;
43
44 use strict;
45 use POSIX;
46 use Types::Serialiser;
47
48 our %archmap = (
49     RPI => 'arm-unknown-linux-gnueabihf',
50 );
51
52 BEGIN {
53   $self = $0;  $self =~ s{^.*/(?=.)}{};
54   my $deref = $0;
55   while ($deref =~ m{^/}) {
56     my $link = readlink $deref;
57     if (!defined $link) {
58       $! == EINVAL
59         or die "$self: checking our script location $deref: $!\n";
60       $deref =~ s{/[^/]+$}{}
61         or die "$self: unexpected script path: $deref\n";
62       unshift @INC, $deref."/TOML-Tiny/lib";
63       last;
64     }
65     last if $link !~ m{^/};
66     $deref = $link;
67   }
68 }
69
70 use Fcntl qw(LOCK_EX);
71 use File::Compare;
72 use TOML::Tiny::Faithful;
73
74 our $src_absdir = getcwd() // die "$self: getcwd failed: $!\n";
75
76 our $worksphere = $src_absdir;
77 $worksphere =~ s{/([^/]+)$}{}
78   or die "$self: cwd \`$worksphere' unsupported!\n";
79 our $subdir = $1; # leafname
80
81 our $lockfile = "../.nailing-cargo.lock";
82
83 our $cargo_lock_update;
84 our $cargo_manifest_args;
85 our $alt_cargo_lock;
86
87 our @configs;
88 our $verbose=1;
89 our ($noact,$dump);
90 our $target;
91
92 sub read_or_enoent ($) {
93   my ($fn) = @_;
94   if (!open R, '<', $fn) {
95     return undef if $!==ENOENT;
96     die "$self: open $fn: $!\n";
97   }
98   local ($/) = undef;
99   my ($r) = <R> // die "$self: read $fn: $!\n";
100   $r;
101 }
102
103 sub stat_exists ($$) {
104   my ($fn, $what) = @_;
105   if (stat $fn) { return 1; }
106   $!==ENOENT or die "$self: stat $what: $fn: $!\n";
107   return 0;
108 }
109
110 sub toml_or_enoent ($$) {
111   my ($f,$what) = @_;
112   my $toml = read_or_enoent($f) // return;
113   my ($v,$e) = from_toml($toml);
114   if (!defined $v) {
115     chomp $e;
116     die "$self: parse TOML: $what: $f: $e\n";
117   }
118   die "$e ?" if length $e;
119   $v;
120 }
121
122 sub load1config ($) {
123   my ($f) = @_;
124   my $toml = toml_or_enoent($f, "config file");
125   push @configs, $toml if defined $toml;
126 }
127
128 sub loadconfigs () {
129   my $cfgleaf = ".nailing-cargo-cfg.toml";
130   load1config("/etc/nailing-cargo/cfg.toml");
131   load1config("$worksphere/$cfgleaf");
132   load1config("$ENV{HOME}/$cfgleaf") if defined $ENV{HOME};
133 }
134
135 sub getcfg ($$) {
136   my ($k, $def) = @_;
137   foreach my $cfg (@configs) {
138     my $v = $cfg->{$k};
139     return $v if defined $v;
140   }
141   return $def;
142 }
143
144 sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
145
146 sub same_file ($$) {
147   my ($x,$y) = @_;
148   "@$x[0..5]" eq "@$y[0..5]";
149 }
150
151 sub takelock () {
152   for (;;) {
153     open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
154     flock LOCK, LOCK_EX or die "$self: lock $lockfile: $!\n";
155     my @fstat = stat LOCK or die "$self: fstat: $!\n";
156     my @stat  = stat $lockfile;
157     if (!@stat) {
158       next if $! == ENOENT;
159       die "$self: stat $lockfile: $!\n";
160     }
161     last if same_file(\@fstat,\@stat);
162   }
163 }
164 sub unlock () {
165   unlink $lockfile or die "$self: removing lockfile: $!\n";
166 }
167
168 our $nail;
169
170 sub badcfg {
171   my $m = pop @_;
172   $" = '.';
173   die "$self: config key \`@_': $m\n";
174 }
175
176 sub cfg_uc {
177   my $v = $nail;
178   foreach my $k (@_) {
179     last unless defined $v;
180     ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
181     $v = $v->{$k};
182   }
183   return $v;
184 }
185
186 sub cfge {
187   my $exp = shift @_;
188   my $v = cfg_uc @_;
189   my $got = ref($v) || 'scalar';
190   return $v if !defined($v) || $got eq $exp;
191   badcfg @_, "found \L$got\E, expected \L$exp\E";
192   # ^ toml doesn't make refs to scalars, so this is unambiguous
193 }
194
195 sub cfgn {
196   my $exp = shift @_;
197   (cfge $exp, @_) // badcfg @_, "missing";
198 }
199
200 sub cfgs  { cfge 'scalar', @_ }
201 sub cfgsn { cfgn 'scalar', @_ }
202
203 sub cfgn_list {
204   my $l = cfge 'ARRAY', @_;
205   foreach my $x (@$l) {
206     !ref $x or badcfg @_, "list contains non-scalar element";
207   }
208   @$l
209 }
210
211 sub readnail () {
212   my $nailfile = "../Cargo.nail";
213   open N, '<', $nailfile or die "$self: open $nailfile: $!\n";
214   local ($/) = undef;
215   my $toml = <N> // die "$self: read $nailfile: $!";
216   my $transformed;
217   if ($toml !~ m{^\s*\[/}m &&
218       $toml !~ m{^[^\n\#]*\=}m &&
219       # old non-toml syntax
220       $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
221     $toml =~ s{^}{[packages\]\n};
222     my @sd;
223     $toml =~ s{^[ \t]*\-[ \t]*\=[ \t]*(\"[-_0-9a-z]+\"\n?)$}{
224       push @sd, $1; '';
225     }mige;
226     $toml = "subdirs = [\n".(join '', map { "$_\n" } @sd)."]\n".$toml;
227     $transformed = 1;
228   }
229   my $e;
230   ($nail,$e) = from_toml($toml);
231   if (!defined $nail) {
232     if ($transformed) {
233       $toml =~ s/^/    /mg;
234       print STDERR "$self: $nailfile transformed into TOML:\n$toml\n";
235     }
236     $/="\n"; chomp $e;
237     die "$self: parse $nailfile: $e\n";
238   }
239   die "$e ?" if length $e;
240
241   if (!ref $nail->{subdirs}) {
242     $nail->{subdirs} = [
243       grep /^[^\#]/,
244       map { s/^\s+//; s/\s+$//; $_; }
245       split m{\n},
246       $nail->{subdirs}
247     ];
248   }
249 }
250
251 our @alt_cargo_lock_stat;
252
253 sub consider_alt_cargo_lock () {
254   my @ck = qw(alt_cargo_lock);
255   # User should *either* have Cargo.lock in .gitignore,
256   # or expect to commit Cargo.lock.example ($alt_cargo_lock)
257
258   $alt_cargo_lock = (cfg_uc @ck) // Types::Serialiser::true;
259
260   if (Types::Serialiser::is_bool $alt_cargo_lock) {
261     if (!$alt_cargo_lock) { $alt_cargo_lock = undef; return; }
262     $alt_cargo_lock = 'Cargo.lock.example';
263   }
264
265   if (ref($alt_cargo_lock) || $alt_cargo_lock =~ m{/}) {
266     badcfg @ck, "expected boolean, or leafname";
267   }
268
269   if (!stat_exists $alt_cargo_lock, "alt_cargo_lock") {
270     $alt_cargo_lock = undef;
271     return;
272   }
273   
274   @alt_cargo_lock_stat = stat _;
275 }
276
277 our $oot_dir;      # oot.dir or "Build"
278
279 sub consider_oot () {
280   $oot_dir = cfgs qw(oot dir);
281   my $use = cfgs qw(oot use);
282   unless (defined($oot_dir) || defined($use)) {
283     $cargo_lock_update//=0;
284     return;
285   }
286   $oot_dir //= 'Build';
287 }
288
289 our %manifests;
290 our %packagemap;
291
292 sub read_manifest ($) {
293   my ($subdir) = @_;
294   my $manifest = "../$subdir/Cargo.toml";
295   print STDERR "$self: reading $manifest...\n" if $verbose>=4;
296   if (defined $manifests{$manifest}) {
297     print STDERR
298  "$self: warning: $subdir: specified more than once!\n";
299     return undef;
300   }
301   foreach my $try ("$manifest.unnailed", "$manifest") {
302     my $toml = toml_or_enoent($try, "package manifest") // next;
303     my $p = $toml->{package}{name};
304     if (!defined $p) {
305       print STDERR
306  "$self: warning: $subdir: missing package.name in $try, ignoring\n";
307       next;
308     }
309     $manifests{$manifest} = $toml;
310     return $p;
311   }
312   return undef;
313 }
314
315 sub readorigs () {
316   foreach my $p (keys %{ $nail->{packages} }) {
317     my $v = $nail->{packages}{$p};
318     my $subdir = ref($v) ? $v->{subdir} : $v;
319     my $gotpackage = read_manifest($subdir) // '<nothing!>';
320     if ($gotpackage ne $p) {
321       print STDERR
322  "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
323     }
324     die if defined $packagemap{$p};
325     $packagemap{$p} = $subdir;
326   }
327   foreach my $subdir (@{ $nail->{subdirs} }) {
328     my $gotpackage = read_manifest($subdir);
329     if (!defined $gotpackage) {
330       print STDERR
331  "$self: warning: ignoring subdir $subdir which has no Cargo.toml\n";
332       next;
333     }
334     $packagemap{$gotpackage} //= $subdir;
335   }
336 }
337
338 sub calculate () {
339   foreach my $p (sort keys %packagemap) {
340     print STDERR "$self: package $p in $packagemap{$p}\n" if $verbose>=2;
341   }
342   foreach my $mf (keys %manifests) {
343     my $toml = $manifests{$mf};
344     foreach my $k (qw(dependencies build-dependencies dev-dependencies)) {
345       my $deps = $toml->{$k};
346       next unless $deps;
347       foreach my $p (keys %packagemap) {
348         my $info = $deps->{$p};
349         next unless defined $info;
350         $deps->{$p} = $info = { } unless ref $info;
351         delete $info->{version};
352         $info->{path} = $worksphere.'/'.$packagemap{$p};
353       }
354     }
355     my $nailing = "$mf.nailing~";
356     unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
357     open N, '>', $nailing or die "$self: create new $nailing: $!\n";
358     print N to_toml($toml) or die "$self: write new $nailing: $!\n";
359     close N or die "$self: close new $nailing: $!\n";
360   }
361 }
362
363 sub addargs () {
364   if (@ARGV>=2 &&
365       $ARGV[0] =~ m{\bcargo\b} &&
366       $ARGV[1] =~ m/generate-lockfile|update/) {
367     $cargo_lock_update //= 1;
368   } else {
369     $cargo_lock_update //= 0;
370   }
371   $cargo_manifest_args //=
372     (defined $oot_dir) && !$cargo_lock_update;
373
374   if ($cargo_manifest_args) {
375     push @ARGV, "--manifest-path=${src_absdir}/Cargo.toml",
376       qw(--locked --target-dir=target);
377   }
378
379   if (defined $target) {
380     if ($target =~ m{^[A-Z]}) {
381       $target = (cfgs 'arch', $target) // $archmap{$target}
382         // die "$self: --target=$target alias specified; not in cfg or map\n";
383     }
384     push @ARGV, "--target=$target";
385   }
386 }
387
388 our $oot_absdir;
389 our $build_absdir; # .../Build/<subdir>
390
391 sub oot_massage_cmdline () {
392   return unless defined $oot_dir;
393
394   my $use = cfgs qw(oot use);
395   $oot_absdir = ($oot_dir !~ m{^/} ? "$worksphere/" : ""). $oot_dir;
396   $build_absdir = "$oot_absdir/$subdir";
397
398   my ($pre,$post);
399   my @xargs;
400   if (!$cargo_lock_update) {
401     push @xargs, $build_absdir;
402     ($pre, $post) = ('cd "$1"; shift; ', '');
403   } else {
404     push @xargs, $oot_absdir, $subdir, $src_absdir;
405     $pre =  <<'END';
406         cd "$1"; shift;
407         mkdir -p -- "$1"; cd "$1"; shift;
408         cp -- "$1"/Cargo.toml
409 END
410     $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
411               "$1"/Cargo.lock
412 ENDLK
413     $pre .= <<'ENDCP';
414                               .;
415 ENDCP
416     $pre .= <<'ENDPRE';
417         shift;
418         mkdir -p src; >src/lib.rs;
419 ENDPRE
420     $post = <<'ENDPOST';
421         rm -r src Cargo.toml;
422 ENDPOST
423   }
424   my $addpath = (cfg_uc qw(oot path_add)) //
425     $use eq 'really' ? Types::Serialiser::true : Types::Serialiser::false;
426   $addpath =
427     !Types::Serialiser::is_bool $addpath ? $addpath           :
428     $addpath                             ? '$HOME/.cargo/bin' :
429                                            undef;
430   if (defined $addpath) {
431     $pre .= <<END
432         PATH=$addpath:\${PATH-/usr/local/bin:/bin:/usr/bin};
433         export PATH;
434 END
435   }
436   $pre  =~ s/^\s+//mg; $pre  =~ s/\s+/ /g;
437   $post =~ s/^\s+//mg; $post =~ s/\s+/ /g;
438
439   my $getuser = sub { cfgsn qw(oot user) };
440   my @command;
441   my $xe = $verbose >= 2 ? 'xe' : 'e';
442   my $sh_ec = sub {
443     if (!length $post) {
444       @command = (@_, 'sh',"-${xe}c",$pre.'exec "$@"','--',@xargs);
445     } else {
446       @command = (@_, 'sh',"-${xe}c",$pre.'"$@"; '.$post,'--',@xargs);
447     }
448     push @command, @ARGV;
449   };
450   my $command_sh = sub {
451     my $quoted = join ' ', map {
452       return $_ if !m/\W/;
453       s/\'/\'\\'\'/g;
454       "'$_'"
455     } @ARGV;
456     @command = @_, "set -${xe}; $pre $quoted; $post";
457   };
458   print STDERR "$self: out-of-tree, building in: \`$build_absdir'\n"
459     if $verbose;
460   if ($use eq 'really') {
461     my $user = $getuser->();
462     my @pw = getpwnam $user or die "$self: oot.user \`$user' lookup failed\n";
463     my $homedir = $pw[7];
464     $sh_ec->('really','-u',$user,'env',"HOME=$homedir");
465     print STDERR "$self: using really to run as user \`$user'\n" if $verbose;
466   } elsif ($use eq 'ssh') {
467     my $user = $getuser->();
468     $user .= '@localhost' unless $user =~ m/\@/;
469     $command_sh->('ssh',$user);
470     print STDERR "$self: using ssh to run as \`$user'\n" if $verbose;
471   } elsif ($use eq 'command_args') {
472     my @c = cfgn_list qw(oot command);
473     $sh_ec->(@c);
474     print STDERR "$self: out-of-tree, adverbial command: @c\n" if $verbose;
475   } elsif ($use eq 'command_sh') {
476     my @c = cfgn_list qw(oot command);
477     $command_sh->(@c);
478     print STDERR "$self: out-of-tree, ssh'ish command: @c\n" if $verbose;
479   } elsif ($use eq 'null') {
480     $sh_ec->();
481   } else {
482     die "$self: oot.use mode $use not recognised\n";
483   }
484   die unless @command;
485   @ARGV = @command;
486 }
487
488 sub setenvs () {
489   $ENV{NAILINGCARGO_WORKSPHERE}   = $worksphere;
490   $ENV{NAILINGCARGO_MANIFEST_DIR} = $src_absdir;
491   $ENV{NAILINGCARGO_BUILDSPHERE}  = $oot_absdir;
492   delete $ENV{NAILINGCARGO_BUILDSPHERE} unless $oot_absdir;
493   $ENV{NAILINGCARGO_BUILD_DIR}    = $build_absdir // $src_absdir;
494 }
495
496 our $want_uninstall;
497
498 END {
499   if ($want_uninstall) {
500     local ($?);
501     foreach my $mf (keys %manifests) {
502       eval { uninstall1($mf,1); 1; } or warn "$@";
503     }
504     unaltcargolock(1) or warn "$@";
505   }
506 }
507
508 our $cleanup_remove_cargo_lock;
509 sub makebackups () {
510   foreach my $mf (keys %manifests) {
511     link "$mf", "$mf.unnailed" or $!==EEXIST
512       or die "$self: make backup link $mf.unnailed: $!\n";
513   }
514
515   if (defined $alt_cargo_lock) {
516     print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
517       if $verbose>=3;
518     if (link $alt_cargo_lock, 'Cargo.lock') {
519       print STDERR " linked\n" if $verbose>=3;
520     } elsif ($! != EEXIST) {
521       print STDERR "\n" if $verbose>=3;
522       die "$self: make \`Cargo.lock' available as \`$alt_cargo_lock': $!\n";
523     } else {
524       print STDERR "checking quality." if $verbose>=3;
525       my @lock_stat = stat 'Cargo.lock'
526         or die "$self: stat Cargo.lock (for alt check: $!\n";
527       same_file(\@alt_cargo_lock_stat, \@lock_stat)
528         or die
529 "$self: \`Cargo.lock' and alt file \`$alt_cargo_lock' both exist and are not the same file!\n";
530     }
531     $cleanup_remove_cargo_lock = 1;
532   }
533 }
534
535 sub nailed ($) {
536   my ($mf) = @_;
537   my $nailed  = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
538   $nailed;
539 }    
540
541 sub install () {
542   foreach my $mf (keys %manifests) {
543     my $nailing = "$mf.nailing~";
544     my $nailed = nailed($mf);
545     my ($use, $rm);
546     my $diff;
547     if (open NN, '<', $nailed) {
548       $diff = compare($nailing, \*NN);
549       die "$self: compare $nailing and $nailed: $!" if $diff<0;
550     } else {
551       $!==ENOENT or die "$self: check previous $nailed: $!\n";
552       $diff = 1;
553     }
554     if ($diff) {
555       $use = $nailing;
556       $rm  = $nailed;
557     } else {
558       $use = $nailed;
559       $rm  = $nailing;
560     }
561     rename $use, $mf or die "$self: install nailed $use: $!\n";
562     unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
563     print STDERR "$self: nailed $mf\n" if $verbose>=3;
564   }
565 }
566
567 sub invoke () {
568   my $r = system @ARGV;
569   if (!$r) {
570     return 0;
571   } elsif ($r<0) {
572     print STDERR "$self: could not execute $ARGV[0]: $!\n";
573     return 127;
574   } elsif ($r & 0xff00) {
575     print STDERR "$self: $ARGV[0] failed (exit status $r)\n";
576     return $r >> 8;
577   } else {
578     print STDERR "$self: $ARGV[0] died due to signal! (wait status $r)\n";
579     return 125;
580   }
581 }
582
583 sub cargo_lock_update_after () {
584   return unless $cargo_lock_update;
585   # avoids importing File::Copy and the error handling is about as good
586   $!=0; $?=0;
587   my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
588   die "$self: run cp: $! $?" if $r<0 || $r & 0xff;
589   die "$self: failed to update local Cargo.lock (wait status $r)\n" if $r;
590 }
591
592 sub uninstall1 ($$) {
593   my ($mf, $enoentok) = @_;
594   my $unnailed = "$mf.unnailed";
595   rename $unnailed, $mf or ($enoentok && $!==ENOENT)
596     or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
597 }
598
599 sub unaltcargolock ($) {
600   my ($enoentok) = @_;
601   return unless $cleanup_remove_cargo_lock;
602   die 'internal error!' unless defined $alt_cargo_lock;
603   unlink 'Cargo.lock' or ($enoentok && $!==ENOENT) or die
604  "$self: cleanup: remove \`Cargo.lock' in favour of \`$alt_cargo_lock': $!\n";
605 }
606
607 sub uninstall () {
608   foreach my $mf (keys %manifests) {
609     my $nailed = nailed($mf);
610     link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
611     uninstall1($mf,0);
612   }
613   unaltcargolock(0);
614 }
615
616 while (@ARGV && $ARGV[0] =~ m/^-/) {
617   $_ = shift @ARGV;
618   last if m{^--$};
619   if (m{^-[^-]}) {
620     while (m{^-.}) {
621       if (s{^-v}{-}) {
622         $verbose++;
623       } elsif (s{^-q}{-}) {
624         $verbose=0;
625       } elsif (s{^-n}{-}) {
626         $noact++;
627       } elsif (s{^-D}{-}) {
628         $dump++;
629       } elsif (s{^-T(.+)}{-}s) {
630         $target = $1;
631       } elsif (s{^-([uU])}{-}) {
632         $cargo_lock_update= $1=~m/[a-z]/;
633       } elsif (s{^-([mM])}{-}) {
634         $cargo_manifest_args= $1=~m/[a-z]/;
635       } else {
636         die "$self: unknown short option(s) $_\n";
637       }
638     }
639   } elsif (s{^--target=}{}) {
640     $target = $_;
641   } elsif (m{^--(no-)?cargo-lock-update}) {
642     $cargo_lock_update= !!$1;
643   } elsif (m{^--(no-)?cargo-manifest-args}) {
644     $cargo_manifest_args= !!$1;
645   } else {
646     die "$self: unknown long option $_\n";
647   }
648 }
649
650 die "$self: need command to run\n" unless @ARGV || $noact;
651
652 takelock();
653 readnail();
654 consider_alt_cargo_lock();
655 consider_oot();
656 readorigs();
657 calculate();
658 addargs();
659 our @display_cmd = @ARGV;
660 oot_massage_cmdline();
661 setenvs();
662
663 if ($dump) {
664   eval '
665     use Data::Dumper;
666     print STDERR Dumper(\%manifests) if $dump>=2;
667     print STDERR Dumper(\%packagemap, \@ARGV,
668                         { src_absdir => $src_absdir,
669                           worksphere => $worksphere,
670                           subdir => $subdir,
671                           oot_dir => $oot_dir,
672                           oot_absdir => $oot_absdir,
673                           build_absdir => $build_absdir });
674   ' or die $@;
675 }
676
677 exit 0 if $noact;
678
679 $want_uninstall = 1;
680 makebackups();
681 install();
682
683 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
684   (scalar keys %manifests), (scalar keys %packagemap),
685   (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
686   if $verbose;
687
688 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
689 my $estatus = invoke();
690
691 cargo_lock_update_after();
692
693 uninstall();
694 $want_uninstall = 0;
695
696 print STDERR "$self: unnailed.  status $estatus.\n" if $verbose;
697
698 exit $estatus;