2 # nailing-cargo: wrapper to use unpublished local crates
3 # SPDX-License-Identifier: AGPL-3.0-or-later
10 use File::Glob qw(bsd_glob GLOB_ERR GLOB_BRACE GLOB_NOMAGIC);
13 RPI => 'arm-unknown-linux-gnueabihf',
17 $self = $0; $self =~ s{^.*/(?=.)}{};
19 while ($deref =~ m{^/}) {
20 my $link = readlink $deref;
23 or die "$self: checking our script location $deref: $!\n";
24 $deref =~ s{/[^/]+$}{}
25 or die "$self: unexpected script path: $deref\n";
26 unshift @INC, $deref."/TOML-Tiny/lib";
29 last if $link !~ m{^/};
34 use Fcntl qw(LOCK_EX);
36 use TOML::Tiny::Faithful;
38 our $src_absdir = getcwd() // die "$self: getcwd failed: $!\n";
40 our $worksphere = $src_absdir;
41 $worksphere =~ s{/([^/]+)$}{}
42 or die "$self: cwd \`$worksphere' unsupported!\n";
43 our $subdir = $1; # leafname
45 our $lockfile = "../.nailing-cargo.lock";
49 our $command_is_cargo;
51 our $cargo_lock_update;
57 # build (default) =>[qw( )],
58 'generate-lockfile'=>[qw( lock-update !target !target-dir )],
59 update =>[qw( lock-update !target online )],
60 fetch =>[qw( online !target-dir )],
63 our @subcmd_xprops = qw(!manifest-path !offline !locked);
70 sub read_or_enoent ($) {
72 if (!open R, '<', $fn) {
73 return undef if $!==ENOENT;
74 die "$self: open $fn: $!\n";
77 my ($r) = <R> // die "$self: read $fn: $!\n";
81 sub stat_exists ($$) {
83 if (stat $fn) { return 1; }
84 $!==ENOENT or die "$self: stat $what: $fn: $!\n";
89 print STDERR " subcmd_p ".(join ' ', keys %$cargo_subcmd)." | @_\n"
91 $cargo_subcmd->{$_[0]}
94 sub toml_or_enoent ($$) {
96 my $toml = read_or_enoent($f) // return;
97 print STDERR "Read TOML from $f\n" if $dump;
98 my ($v,$e) = from_toml($toml);
101 die "$self: parse TOML: $what: $f: $e\n";
103 die "$e ?" if length $e;
107 sub load1config ($) {
109 my $toml = toml_or_enoent($f, "config file");
110 push @configs, $toml if defined $toml;
114 my $dotfile = ".nailing-cargo.toml";
115 load1config("../Nailing-Cargo.toml");
116 load1config($dotfile);
117 load1config("$ENV{HOME}/$dotfile") if defined $ENV{HOME};
118 load1config("/etc/nailing-cargo/cfg.toml");
121 sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
125 "@$x[0..5]" eq "@$y[0..5]";
130 open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
131 flock LOCK, LOCK_EX or die "$self: lock $lockfile: $!\n";
132 my @fstat = stat LOCK or die "$self: fstat: $!\n";
133 my @stat = stat $lockfile;
135 next if $! == ENOENT;
136 die "$self: stat $lockfile: $!\n";
138 last if same_file(\@fstat,\@stat);
142 unlink $lockfile or die "$self: removing lockfile: $!\n";
150 die "$self: config key \`@_': $m\n";
154 foreach my $cfg (@configs) {
157 last unless defined $v;
158 ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
161 return $v if defined $v;
169 my $got = ref($v) || 'scalar';
170 return $v if !defined($v) || $got eq $exp;
171 badcfg @_, "found \L$got\E, expected \L$exp\E";
172 # ^ toml doesn't make refs to scalars, so this is unambiguous
177 (cfge $exp, @_) // badcfg @_, "missing";
180 sub cfgs { cfge 'scalar', @_ }
181 sub cfgsn { cfgn 'scalar', @_ }
185 return $v if !defined($v) || Types::Serialiser::is_bool $v;
186 badcfg @_, "expected boolean";
190 my $l = cfge 'ARRAY', @_;
191 foreach my $x (@$l) {
192 !ref $x or badcfg @_, "list contains non-scalar element";
198 my $nailfile = "../Cargo.nail";
199 open N, '<', $nailfile or die "$self: open $nailfile: $!\n";
201 my $toml = <N> // die "$self: read $nailfile: $!";
203 if ($toml !~ m{^\s*\[/}m &&
204 $toml !~ m{^[^\n\#]*\=}m &&
205 # old non-toml syntax
206 $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
207 $toml =~ s{^}{[packages\]\n};
209 $toml =~ s{^[ \t]*\-[ \t]*\=[ \t]*(\"[-_0-9a-z]+\"\n?)$}{
212 $toml = "subdirs = [\n".(join '', map { "$_\n" } @sd)."]\n".$toml;
216 ($nail,$e) = from_toml($toml);
217 if (!defined $nail) {
220 print STDERR "$self: $nailfile transformed into TOML:\n$toml\n";
223 die "$self: parse $nailfile: $e\n";
225 die "$e ?" if length $e;
227 $nail->{subdirs} //= [ ];
229 if (!ref $nail->{subdirs}) {
232 map { s/^\s+//; s/\s+$//; $_; }
238 unshift @configs, $nail;
241 our @alt_cargo_lock_stat;
243 sub consider_alt_cargo_lock () {
244 my @ck = qw(alt_cargo_lock);
245 # User should *either* have Cargo.lock in .gitignore,
246 # or expect to commit Cargo.lock.example ($alt_cargo_lock)
248 $alt_cargo_lock = (cfg_uc @ck);
251 if (defined($alt_cargo_lock) && ref($alt_cargo_lock) eq 'HASH') {
252 $force = cfg_bool qw(alt_cargo_lock force);
253 my @ck = qw(alt_cargo_lock file);
254 $alt_cargo_lock = cfg_uc @ck;
256 $alt_cargo_lock //= Types::Serialiser::true;
258 if (Types::Serialiser::is_bool $alt_cargo_lock) {
259 if (!$alt_cargo_lock) { $alt_cargo_lock = undef; return; }
260 $alt_cargo_lock = 'Cargo.lock.example';
263 if (ref($alt_cargo_lock) || $alt_cargo_lock =~ m{/}) {
264 badcfg @ck, "expected boolean, or leafname";
267 if (!stat_exists $alt_cargo_lock, "alt_cargo_lock") {
268 $alt_cargo_lock = undef unless $force;
272 @alt_cargo_lock_stat = stat _;
275 our $oot_dir; # oot.dir or "Build"
278 sub consider_oot () {
279 $oot_dir = cfgs qw(oot dir);
280 my $use = cfgs qw(oot use);
281 unless (defined($oot_dir) || defined($use) ||
282 defined(cfg_uc qw(oot user))) {
285 if (($use//'') eq 'disable') {
289 $oot_dir //= 'Build';
290 $oot_absdir = ($oot_dir !~ m{^/} ? "$worksphere/" : ""). $oot_dir;
298 sub read_manifest ($$$) {
299 my ($subdir, $org_subdir, $why) = @_;
300 my $manifest = "../$subdir/Cargo.toml";
301 print STDERR "$self: reading $manifest...\n" if $verbose>=4;
302 if (defined $manifests{$manifest}) {
304 "$self: warning: $subdir: specified more than once!".
305 " (ignoring $why)\n";
308 foreach my $try ("$manifest.unnailed", "$manifest") {
309 my $toml = toml_or_enoent($try, "manifest, in $why") // next;
310 my $ws = $toml->{workspace};
312 queue_workspace_members($subdir, $org_subdir, $ws, "$subdir, $why");
314 my $p = $toml->{package}{name};
315 if (!defined $p and !defined $ws) {
317 "$self: warning: $subdir, $why: missing package.name in $try, ignoring\n";
320 $manifests{$manifest} = $toml if $p;
326 sub queue_workspace_members ($$) {
327 my ($subdir, $org_subdir, $ws_toml, $what) = @_;
328 # We need to (more or less) reimplement the cargo workspace
329 # membership algorithm (see the "workspaces" section of the cargo
330 # reference). How tiresome.
332 # It's not quite the same for us because we aren't interested in
333 # whether cargo thinks things are "in the workspace". But we do
334 # need to do the automatic discover.
336 my @include = @{ $ws_toml->{members} // [ ] };
337 my $exclude = $ws_toml->{exclude} // [ ];
340 s/[^*?0-9a-zA-Z_]/\\$&/g;
345 foreach my $spec (@include) {
346 if ($spec =~ m{^/}) {
348 "$self: warning: absolute workspace member $spec in $what (not nailing, but cargo will probably use it)\n";
351 my $spec_glob = "../$subdir/$spec";
352 my $globflags = GLOB_ERR|GLOB_BRACE|GLOB_NOMAGIC;
353 foreach my $globent (bsd_glob($spec_glob, $globflags)) {
354 next if grep { $globent =~ m{^$_$} } @exclude;
355 queue_referenced_path($globent, $org_subdir,
356 "member of workspace $what");
361 sub queue_referenced_path ($$$) {
362 my ($spec_path, $org_subdir, $why) = @_;
364 qw(realpath), "--relative-to=../$org_subdir", "--", $spec_path
365 or die "$self: fork/pipe/exec for realpath(1)\n";
366 my $rel_path = do { local $/=undef; <REALPATH>; };
368 my $r = close(REALPATH);
369 die "$self: reap realpath: $!\n" if $!;
370 if (!chomp($rel_path) or $?) {
372 "$self: warning: failed to determine realpath for $spec_path in $org_subdir (exit code $?)\n";
375 if ($rel_path =~ m{^\.\./} or $rel_path eq '..') {
377 "$self: warning: $spec_path ($why) points outside $org_subdir, not following so not nailing (although cargo probably will follow it)\n";
381 my $q_subdir = "$org_subdir/$rel_path";
382 print STDERR "$self: making a note to look at $q_subdir, $why)\n"
385 push @queued_paths, [ "$q_subdir", $org_subdir, $why ];
389 foreach my $p (keys %{ $nail->{packages} }) {
390 my $v = $nail->{packages}{$p};
391 my $subdir = ref($v) ? $v->{subdir} : $v;
392 my ($gotpackage, $ws) = read_manifest($subdir, $subdir, "from [packages]");
393 $gotpackage //= '<nothing!>';
394 if ($gotpackage ne $p) {
396 "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
398 die if defined $packagemap{$p};
399 $packagemap{$p} = $subdir;
401 foreach my $subdir (@{ $nail->{subdirs} }) {
402 my ($gotpackage,$ws) = read_manifest($subdir, $subdir, "from [subdirs]");
403 if (!defined $gotpackage) {
405 "$self: warning: ignoring subdir $subdir which has no (suitable) Cargo.toml\n"
409 $packagemap{$gotpackage} //= $subdir;
411 while (my ($subdir, $org_subdir, $why) = @{ shift @queued_paths or [] }) {
412 next if $manifests{"../$subdir/Cargo.toml"};
413 my ($gotpackage, $ws) = read_manifest($subdir, $org_subdir, $why);
414 next unless $gotpackage;
415 $packagemap{$gotpackage} //= $subdir;
420 foreach my $p (sort keys %packagemap) {
421 print STDERR "$self: package $p in $packagemap{$p}\n" if $verbose>=2;
423 foreach my $mf (keys %manifests) {
424 my $toml = $manifests{$mf};
425 foreach my $k (qw(dependencies build-dependencies dev-dependencies)) {
426 my $deps = $toml->{$k};
428 foreach my $p (keys %packagemap) {
429 my $info = $deps->{$p};
430 next unless defined $info;
431 $deps->{$p} = $info = { } unless ref $info;
432 delete $info->{version};
433 $info->{path} = $worksphere.'/'.$packagemap{$p};
436 my $nailing = "$mf.nailing~";
437 unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
438 open N, '>', $nailing or die "$self: create new $nailing: $!\n";
439 print N to_toml($toml) or die "$self: write new $nailing: $!\n";
440 close N or die "$self: close new $nailing: $!\n";
445 if (!defined $online) {
446 $_ = cfg_uc qw(misc online);
448 } elsif (Types::Serialiser::is_bool $_) {
453 } elsif (m/^[1ty]/) { # allow booleanish strings
454 $online = 1; # for less user frustration
455 } elsif (m/^[0fn]/) {
458 badcfg qw(misc online), "expected boolean or 'auto', found '$_'";
461 $online //= 1 if subcmd_p('online');
464 $cargo_lock_update //= subcmd_p('lock-update');
468 if (!$cargo_lock_update) {
469 push @add, qw(--locked) unless subcmd_p('!locked');
470 if (defined($oot_dir) && !subcmd_p('!manifest-path')) {
471 my $cargotoml = "${src_absdir}/Cargo.toml";
472 push @args_preface, "--manifest-path=$cargotoml" if $pass_options;
473 push @add, qw(--target-dir=target) unless subcmd_p('!target-dir');
477 if (defined($target) && !subcmd_p('!target')) {
478 if ($target =~ m{^[A-Z]}) {
479 $target = (cfgs 'arch', $target) // $archmap{$target}
480 // die "$self: --target=$target alias specified; not in cfg or map\n";
482 push @add, "--target=$target";
485 push @add, "--offline" unless $online || subcmd_p('!offline');
487 push @args_preface, @add if $pass_options;
488 die if grep { m/ / } @add;
489 $ENV{NAILINGCARGO_CARGO_OPTIONS} = "@add";
491 unshift @ARGV, @args_preface;
494 our $build_absdir; # .../Build/<subdir>
496 sub oot_massage_cmdline () {
497 return unless defined $oot_dir;
499 my $use = cfgs qw(oot use);
500 $use // die "$self: out-of-tree build, but \`oot.use' not configured\n";
501 $build_absdir = "$oot_absdir/$subdir";
505 if (!$cargo_lock_update) {
506 push @xargs, $build_absdir;
507 ($pre, $post) = ('cd "$1"; shift; ', '');
509 push @xargs, $oot_absdir, $subdir, $src_absdir;
512 mkdir -p -- "$1"; cd "$1"; shift;
513 cp -- "$1"/Cargo.toml
515 $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
523 mkdir -p src; >src/lib.rs; >build.rs
526 rm -r src Cargo.toml build.rs;
529 my $addpath = (cfg_uc qw(oot path_add)) //
530 $use eq 'really' ? Types::Serialiser::true : Types::Serialiser::false;
532 !Types::Serialiser::is_bool $addpath ? $addpath :
533 $addpath ? '$HOME/.cargo/bin' :
535 if (defined $addpath) {
537 PATH=$addpath:\${PATH-/usr/local/bin:/bin:/usr/bin};
541 $pre =~ s/^\s+//mg; $pre =~ s/\s+/ /g;
542 $post =~ s/^\s+//mg; $post =~ s/\s+/ /g;
544 my $getuser = sub { cfgsn qw(oot user) };
546 my $xe = $verbose >= 2 ? 'xe' : 'e';
549 @command = (@_, 'sh',"-${xe}c",$pre.'exec "$@"','--',@xargs);
551 @command = (@_, 'sh',"-${xe}c",$pre.'"$@"; '.$post,'--',@xargs);
553 push @command, @ARGV;
555 my $command_sh = sub {
556 my $quoted = join ' ', map {
561 @command = @_, "set -${xe}; $pre $quoted; $post";
563 print STDERR "$self: out-of-tree, building in: \`$build_absdir'\n"
565 if ($use eq 'really') {
566 my $user = $getuser->();
567 my @pw = getpwnam $user or die "$self: oot.user \`$user' lookup failed\n";
568 my $homedir = $pw[7];
569 $sh_ec->('really','-u',$user,'env',"HOME=$homedir");
570 print STDERR "$self: using really to run as user \`$user'\n" if $verbose;
571 } elsif ($use eq 'ssh') {
572 my $user = $getuser->();
573 $user .= '@localhost' unless $user =~ m/\@/;
574 $command_sh->('ssh',$user);
575 print STDERR "$self: using ssh to run as \`$user'\n" if $verbose;
576 } elsif ($use eq 'command_args') {
577 my @c = cfgn_list qw(oot command);
579 print STDERR "$self: out-of-tree, adverbial command: @c\n" if $verbose;
580 } elsif ($use eq 'command_sh') {
581 my @c = cfgn_list qw(oot command);
583 print STDERR "$self: out-of-tree, ssh'ish command: @c\n" if $verbose;
584 } elsif ($use eq 'null') {
587 die "$self: oot.use mode $use not recognised\n";
594 $ENV{CARGO_MANIFEST_DIR} = $src_absdir;
595 $ENV{NAILINGCARGO_MANIFEST_DIR} = $src_absdir;
596 $ENV{NAILINGCARGO_WORKSPHERE} = $worksphere;
597 $ENV{NAILINGCARGO_BUILDSPHERE} = $oot_absdir;
598 delete $ENV{NAILINGCARGO_BUILDSPHERE} unless $oot_absdir;
599 $ENV{NAILINGCARGO_BUILD_DIR} = $build_absdir // $src_absdir;
605 if ($want_uninstall) {
607 foreach my $mf (keys %manifests) {
608 eval { uninstall1($mf,1); 1; } or warn "$@";
610 eval { unaltcargolock(1); 1; } or warn "$@";
614 sub consider_directories () {
615 return unless defined $oot_dir;
616 my $bsubdir = "../$oot_dir/$subdir";
617 return if stat $bsubdir;
618 die "$0: build directory $bsubdir inaccessible\n"
620 return if $cargo_lock_update; # will make it
621 die "$0: build directory $bsubdir does not exist, and not in Cargo.lock update mode!\n";
624 our $cleanup_cargo_lock;
626 foreach my $mf (keys %manifests) {
627 link "$mf", "$mf.unnailed" or $!==EEXIST
628 or die "$self: make backup link $mf.unnailed: $!\n";
631 if (defined($alt_cargo_lock)) {
632 if (@alt_cargo_lock_stat) {
633 print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
635 if (link $alt_cargo_lock, 'Cargo.lock') {
636 print STDERR " linked\n" if $verbose>=3;
637 } elsif ($! != EEXIST) {
638 print STDERR "\n" if $verbose>=3;
639 die "$self: make \`Cargo.lock' available as \`$alt_cargo_lock': $!\n";
641 print STDERR "checking quality." if $verbose>=3;
642 my @lock_stat = stat 'Cargo.lock'
643 or die "$self: stat Cargo.lock (for alt check: $!\n";
644 same_file(\@alt_cargo_lock_stat, \@lock_stat)
646 "$self: \`Cargo.lock' and alt file \`$alt_cargo_lock' both exist and are not the same file!\n";
648 $cleanup_cargo_lock = 1;
650 $cleanup_cargo_lock = 1;
651 # If Cargo.lock exists and alt doesn't, that means either
652 # that a previous run was interrupted, or that the user has
660 my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
665 my @our_unfound_stab = stat_exists('Cargo.toml', 'local Cargo.toml')
667 foreach my $mf (keys %manifests) {
668 if (@our_unfound_stab) {
669 if (stat_exists $mf, "manifest in to-be-nailed directory") {
670 my @mf_stab = stat _ ;
671 if ("@mf_stab[0..1]" eq "@our_unfound_stab[0..1]") {
672 @our_unfound_stab = ();
677 my $nailing = "$mf.nailing~";
678 my $nailed = nailed($mf);
681 if (open NN, '<', $nailed) {
682 $diff = compare($nailing, \*NN);
683 die "$self: compare $nailing and $nailed: $!" if $diff<0;
685 $!==ENOENT or die "$self: check previous $nailed: $!\n";
695 rename $use, $mf or die "$self: install nailed $use: $!\n";
696 unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
697 print STDERR "$self: nailed $mf\n" if $verbose>=3;
700 if (@our_unfound_stab) {
702 "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
707 my $r = system @ARGV;
711 print STDERR "$self: could not execute $ARGV[0]: $!\n";
713 } elsif ($r & 0xff00) {
714 print STDERR "$self: $ARGV[0] failed (exit status $r)\n";
717 print STDERR "$self: $ARGV[0] died due to signal! (wait status $r)\n";
722 sub cargo_lock_update_after () {
723 if ($cargo_lock_update) {
724 # avoids importing File::Copy and the error handling is about as good
726 my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
727 die "$self: run cp: $! $?" if $r<0 || $r & 0xff;
728 die "$self: failed to update local Cargo.lock (wait status $r)\n" if $r;
732 sub uninstall1 ($$) {
733 my ($mf, $enoentok) = @_;
734 my $unnailed = "$mf.unnailed";
735 rename $unnailed, $mf or ($enoentok && $!==ENOENT)
736 or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
739 sub unaltcargolock ($) {
741 return unless $cleanup_cargo_lock;
742 die 'internal error!' unless defined $alt_cargo_lock;
744 # we ignore $enoentok because we don't know if one was supposed to
747 rename('Cargo.lock', $alt_cargo_lock) or $!==ENOENT or die
748 "$self: cleanup: rename possibly-updated \`Cargo.lock' to \`$alt_cargo_lock': $!\n";
750 unlink 'Cargo.lock' or $!==ENOENT or die
751 "$self: cleanup: remove \`Cargo.lock' in favour of \`$alt_cargo_lock': $!\n";
752 # ^ this also helps clean up the stupid rename() corner case
756 foreach my $mf (keys %manifests) {
757 my $nailed = nailed($mf);
758 link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
767 # Loop exit condition:
770 # $is_cargo==1 <cargo-command> <cargo-opts> [--] <subcmd>...
771 # $is_cargo==0 <build-command>...
774 @ARGV or die "$self: need cargo subcommand\n";
779 my $not_a_nailing_opt = sub { # usage 1
780 unshift @ARGV, $orgopt;
781 unshift @ARGV, 'cargo';
783 no warnings qw(exiting);
786 $not_a_nailing_opt->() unless m{^-};
787 $not_a_nailing_opt->() if $_ eq '--';
789 if ($_ eq '---') { # usage 2 or 3
790 die "$self: --- must be followed by build command\n" unless @ARGV;
791 if ($ARGV[0] eq '--') { # usage 3
794 } elsif (grep { $_ eq '--' } @ARGV) { # usage 2
796 } elsif ($ARGV[0] =~ m{[^/]*cargo[^/]*$}) { # usage 2
807 } elsif (s{^-q}{-}) {
809 } elsif (s{^-n}{-}) {
811 } elsif (s{^-s(.+)}{-}s) {
813 } elsif (s{^-([uU])}{-}) {
814 $cargo_lock_update = $1=~m/[a-z]/;
815 } elsif (s{^-([cC])}{-}) {
816 $pass_options = $1=~m/[a-z]/;
817 } elsif (s{^-D}{-}) {
819 } elsif (s{^-T(.+)}{-}s) {
821 } elsif (s{^-([oO])}{-}) {
822 $online = $1=~m/[a-z]/;
824 die "$self: unknown short option(s) $_\n" unless $_ eq $orgopt;
825 $not_a_nailing_opt->();
828 } elsif (s{^--target=}{}) {
830 } elsif (m{^--(on|off)line$}) {
831 $online = $1 eq 'on';
832 } elsif (s{^--subcommand-props=}{}) {
833 my @props = split /\,/, $_;
835 if (!%subcmd_prop_ok) {
836 foreach my $v (\@subcmd_xprops, values %subcmd_props) {
837 $subcmd_prop_ok{$_}=1 foreach @$v;
841 or die "$self: unknown subcommand property \`$_'\n"
843 $cargo_subcmd = \@props;
844 } elsif (m{^--(no-)?cargo-lock-update}) {
845 $cargo_lock_update= !!$1;
847 $not_a_nailing_opt->();
855 @args_preface = shift @ARGV;
856 while (defined($_ = shift @ARGV)) {
857 if (!m{^-}) { unshift @ARGV, $_; last; }
858 if ($_ eq '--') { last; }
859 push @args_preface, $_;
861 @ARGV || die "$self: need cargo subcommand\n";
862 $cargo_subcmd //= $ARGV[0];
865 $cargo_subcmd //= '';
868 push @args_preface, shift @ARGV;
870 if (!ref($cargo_subcmd)) {
871 print STDERR " cargo_subcmd lookup $cargo_subcmd\n" if $dump;
872 $cargo_subcmd = $subcmd_props{$cargo_subcmd} // [ ];
875 print STDERR " cargo_subcmd props @$cargo_subcmd\n" if $dump;
877 $cargo_subcmd{$_} = 1 foreach @$cargo_subcmd;
878 $cargo_subcmd = \%cargo_subcmd;
885 consider_alt_cargo_lock();
890 consider_directories();
891 our @display_cmd = @ARGV;
892 oot_massage_cmdline();
898 print STDERR Dumper(\%manifests) if $dump>=2;
899 print STDERR Dumper(\%packagemap, \@ARGV,
900 { src_absdir => $src_absdir,
901 worksphere => $worksphere,
904 oot_absdir => $oot_absdir,
905 build_absdir => $build_absdir });
915 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
916 (scalar keys %manifests), (scalar keys %packagemap),
917 (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
920 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
921 my $estatus = invoke();
923 cargo_lock_update_after();
928 print STDERR "$self: unnailed. status $estatus.\n" if $verbose;