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);
14 RPI => 'arm-unknown-linux-gnueabihf',
18 $self = $0; $self =~ s{^.*/(?=.)}{};
20 while ($deref =~ m{^/}) {
21 my $link = readlink $deref;
24 or die "$self: checking our script location $deref: $!\n";
25 $deref =~ s{/[^/]+$}{}
26 or die "$self: unexpected script path: $deref\n";
27 unshift @INC, $deref."/TOML-Tiny/lib";
30 last if $link !~ m{^/};
35 use Fcntl qw(LOCK_EX);
37 use TOML::Tiny::Faithful;
39 our $src_absdir = getcwd() // die "$self: getcwd failed: $!\n";
41 our $worksphere = $src_absdir;
42 $worksphere =~ s{/([^/]+)$}{}
43 or die "$self: cwd \`$worksphere' unsupported!\n";
44 our $subdir = $1; # leafname
46 our $lockfile = "../.nailing-cargo.lock";
50 our $command_is_cargo;
52 our $cargo_lock_update;
58 # build (default) =>[qw( )],
59 'generate-lockfile'=>[qw( lock-update !target !target-dir )],
60 update =>[qw( lock-update !target online )],
61 fetch =>[qw( online !target-dir )],
64 our @subcmd_xprops = qw(!manifest-path !offline !locked);
71 sub read_or_enoent ($) {
73 if (!open R, '<', $fn) {
74 return undef if $!==ENOENT;
75 die "$self: open $fn: $!\n";
78 my ($r) = <R> // die "$self: read $fn: $!\n";
82 sub stat_exists ($$) {
84 if (stat $fn) { return 1; }
85 $!==ENOENT or die "$self: stat $what: $fn: $!\n";
90 print STDERR " subcmd_p ".(join ' ', keys %$cargo_subcmd)." | @_\n"
92 $cargo_subcmd->{$_[0]}
95 sub toml_or_enoent ($$) {
97 my $toml = read_or_enoent($f) // return;
98 print STDERR "Read TOML from $f\n" if $dump;
99 my ($v,$e) = from_toml($toml);
102 die "$self: parse TOML: $what: $f: $e\n";
104 die "$e ?" if length $e;
108 sub load1config ($) {
110 my $toml = toml_or_enoent($f, "config file");
111 push @configs, $toml if defined $toml;
115 my $dotfile = ".nailing-cargo.toml";
116 load1config("../Nailing-Cargo.toml");
117 load1config($dotfile);
118 load1config("$ENV{HOME}/$dotfile") if defined $ENV{HOME};
119 load1config("/etc/nailing-cargo/cfg.toml");
122 sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
126 "@$x[0..5]" eq "@$y[0..5]";
131 open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
132 flock LOCK, LOCK_EX or die "$self: lock $lockfile: $!\n";
133 my @fstat = stat LOCK or die "$self: fstat: $!\n";
134 my @stat = stat $lockfile;
136 next if $! == ENOENT;
137 die "$self: stat $lockfile: $!\n";
139 last if same_file(\@fstat,\@stat);
143 unlink $lockfile or die "$self: removing lockfile: $!\n";
151 die "$self: config key \`@_': $m\n";
155 foreach my $cfg (@configs) {
158 last unless defined $v;
159 ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
162 return $v if defined $v;
170 my $got = ref($v) || 'scalar';
171 return $v if !defined($v) || $got eq $exp;
172 badcfg @_, "found \L$got\E, expected \L$exp\E";
173 # ^ toml doesn't make refs to scalars, so this is unambiguous
178 (cfge $exp, @_) // badcfg @_, "missing";
181 sub cfgs { cfge 'scalar', @_ }
182 sub cfgsn { cfgn 'scalar', @_ }
186 return $v if !defined($v) || Types::Serialiser::is_bool $v;
187 badcfg @_, "expected boolean";
191 my $l = cfge 'ARRAY', @_;
192 foreach my $x (@$l) {
193 !ref $x or badcfg @_, "list contains non-scalar element";
199 my $nailfile = "../Cargo.nail";
200 open N, '<', $nailfile or die "$self: open $nailfile: $!\n";
202 my $toml = <N> // die "$self: read $nailfile: $!";
204 if ($toml !~ m{^\s*\[/}m &&
205 $toml !~ m{^[^\n\#]*\=}m &&
206 # old non-toml syntax
207 $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
208 $toml =~ s{^}{[packages\]\n};
210 $toml =~ s{^[ \t]*\-[ \t]*\=[ \t]*(\"[-_0-9a-z]+\"\n?)$}{
213 $toml = "subdirs = [\n".(join '', map { "$_\n" } @sd)."]\n".$toml;
217 ($nail,$e) = from_toml($toml);
218 if (!defined $nail) {
221 print STDERR "$self: $nailfile transformed into TOML:\n$toml\n";
224 die "$self: parse $nailfile: $e\n";
226 die "$e ?" if length $e;
228 $nail->{subdirs} //= [ ];
230 if (!ref $nail->{subdirs}) {
233 map { s/^\s+//; s/\s+$//; $_; }
239 unshift @configs, $nail;
242 sub get_dependency_tables ($) {
244 my @keys = qw(dependencies build-dependencies dev-dependencies);
248 foreach my $k (@keys) {
249 my $deps = $node->{$k};
250 push @r, $deps if $deps;
257 our @alt_cargo_lock_stat;
259 sub consider_alt_cargo_lock () {
260 my @ck = qw(alt_cargo_lock);
261 # User should *either* have Cargo.lock in .gitignore,
262 # or expect to commit Cargo.lock.example ($alt_cargo_lock)
264 $alt_cargo_lock = (cfg_uc @ck);
267 if (defined($alt_cargo_lock) && ref($alt_cargo_lock) eq 'HASH') {
268 $force = cfg_bool qw(alt_cargo_lock force);
269 my @ck = qw(alt_cargo_lock file);
270 $alt_cargo_lock = cfg_uc @ck;
272 $alt_cargo_lock //= Types::Serialiser::true;
274 if (Types::Serialiser::is_bool $alt_cargo_lock) {
275 if (!$alt_cargo_lock) { $alt_cargo_lock = undef; return; }
276 $alt_cargo_lock = 'Cargo.lock.example';
279 if (ref($alt_cargo_lock) || $alt_cargo_lock =~ m{/}) {
280 badcfg @ck, "expected boolean, or leafname";
283 if (!stat_exists $alt_cargo_lock, "alt_cargo_lock") {
284 $alt_cargo_lock = undef unless $force;
288 @alt_cargo_lock_stat = stat _;
291 our $oot_dir; # oot.dir or "Build"
294 sub consider_oot () {
295 $oot_dir = cfgs qw(oot dir);
296 my $use = cfgs qw(oot use);
297 unless (defined($oot_dir) || defined($use) ||
298 defined(cfg_uc qw(oot user))) {
301 if (($use//'') eq 'disable') {
305 $oot_dir //= 'Build';
306 $oot_absdir = ($oot_dir !~ m{^/} ? "$worksphere/" : ""). $oot_dir;
314 sub read_manifest ($$$) {
315 my ($subdir, $org_subdir, $why) = @_;
316 my $manifest = "../$subdir/Cargo.toml";
317 print STDERR "$self: reading $manifest...\n" if $verbose>=4;
318 if (defined $manifests{$manifest}) {
320 "$self: warning: $subdir: specified more than once!".
321 " (ignoring $why)\n";
324 foreach my $try ("$manifest.unnailed", "$manifest") {
325 my $toml = toml_or_enoent($try, "manifest, in $why") // next;
326 my $ws = $toml->{workspace};
328 queue_workspace_members($subdir, $org_subdir, $ws, "$subdir, $why");
330 my $p = $toml->{package}{name};
331 if (!defined $p and !defined $ws) {
333 "$self: warning: $subdir, $why: missing package.name in $try, ignoring\n";
336 $manifests{$manifest} = $toml if $p;
342 sub queue_workspace_members ($$) {
343 my ($subdir, $org_subdir, $ws_toml, $what) = @_;
344 # We need to (more or less) reimplement the cargo workspace
345 # membership algorithm (see the "workspaces" section of the cargo
346 # reference). How tiresome.
348 # It's not quite the same for us because we aren't interested in
349 # whether cargo thinks things are "in the workspace". But we do
350 # need to do the automatic discover.
352 my @include = @{ $ws_toml->{members} // [ ] };
353 my $exclude = $ws_toml->{exclude} // [ ];
356 s/[^*?0-9a-zA-Z_]/\\$&/g;
361 foreach my $spec (@include) {
362 if ($spec =~ m{^/}) {
364 "$self: warning: absolute workspace member $spec in $what (not nailing, but cargo will probably use it)\n";
367 my $spec_glob = "../$subdir/$spec";
368 my $globflags = GLOB_ERR|GLOB_BRACE|GLOB_NOMAGIC;
369 foreach my $globent (bsd_glob($spec_glob, $globflags)) {
370 next if grep { $globent =~ m{^$_$} } @exclude;
371 queue_referenced_path($globent, $org_subdir,
372 "member of workspace $what");
377 sub queue_referenced_path ($$$) {
378 my ($spec_path, $org_subdir, $why) = @_;
380 qw(realpath), "--relative-to=../$org_subdir", "--", $spec_path
381 or die "$self: fork/pipe/exec for realpath(1)\n";
382 my $rel_path = do { local $/=undef; <REALPATH>; };
384 my $r = close(REALPATH);
385 die "$self: reap realpath: $!\n" if $!;
386 if (!chomp($rel_path) or $?) {
388 "$self: warning: failed to determine realpath for $spec_path in $org_subdir (exit code $?)\n";
391 if ($rel_path =~ m{^\.\./} or $rel_path eq '..') {
393 "$self: warning: $spec_path ($why) points outside $org_subdir, not following so not nailing (although cargo probably will follow it)\n";
397 my $q_subdir = "$org_subdir/$rel_path";
398 print STDERR "$self: making a note to look at $q_subdir, $why)\n"
401 push @queued_paths, [ "$q_subdir", $org_subdir, $why ];
405 foreach my $p (keys %{ $nail->{packages} }) {
406 my $v = $nail->{packages}{$p};
407 my $subdir = ref($v) ? $v->{subdir} : $v;
408 my ($gotpackage, $ws) = read_manifest($subdir, $subdir, "from [packages]");
409 $gotpackage //= '<nothing!>';
410 if ($gotpackage ne $p) {
412 "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
414 die if defined $packagemap{$p};
415 $packagemap{$p} = $subdir;
417 foreach my $subdir (@{ $nail->{subdirs} }) {
418 my ($gotpackage,$ws) = read_manifest($subdir, $subdir, "from [subdirs]");
419 if (!defined $gotpackage) {
421 "$self: warning: ignoring subdir $subdir which has no (suitable) Cargo.toml\n"
425 $packagemap{$gotpackage} //= $subdir;
427 while (my ($subdir, $org_subdir, $why) = @{ shift @queued_paths or [] }) {
428 next if $manifests{"../$subdir/Cargo.toml"};
429 my ($gotpackage, $ws) = read_manifest($subdir, $org_subdir, $why);
430 next unless $gotpackage;
431 $packagemap{$gotpackage} //= $subdir;
436 foreach my $p (sort keys %packagemap) {
437 print STDERR "$self: package $p in $packagemap{$p}\n" if $verbose>=2;
439 foreach my $mf (keys %manifests) {
440 my $toml = $manifests{$mf};
441 foreach my $deps (get_dependency_tables $toml) {
443 foreach my $p (keys %packagemap) {
444 my $info = $deps->{$p};
445 next unless defined $info;
446 $deps->{$p} = $info = { } unless ref $info;
447 delete $info->{version};
448 my $newpath = $worksphere.'/'.$packagemap{$p};
449 if ($cargo_lock_update and defined $oot_dir and
450 $newpath =~ m{^\Q$src_absdir\E(?=$|/)}) {
451 our $oot_subdir_realpath;
452 $oot_subdir_realpath //= Cwd::realpath "$oot_absdir/$subdir"
453 // die "$self: cannot resolve $oot_absdir/$subdir: $!";
454 $newpath = $oot_subdir_realpath.$';
456 $info->{path} = $newpath;
459 my $nailing = "$mf.nailing~";
460 unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
461 open N, '>', $nailing or die "$self: create new $nailing: $!\n";
462 print N to_toml($toml) or die "$self: write new $nailing: $!\n";
463 close N or die "$self: close new $nailing: $!\n";
468 if (!defined $online) {
469 $_ = cfg_uc qw(misc online);
471 } elsif (Types::Serialiser::is_bool $_) {
476 } elsif (m/^[1ty]/) { # allow booleanish strings
477 $online = 1; # for less user frustration
478 } elsif (m/^[0fn]/) {
481 badcfg qw(misc online), "expected boolean or 'auto', found '$_'";
484 $online //= 1 if subcmd_p('online');
487 $cargo_lock_update //= subcmd_p('lock-update');
491 if (!$cargo_lock_update) {
492 push @add, qw(--locked) unless subcmd_p('!locked');
493 if (defined($oot_dir) && !subcmd_p('!manifest-path')) {
494 my $cargotoml = "${src_absdir}/Cargo.toml";
495 push @args_preface, "--manifest-path=$cargotoml" if $pass_options;
496 push @add, qw(--target-dir=target) unless subcmd_p('!target-dir');
500 if (defined($target) && !subcmd_p('!target')) {
501 if ($target =~ m{^[A-Z]}) {
502 $target = (cfgs 'arch', $target) // $archmap{$target}
503 // die "$self: --target=$target alias specified; not in cfg or map\n";
505 push @add, "--target=$target";
508 push @add, "--offline" unless $online || subcmd_p('!offline');
510 push @args_preface, @add if $pass_options;
511 die if grep { m/ / } @add;
512 $ENV{NAILINGCARGO_CARGO_OPTIONS} = "@add";
514 unshift @ARGV, @args_preface;
517 our $build_absdir; # .../Build/<subdir>
519 sub oot_massage_cmdline () {
520 return unless defined $oot_dir;
522 my $use = cfgs qw(oot use);
523 $use // die "$self: out-of-tree build, but \`oot.use' not configured\n";
524 $build_absdir = "$oot_absdir/$subdir";
526 my ($pre,$post) = ('','');
528 if (!$cargo_lock_update) {
529 push @xargs, $build_absdir;
530 ($pre, $post) = ('cd "$1"; shift; ', '');
532 push @xargs, $oot_absdir, $subdir, $src_absdir;
535 mkdir -p -- "$1"; cd "$1"; shift;
536 clean () { find -lname "$1/*" -print0 | xargs -0r rm --; }; clean;
537 find "$1" -maxdepth 1 \! -name Cargo.lock -print0 | xargs -0r -I_ ln -sf -- _ .;
539 $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
541 cp -- "$1"/Cargo.lock .;
546 # $post = <<'ENDCLEAN';
550 my $addpath = (cfg_uc qw(oot path_add)) //
551 $use eq 'really' ? Types::Serialiser::true : Types::Serialiser::false;
553 !Types::Serialiser::is_bool $addpath ? $addpath :
554 $addpath ? '$HOME/.cargo/bin' :
556 if (defined $addpath) {
558 PATH=$addpath:\${PATH-/usr/local/bin:/bin:/usr/bin};
562 $pre =~ s/^\s+//mg; $pre =~ s/\s+/ /g;
563 $post =~ s/^\s+//mg; $post =~ s/\s+/ /g;
565 my $getuser = sub { cfgsn qw(oot user) };
567 my $xe = $verbose >= 2 ? 'xe' : 'e';
570 @command = (@_, 'sh',"-${xe}c",$pre.'exec "$@"','--',@xargs);
572 @command = (@_, 'sh',"-${xe}c",$pre.'"$@"; '.$post,'--',@xargs);
574 push @command, @ARGV;
576 my $command_sh = sub {
577 my $quoted = join ' ', map {
582 @command = @_, "set -${xe}; $pre $quoted; $post";
584 print STDERR "$self: out-of-tree, building in: \`$build_absdir'\n"
586 if ($use eq 'really') {
587 my $user = $getuser->();
588 my @pw = getpwnam $user or die "$self: oot.user \`$user' lookup failed\n";
589 my $homedir = $pw[7];
590 $sh_ec->('really','-u',$user,'env',"HOME=$homedir");
591 print STDERR "$self: using really to run as user \`$user'\n" if $verbose;
592 } elsif ($use eq 'ssh') {
593 my $user = $getuser->();
594 $user .= '@localhost' unless $user =~ m/\@/;
595 $command_sh->('ssh',$user);
596 print STDERR "$self: using ssh to run as \`$user'\n" if $verbose;
597 } elsif ($use eq 'command_args') {
598 my @c = cfgn_list qw(oot command);
600 print STDERR "$self: out-of-tree, adverbial command: @c\n" if $verbose;
601 } elsif ($use eq 'command_sh') {
602 my @c = cfgn_list qw(oot command);
604 print STDERR "$self: out-of-tree, ssh'ish command: @c\n" if $verbose;
605 } elsif ($use eq 'null') {
608 die "$self: oot.use mode $use not recognised\n";
615 $ENV{CARGO_MANIFEST_DIR} = $src_absdir;
616 $ENV{NAILINGCARGO_MANIFEST_DIR} = $src_absdir;
617 $ENV{NAILINGCARGO_WORKSPHERE} = $worksphere;
618 $ENV{NAILINGCARGO_BUILDSPHERE} = $oot_absdir;
619 delete $ENV{NAILINGCARGO_BUILDSPHERE} unless $oot_absdir;
620 $ENV{NAILINGCARGO_BUILD_DIR} = $build_absdir // $src_absdir;
626 if ($want_uninstall) {
628 foreach my $mf (keys %manifests) {
629 eval { uninstall1($mf,1); 1; } or warn "$@";
631 eval { unaltcargolock(1); 1; } or warn "$@";
635 sub consider_directories () {
636 return unless defined $oot_dir;
637 my $bsubdir = "../$oot_dir/$subdir";
638 return if stat $bsubdir;
639 die "$0: build directory $bsubdir inaccessible\n"
641 return if $cargo_lock_update; # will make it
642 die "$0: build directory $bsubdir does not exist, and not in Cargo.lock update mode!\n";
645 our $cleanup_cargo_lock;
647 foreach my $mf (keys %manifests) {
648 link "$mf", "$mf.unnailed" or $!==EEXIST
649 or die "$self: make backup link $mf.unnailed: $!\n";
652 if (defined($alt_cargo_lock)) {
653 if (@alt_cargo_lock_stat) {
654 print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
656 if (link $alt_cargo_lock, 'Cargo.lock') {
657 print STDERR " linked\n" if $verbose>=3;
658 } elsif ($! != EEXIST) {
659 print STDERR "\n" if $verbose>=3;
660 die "$self: make \`Cargo.lock' available as \`$alt_cargo_lock': $!\n";
662 print STDERR "checking quality." if $verbose>=3;
663 my @lock_stat = stat 'Cargo.lock'
664 or die "$self: stat Cargo.lock (for alt check: $!\n";
665 same_file(\@alt_cargo_lock_stat, \@lock_stat)
667 "$self: \`Cargo.lock' and alt file \`$alt_cargo_lock' both exist and are not the same file!\n";
669 $cleanup_cargo_lock = 1;
671 $cleanup_cargo_lock = 1;
672 # If Cargo.lock exists and alt doesn't, that means either
673 # that a previous run was interrupted, or that the user has
681 my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
686 my @our_unfound_stab = stat_exists('Cargo.toml', 'local Cargo.toml')
688 foreach my $mf (keys %manifests) {
689 if (@our_unfound_stab) {
690 if (stat_exists $mf, "manifest in to-be-nailed directory") {
691 my @mf_stab = stat _ ;
692 if ("@mf_stab[0..1]" eq "@our_unfound_stab[0..1]") {
693 @our_unfound_stab = ();
698 my $nailing = "$mf.nailing~";
699 my $nailed = nailed($mf);
702 if (open NN, '<', $nailed) {
703 $diff = compare($nailing, \*NN);
704 die "$self: compare $nailing and $nailed: $!" if $diff<0;
706 $!==ENOENT or die "$self: check previous $nailed: $!\n";
716 rename $use, $mf or die "$self: install nailed $use: $!\n";
717 unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
718 print STDERR "$self: nailed $mf\n" if $verbose>=3;
721 if (@our_unfound_stab) {
723 "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
728 my $r = system @ARGV;
732 print STDERR "$self: could not execute $ARGV[0]: $!\n";
734 } elsif ($r & 0xff00) {
735 print STDERR "$self: $ARGV[0] failed (exit status $r)\n";
738 print STDERR "$self: $ARGV[0] died due to signal! (wait status $r)\n";
743 sub cargo_lock_update_after () {
744 if ($cargo_lock_update) {
745 # avoids importing File::Copy and the error handling is about as good
747 my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
748 die "$self: run cp: $! $?" if $r<0 || $r & 0xff;
749 die "$self: failed to update local Cargo.lock (wait status $r)\n" if $r;
753 sub uninstall1 ($$) {
754 my ($mf, $enoentok) = @_;
755 my $unnailed = "$mf.unnailed";
756 rename $unnailed, $mf or ($enoentok && $!==ENOENT)
757 or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
760 sub unaltcargolock ($) {
762 return unless $cleanup_cargo_lock;
763 die 'internal error!' unless defined $alt_cargo_lock;
765 # we ignore $enoentok because we don't know if one was supposed to
768 rename('Cargo.lock', $alt_cargo_lock) or $!==ENOENT or die
769 "$self: cleanup: rename possibly-updated \`Cargo.lock' to \`$alt_cargo_lock': $!\n";
771 unlink 'Cargo.lock' or $!==ENOENT or die
772 "$self: cleanup: remove \`Cargo.lock' in favour of \`$alt_cargo_lock': $!\n";
773 # ^ this also helps clean up the stupid rename() corner case
777 foreach my $mf (keys %manifests) {
778 my $nailed = nailed($mf);
779 link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
788 # Loop exit condition:
791 # $is_cargo==1 <cargo-command> <cargo-opts> [--] <subcmd>...
792 # $is_cargo==0 <build-command>...
795 @ARGV or die "$self: need cargo subcommand\n";
800 my $not_a_nailing_opt = sub { # usage 1
801 unshift @ARGV, $orgopt;
802 unshift @ARGV, 'cargo';
804 no warnings qw(exiting);
807 $not_a_nailing_opt->() unless m{^-};
808 $not_a_nailing_opt->() if $_ eq '--';
810 if ($_ eq '---') { # usage 2 or 3
811 die "$self: --- must be followed by build command\n" unless @ARGV;
812 if ($ARGV[0] eq '--') { # usage 3
815 } elsif (grep { $_ eq '--' } @ARGV) { # usage 2
817 } elsif ($ARGV[0] =~ m{[^/]*cargo[^/]*$}) { # usage 2
828 } elsif (s{^-q}{-}) {
830 } elsif (s{^-n}{-}) {
832 } elsif (s{^-s(.+)}{-}s) {
834 } elsif (s{^-([uU])}{-}) {
835 $cargo_lock_update = $1=~m/[a-z]/;
836 } elsif (s{^-([cC])}{-}) {
837 $pass_options = $1=~m/[a-z]/;
838 } elsif (s{^-D}{-}) {
840 } elsif (s{^-T(.+)}{-}s) {
842 } elsif (s{^-([oO])}{-}) {
843 $online = $1=~m/[a-z]/;
845 die "$self: unknown short option(s) $_\n" unless $_ eq $orgopt;
846 $not_a_nailing_opt->();
849 } elsif (s{^--target=}{}) {
851 } elsif (m{^--(on|off)line$}) {
852 $online = $1 eq 'on';
853 } elsif (s{^--subcommand-props=}{}) {
854 my @props = split /\,/, $_;
856 if (!%subcmd_prop_ok) {
857 foreach my $v (\@subcmd_xprops, values %subcmd_props) {
858 $subcmd_prop_ok{$_}=1 foreach @$v;
862 or die "$self: unknown subcommand property \`$_'\n"
864 $cargo_subcmd = \@props;
865 } elsif (m{^--(no-)?cargo-lock-update}) {
866 $cargo_lock_update= !!$1;
868 $not_a_nailing_opt->();
876 @args_preface = shift @ARGV;
877 while (defined($_ = shift @ARGV)) {
878 if (!m{^-}) { unshift @ARGV, $_; last; }
879 if ($_ eq '--') { last; }
880 push @args_preface, $_;
882 @ARGV || die "$self: need cargo subcommand\n";
883 $cargo_subcmd //= $ARGV[0];
886 $cargo_subcmd //= '';
889 push @args_preface, shift @ARGV;
891 if (!ref($cargo_subcmd)) {
892 print STDERR " cargo_subcmd lookup $cargo_subcmd\n" if $dump;
893 $cargo_subcmd = $subcmd_props{$cargo_subcmd} // [ ];
896 print STDERR " cargo_subcmd props @$cargo_subcmd\n" if $dump;
898 $cargo_subcmd{$_} = 1 foreach @$cargo_subcmd;
899 $cargo_subcmd = \%cargo_subcmd;
906 consider_alt_cargo_lock();
911 consider_directories();
912 our @display_cmd = @ARGV;
913 oot_massage_cmdline();
919 print STDERR Dumper(\%manifests) if $dump>=2;
920 print STDERR Dumper(\%packagemap, \@ARGV,
921 { src_absdir => $src_absdir,
922 worksphere => $worksphere,
925 oot_absdir => $oot_absdir,
926 build_absdir => $build_absdir });
936 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
937 (scalar keys %manifests), (scalar keys %packagemap),
938 (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
941 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
942 my $estatus = invoke();
944 cargo_lock_update_after();
949 print STDERR "$self: unnailed. status $estatus.\n" if $verbose;