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;
254 foreach my $target_node (values %{ $toml->{target} // { } }) {
255 $process->($target_node);
260 our @alt_cargo_lock_stat;
262 sub consider_alt_cargo_lock () {
263 my @ck = qw(alt_cargo_lock);
264 # User should *either* have Cargo.lock in .gitignore,
265 # or expect to commit Cargo.lock.example ($alt_cargo_lock)
267 $alt_cargo_lock = (cfg_uc @ck);
270 if (defined($alt_cargo_lock) && ref($alt_cargo_lock) eq 'HASH') {
271 $force = cfg_bool qw(alt_cargo_lock force);
272 my @ck = qw(alt_cargo_lock file);
273 $alt_cargo_lock = cfg_uc @ck;
275 $alt_cargo_lock //= Types::Serialiser::true;
277 if (Types::Serialiser::is_bool $alt_cargo_lock) {
278 if (!$alt_cargo_lock) { $alt_cargo_lock = undef; return; }
279 $alt_cargo_lock = 'Cargo.lock.example';
282 if (ref($alt_cargo_lock) || $alt_cargo_lock =~ m{/}) {
283 badcfg @ck, "expected boolean, or leafname";
286 if (!stat_exists $alt_cargo_lock, "alt_cargo_lock") {
287 $alt_cargo_lock = undef unless $force;
291 @alt_cargo_lock_stat = stat _;
294 our $oot_dir; # oot.dir or "Build"
297 sub consider_oot () {
298 $oot_dir = cfgs qw(oot dir);
299 my $use = cfgs qw(oot use);
300 unless (defined($oot_dir) || defined($use) ||
301 defined(cfg_uc qw(oot user))) {
304 if (($use//'') eq 'disable') {
308 $oot_dir //= 'Build';
309 $oot_absdir = ($oot_dir !~ m{^/} ? "$worksphere/" : ""). $oot_dir;
317 sub read_manifest ($$$) {
318 my ($subdir, $org_subdir, $why) = @_;
319 my $manifest = "../$subdir/Cargo.toml";
320 print STDERR "$self: reading $manifest...\n" if $verbose>=4;
321 if (defined $manifests{$manifest}) {
323 "$self: warning: $subdir: specified more than once!".
324 " (ignoring $why)\n";
327 foreach my $try ("$manifest.unnailed", "$manifest") {
328 my $toml = toml_or_enoent($try, "manifest, in $why") // next;
329 my $ws = $toml->{workspace};
331 queue_workspace_members($subdir, $org_subdir, $ws, "$subdir, $why");
333 my $p = $toml->{package}{name};
334 if (!defined $p and !defined $ws) {
336 "$self: warning: $subdir, $why: missing package.name in $try, ignoring\n";
339 $manifests{$manifest} = [ $toml, $org_subdir ] if $p;
345 sub queue_workspace_members ($$) {
346 my ($subdir, $org_subdir, $ws_toml, $what) = @_;
347 # We need to (more or less) reimplement the cargo workspace
348 # membership algorithm (see the "workspaces" section of the cargo
349 # reference). How tiresome.
351 # It's not quite the same for us because we aren't interested in
352 # whether cargo thinks things are "in the workspace". But we do
353 # need to do the automatic discover.
355 my @include = @{ $ws_toml->{members} // [ ] };
356 my $exclude = $ws_toml->{exclude} // [ ];
359 s/[^*?0-9a-zA-Z_]/\\$&/g;
364 foreach my $spec (@include) {
365 if ($spec =~ m{^/}) {
367 "$self: warning: absolute workspace member $spec in $what (not nailing, but cargo will probably use it)\n";
370 my $spec_glob = "../$subdir/$spec";
371 my $globflags = GLOB_ERR|GLOB_BRACE|GLOB_NOMAGIC;
372 foreach my $globent (bsd_glob($spec_glob, $globflags)) {
373 next if grep { $globent =~ m{^$_$} } @exclude;
374 queue_referenced_path($globent, $org_subdir,
375 "member of workspace $what");
380 sub queue_referenced_path ($$$) {
381 my ($spec_path, $org_subdir, $why) = @_;
383 qw(realpath), "--relative-to=../$org_subdir", "--", $spec_path
384 or die "$self: fork/pipe/exec for realpath(1)\n";
385 my $rel_path = do { local $/=undef; <REALPATH>; };
387 my $r = close(REALPATH);
388 die "$self: reap realpath: $!\n" if $!;
389 if (!chomp($rel_path) or $?) {
391 "$self: warning: failed to determine realpath for $spec_path in $org_subdir (exit code $?)\n";
394 if ($rel_path =~ m{^\.\./} or $rel_path eq '..') {
396 "$self: warning: $spec_path ($why) points outside $org_subdir, not following so not nailing (although cargo probably will follow it)\n";
400 my $q_subdir = "$org_subdir/$rel_path";
401 print STDERR "$self: making a note to look at $q_subdir, $why)\n"
404 push @queued_paths, [ "$q_subdir", $org_subdir, $why ];
408 foreach my $p (keys %{ $nail->{packages} }) {
409 my $v = $nail->{packages}{$p};
410 my $subdir = ref($v) ? $v->{subdir} : $v;
411 my ($gotpackage, $ws) = read_manifest($subdir, $subdir, "from [packages]");
412 $gotpackage //= '<nothing!>';
413 if ($gotpackage ne $p) {
415 "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
417 die if defined $packagemap{$p};
418 $packagemap{$p} = [ $subdir, $subdir ];
420 foreach my $subdir (@{ $nail->{subdirs} }) {
421 my ($gotpackage,$ws) = read_manifest($subdir, $subdir, "from [subdirs]");
422 if (!defined $gotpackage) {
424 "$self: warning: ignoring subdir $subdir which has no (suitable) Cargo.toml\n"
428 $packagemap{$gotpackage} //= [ $subdir, $subdir ];
430 while (my ($subdir, $org_subdir, $why) = @{ shift @queued_paths or [] }) {
431 next if $manifests{"../$subdir/Cargo.toml"};
432 my ($gotpackage, $ws) = read_manifest($subdir, $org_subdir, $why);
433 next unless $gotpackage;
434 $packagemap{$gotpackage} //= [ $subdir, $org_subdir ];
439 foreach my $p (sort keys %packagemap) {
440 print STDERR "$self: package $p in $packagemap{$p}[0]\n" if $verbose>=2;
442 foreach my $mf (keys %manifests) {
443 my ($toml, $mf_org_subdir) = @{ $manifests{$mf} };
444 foreach my $deps (get_dependency_tables $toml) {
446 foreach my $p (keys %packagemap) {
447 my $info = $deps->{$p};
448 next unless defined $info;
449 $deps->{$p} = $info = { } unless ref $info;
450 my $oldpath = $info->{path};
451 delete $info->{version};
452 my $newpath = $worksphere.'/'.$packagemap{$p}[0];
453 if ($cargo_lock_update and defined $oot_dir and
454 $newpath =~ m{^\Q$src_absdir\E(?=$|/)}) {
455 our $oot_subdir_realpath;
456 $oot_subdir_realpath //= Cwd::realpath "$oot_absdir/$subdir"
457 // die "$self: cannot resolve $oot_absdir/$subdir: $!";
458 $newpath = $oot_subdir_realpath.$';
460 print STDERR "in $mf set $p path=$newpath (was ".
461 ($oldpath // '<unset>').")\n"
463 $info->{path} = $newpath;
465 delete $info->{branch};
468 my $nailing = "$mf.nailing~";
469 unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
470 open N, '>', $nailing or die "$self: create new $nailing: $!\n";
471 print N to_toml($toml) or die "$self: write new $nailing: $!\n";
472 close N or die "$self: close new $nailing: $!\n";
477 if (!defined $online) {
478 $_ = cfg_uc qw(misc online);
480 } elsif (Types::Serialiser::is_bool $_) {
485 } elsif (m/^[1ty]/) { # allow booleanish strings
486 $online = 1; # for less user frustration
487 } elsif (m/^[0fn]/) {
490 badcfg qw(misc online), "expected boolean or 'auto', found '$_'";
493 $online //= 1 if subcmd_p('online');
496 $cargo_lock_update //= subcmd_p('lock-update');
500 if (!$cargo_lock_update) {
501 push @add, qw(--locked) unless subcmd_p('!locked');
502 if (defined($oot_dir) && !subcmd_p('!manifest-path')) {
503 my $cargotoml = "${src_absdir}/Cargo.toml";
504 push @args_preface, "--manifest-path=$cargotoml" if $pass_options;
505 push @add, qw(--target-dir=target) unless subcmd_p('!target-dir');
509 if (defined($target) && !subcmd_p('!target')) {
510 if ($target =~ m{^[A-Z]}) {
511 $target = (cfgs 'arch', $target) // $archmap{$target}
512 // die "$self: --target=$target alias specified; not in cfg or map\n";
514 push @add, "--target=$target";
517 push @add, "--offline" unless $online || subcmd_p('!offline');
519 push @args_preface, @add if $pass_options;
520 die if grep { m/ / } @add;
521 $ENV{NAILINGCARGO_CARGO_OPTIONS} = "@add";
523 unshift @ARGV, @args_preface;
526 our $build_absdir; # .../Build/<subdir>
528 sub oot_massage_cmdline () {
529 return unless defined $oot_dir;
531 my $use = cfgs qw(oot use);
532 $use // die "$self: out-of-tree build, but \`oot.use' not configured\n";
533 $build_absdir = "$oot_absdir/$subdir";
535 my ($pre,$post) = ('','');
537 if (!$cargo_lock_update) {
538 push @xargs, $build_absdir;
539 ($pre, $post) = ('cd "$1"; shift; ', '');
541 push @xargs, $oot_absdir, $subdir, $src_absdir;
544 mkdir -p -- "$1"; cd "$1"; shift;
545 clean () { find -lname "$1/*" -print0 | xargs -0r rm --; }; clean;
546 find "$1" -maxdepth 1 \! -name Cargo.lock -print0 | xargs -0r -I_ ln -sf -- _ .;
548 $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
550 cp -- "$1"/Cargo.lock .;
555 # $post = <<'ENDCLEAN';
559 my $addpath = (cfg_uc qw(oot path_add)) //
560 $use eq 'really' ? Types::Serialiser::true : Types::Serialiser::false;
562 !Types::Serialiser::is_bool $addpath ? $addpath :
563 $addpath ? '$HOME/.cargo/bin' :
565 if (defined $addpath) {
567 PATH=$addpath:\${PATH-/usr/local/bin:/bin:/usr/bin};
571 $pre =~ s/^\s+//mg; $pre =~ s/\s+/ /g;
572 $post =~ s/^\s+//mg; $post =~ s/\s+/ /g;
574 my $getuser = sub { cfgsn qw(oot user) };
576 my $xe = $verbose >= 2 ? 'xe' : 'e';
579 @command = (@_, 'sh',"-${xe}c",$pre.'exec "$@"','--',@xargs);
581 @command = (@_, 'sh',"-${xe}c",$pre.'"$@"; '.$post,'--',@xargs);
583 push @command, @ARGV;
585 my $command_sh = sub {
586 my $quoted = join ' ', map {
591 @command = @_, "set -${xe}; $pre $quoted; $post";
593 print STDERR "$self: out-of-tree, building in: \`$build_absdir'\n"
595 if ($use eq 'really') {
596 my $user = $getuser->();
597 my @pw = getpwnam $user or die "$self: oot.user \`$user' lookup failed\n";
598 my $homedir = $pw[7];
599 $sh_ec->('really','-u',$user,'env',"HOME=$homedir");
600 print STDERR "$self: using really to run as user \`$user'\n" if $verbose;
601 } elsif ($use eq 'ssh') {
602 my $user = $getuser->();
603 $user .= '@localhost' unless $user =~ m/\@/;
604 $command_sh->('ssh',$user);
605 print STDERR "$self: using ssh to run as \`$user'\n" if $verbose;
606 } elsif ($use eq 'command_args') {
607 my @c = cfgn_list qw(oot command);
609 print STDERR "$self: out-of-tree, adverbial command: @c\n" if $verbose;
610 } elsif ($use eq 'command_sh') {
611 my @c = cfgn_list qw(oot command);
613 print STDERR "$self: out-of-tree, ssh'ish command: @c\n" if $verbose;
614 } elsif ($use eq 'null') {
617 die "$self: oot.use mode $use not recognised\n";
624 $ENV{CARGO_MANIFEST_DIR} = $src_absdir;
625 $ENV{NAILINGCARGO_MANIFEST_DIR} = $src_absdir;
626 $ENV{NAILINGCARGO_WORKSPHERE} = $worksphere;
627 $ENV{NAILINGCARGO_BUILDSPHERE} = $oot_absdir;
628 delete $ENV{NAILINGCARGO_BUILDSPHERE} unless $oot_absdir;
629 $ENV{NAILINGCARGO_BUILD_DIR} = $build_absdir // $src_absdir;
635 if ($want_uninstall) {
637 foreach my $mf (keys %manifests) {
638 eval { uninstall1($mf,1); 1; } or warn "$@";
640 eval { unaltcargolock(1); 1; } or warn "$@";
644 sub consider_directories () {
645 return unless defined $oot_dir;
646 my $bsubdir = "../$oot_dir/$subdir";
647 return if stat $bsubdir;
648 die "$0: build directory $bsubdir inaccessible\n"
650 return if $cargo_lock_update; # will make it
651 die "$0: build directory $bsubdir does not exist, and not in Cargo.lock update mode!\n";
654 our $cleanup_cargo_lock;
656 foreach my $mf (keys %manifests) {
657 link "$mf", "$mf.unnailed" or $!==EEXIST
658 or die "$self: make backup link $mf.unnailed: $!\n";
661 if (defined($alt_cargo_lock)) {
662 if (@alt_cargo_lock_stat) {
663 print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
665 if (link $alt_cargo_lock, 'Cargo.lock') {
666 print STDERR " linked\n" if $verbose>=3;
667 } elsif ($! != EEXIST) {
668 print STDERR "\n" if $verbose>=3;
669 die "$self: make \`Cargo.lock' available as \`$alt_cargo_lock': $!\n";
671 print STDERR "checking quality." if $verbose>=3;
672 my @lock_stat = stat 'Cargo.lock'
673 or die "$self: stat Cargo.lock (for alt check: $!\n";
674 same_file(\@alt_cargo_lock_stat, \@lock_stat)
676 "$self: \`Cargo.lock' and alt file \`$alt_cargo_lock' both exist and are not the same file!\n";
678 $cleanup_cargo_lock = 1;
680 $cleanup_cargo_lock = 1;
681 # If Cargo.lock exists and alt doesn't, that means either
682 # that a previous run was interrupted, or that the user has
690 my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
695 my @our_unfound_stab = stat_exists('Cargo.toml', 'local Cargo.toml')
697 foreach my $mf (keys %manifests) {
698 if (@our_unfound_stab) {
699 if (stat_exists $mf, "manifest in to-be-nailed directory") {
700 my @mf_stab = stat _ ;
701 if ("@mf_stab[0..1]" eq "@our_unfound_stab[0..1]") {
702 @our_unfound_stab = ();
707 my $nailing = "$mf.nailing~";
708 my $nailed = nailed($mf);
711 if (open NN, '<', $nailed) {
712 $diff = compare($nailing, \*NN);
713 die "$self: compare $nailing and $nailed: $!" if $diff<0;
715 $!==ENOENT or die "$self: check previous $nailed: $!\n";
725 rename $use, $mf or die "$self: install nailed $use: $!\n";
726 unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
727 print STDERR "$self: nailed $mf\n" if $verbose>=3;
730 if (@our_unfound_stab) {
732 "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
737 my $r = system @ARGV;
741 print STDERR "$self: could not execute $ARGV[0]: $!\n";
743 } elsif ($r & 0xff00) {
744 print STDERR "$self: $ARGV[0] failed (exit status $r)\n";
747 print STDERR "$self: $ARGV[0] died due to signal! (wait status $r)\n";
752 sub cargo_lock_update_after () {
753 if ($cargo_lock_update) {
754 # avoids importing File::Copy and the error handling is about as good
756 my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
757 die "$self: run cp: $! $?" if $r<0 || $r & 0xff;
758 die "$self: failed to update local Cargo.lock (wait status $r)\n" if $r;
762 sub uninstall1 ($$) {
763 my ($mf, $enoentok) = @_;
764 my $unnailed = "$mf.unnailed";
765 rename $unnailed, $mf or ($enoentok && $!==ENOENT)
766 or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
769 sub unaltcargolock ($) {
771 return unless $cleanup_cargo_lock;
772 die 'internal error!' unless defined $alt_cargo_lock;
774 # we ignore $enoentok because we don't know if one was supposed to
777 rename('Cargo.lock', $alt_cargo_lock) or $!==ENOENT or die
778 "$self: cleanup: rename possibly-updated \`Cargo.lock' to \`$alt_cargo_lock': $!\n";
780 unlink 'Cargo.lock' or $!==ENOENT or die
781 "$self: cleanup: remove \`Cargo.lock' in favour of \`$alt_cargo_lock': $!\n";
782 # ^ this also helps clean up the stupid rename() corner case
786 foreach my $mf (keys %manifests) {
787 my $nailed = nailed($mf);
788 link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
797 # Loop exit condition:
800 # $is_cargo==1 <cargo-command> <cargo-opts> [--] <subcmd>...
801 # $is_cargo==0 <build-command>...
804 @ARGV or die "$self: need cargo subcommand\n";
809 my $not_a_nailing_opt = sub { # usage 1
810 unshift @ARGV, $orgopt;
811 unshift @ARGV, 'cargo';
813 no warnings qw(exiting);
816 $not_a_nailing_opt->() unless m{^-};
817 $not_a_nailing_opt->() if $_ eq '--';
819 if ($_ eq '---') { # usage 2 or 3
820 die "$self: --- must be followed by build command\n" unless @ARGV;
821 if ($ARGV[0] eq '--') { # usage 3
824 } elsif (grep { $_ eq '--' } @ARGV) { # usage 2
826 } elsif ($ARGV[0] =~ m{[^/]*cargo[^/]*$}) { # usage 2
837 } elsif (s{^-q}{-}) {
839 } elsif (s{^-n}{-}) {
841 } elsif (s{^-s(.+)}{-}s) {
843 } elsif (s{^-([uU])}{-}) {
844 $cargo_lock_update = $1=~m/[a-z]/;
845 } elsif (s{^-([cC])}{-}) {
846 $pass_options = $1=~m/[a-z]/;
847 } elsif (s{^-D}{-}) {
849 } elsif (s{^-T(.+)}{-}s) {
851 } elsif (s{^-([oO])}{-}) {
852 $online = $1=~m/[a-z]/;
854 die "$self: unknown short option(s) $_\n" unless $_ eq $orgopt;
855 $not_a_nailing_opt->();
858 } elsif (s{^--target=}{}) {
860 } elsif (m{^--(on|off)line$}) {
861 $online = $1 eq 'on';
862 } elsif (s{^--subcommand-props=}{}) {
863 my @props = split /\,/, $_;
865 if (!%subcmd_prop_ok) {
866 foreach my $v (\@subcmd_xprops, values %subcmd_props) {
867 $subcmd_prop_ok{$_}=1 foreach @$v;
871 or die "$self: unknown subcommand property \`$_'\n"
873 $cargo_subcmd = \@props;
874 } elsif (m{^--(no-)?cargo-lock-update}) {
875 $cargo_lock_update= !!$1;
877 $not_a_nailing_opt->();
885 @args_preface = shift @ARGV;
886 while (defined($_ = shift @ARGV)) {
887 if (!m{^-}) { unshift @ARGV, $_; last; }
888 if ($_ eq '--') { last; }
889 push @args_preface, $_;
891 @ARGV || die "$self: need cargo subcommand\n";
892 $cargo_subcmd //= $ARGV[0];
895 $cargo_subcmd //= '';
898 push @args_preface, shift @ARGV;
900 if (!ref($cargo_subcmd)) {
901 print STDERR " cargo_subcmd lookup $cargo_subcmd\n" if $dump;
902 $cargo_subcmd = $subcmd_props{$cargo_subcmd} // [ ];
905 print STDERR " cargo_subcmd props @$cargo_subcmd\n" if $dump;
907 $cargo_subcmd{$_} = 1 foreach @$cargo_subcmd;
908 $cargo_subcmd = \%cargo_subcmd;
915 consider_alt_cargo_lock();
920 consider_directories();
921 our @display_cmd = @ARGV;
922 oot_massage_cmdline();
928 print STDERR Dumper(\%manifests) if $dump>=2;
929 print STDERR Dumper(\%packagemap, \@ARGV,
930 { src_absdir => $src_absdir,
931 worksphere => $worksphere,
934 oot_absdir => $oot_absdir,
935 build_absdir => $build_absdir });
945 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
946 (scalar keys %manifests), (scalar keys %packagemap),
947 (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
950 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
951 my $estatus = invoke();
953 cargo_lock_update_after();
958 print STDERR "$self: unnailed. status $estatus.\n" if $verbose;