2 # nailing-cargo: wrapper to use unpublished local crates
3 # SPDX-License-Identifier: AGPL-3.0-or-later
8 nailing-cargo <nailing-opts> <cargo-opts> [--] <subcmd>...
9 nailing-cargo <nailing-opts> --- <cargo> <cargo-opts> [--] <subcmd>...
10 nailing-cargo <nailing-opts> --- [--] <build-command>...
14 -v Increase verbosity. (Default is 1)
16 -D Increase amount of debugging dump.
17 -n "No action": stop after writing Cargo.toml.nailing~
18 everywhere, and do not run any build command
20 -c Do add cargo command line options } default is add if
21 -C Do not add cargo command line options } command is cargo
23 -o --online -O --offline
24 -u --cargo-lock-update -U --no-cargo-lock-update
26 -T<arch> --target=<arch> Specify target architecture
27 -h --help Print this message
29 -s<subcommand> Treat command as `cargo <subcommand>`
30 --subcommand-props=<prop>,... Override command props (see docs)
38 use Types::Serialiser;
39 use File::Glob qw(bsd_glob GLOB_ERR GLOB_BRACE GLOB_NOMAGIC);
43 RPI => 'arm-unknown-linux-gnueabihf',
47 $self = $0; $self =~ s{^.*/(?=.)}{};
49 while ($deref =~ m{^/}) {
50 my $link = readlink $deref;
53 or die "$self: checking our script location $deref: $!\n";
54 $deref =~ s{/[^/]+$}{}
55 or die "$self: unexpected script path: $deref\n";
56 unshift @INC, $deref."/TOML-Tiny/lib";
59 last if $link !~ m{^/};
64 use Fcntl qw(LOCK_EX);
66 use TOML::Tiny::Faithful;
68 our $src_absdir = getcwd() // die "$self: getcwd failed: $!\n";
70 our $worksphere = $src_absdir;
71 $worksphere =~ s{/([^/]+)$}{}
72 or die "$self: cwd \`$worksphere' unsupported!\n";
73 our $subdir = $1; # leafname
75 our $lockfile = "../.nailing-cargo.lock";
79 our $command_is_cargo;
81 our $cargo_lock_update;
87 # build (default) =>[qw( )],
88 'generate-lockfile'=>[qw( lock-update !target !target-dir )],
89 update =>[qw( lock-update !target online )],
90 fetch =>[qw( online !target-dir )],
93 our @subcmd_xprops = qw(!manifest-path !offline !locked);
101 print $usage or die $!;
105 sub read_or_enoent ($) {
107 if (!open R, '<', $fn) {
108 return undef if $!==ENOENT;
109 die "$self: open $fn: $!\n";
112 my ($r) = <R> // die "$self: read $fn: $!\n";
116 sub stat_exists ($$) {
117 my ($fn, $what) = @_;
118 if (stat $fn) { return 1; }
119 $!==ENOENT or die "$self: stat $what: $fn: $!\n";
124 print STDERR " subcmd_p ".(join ' ', keys %$cargo_subcmd)." | @_\n"
126 $cargo_subcmd->{$_[0]}
129 sub toml_or_enoent ($$) {
131 my $toml = read_or_enoent($f) // return;
132 print STDERR "Read TOML from $f\n" if $dump;
133 my ($v,$e) = from_toml($toml);
136 die "$self: parse TOML: $what: $f: $e\n";
138 die "$e ?" if length $e;
142 sub load1config ($) {
144 my $toml = toml_or_enoent($f, "config file");
145 push @configs, $toml if defined $toml;
149 my $dotfile = ".nailing-cargo.toml";
150 load1config("../Nailing-Cargo.toml");
151 load1config($dotfile);
152 load1config("$ENV{HOME}/$dotfile") if defined $ENV{HOME};
153 load1config("/etc/nailing-cargo/cfg.toml");
156 sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
160 "@$x[0..5]" eq "@$y[0..5]";
165 open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
166 flock LOCK, LOCK_EX or die "$self: lock $lockfile: $!\n";
167 my @fstat = stat LOCK or die "$self: fstat: $!\n";
168 my @stat = stat $lockfile;
170 next if $! == ENOENT;
171 die "$self: stat $lockfile: $!\n";
173 last if same_file(\@fstat,\@stat);
177 unlink $lockfile or die "$self: removing lockfile: $!\n";
185 die "$self: config key \`@_': $m\n";
189 foreach my $cfg (@configs) {
192 last unless defined $v;
193 ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
196 return $v if defined $v;
204 my $got = ref($v) || 'scalar';
205 return $v if !defined($v) || $got eq $exp;
206 badcfg @_, "found \L$got\E, expected \L$exp\E";
207 # ^ toml doesn't make refs to scalars, so this is unambiguous
212 (cfge $exp, @_) // badcfg @_, "missing";
215 sub cfgs { cfge 'scalar', @_ }
216 sub cfgsn { cfgn 'scalar', @_ }
220 return $v if !defined($v) || Types::Serialiser::is_bool $v;
221 badcfg @_, "expected boolean";
225 my $l = cfge 'ARRAY', @_;
226 foreach my $x (@$l) {
227 !ref $x or badcfg @_, "list contains non-scalar element";
233 my $nailfile = "../Cargo.nail";
234 open N, '<', $nailfile or die "$self: open $nailfile: $!\n";
236 my $toml = <N> // die "$self: read $nailfile: $!";
238 if ($toml !~ m{^\s*\[/}m &&
239 $toml !~ m{^[^\n\#]*\=}m &&
240 # old non-toml syntax
241 $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
242 $toml =~ s{^}{[packages\]\n};
244 $toml =~ s{^[ \t]*\-[ \t]*\=[ \t]*(\"[-_0-9a-z]+\"\n?)$}{
247 $toml = "subdirs = [\n".(join '', map { "$_\n" } @sd)."]\n".$toml;
251 ($nail,$e) = from_toml($toml);
252 if (!defined $nail) {
255 print STDERR "$self: $nailfile transformed into TOML:\n$toml\n";
258 die "$self: parse $nailfile: $e\n";
260 die "$e ?" if length $e;
262 $nail->{subdirs} //= [ ];
264 if (!ref $nail->{subdirs}) {
267 map { s/^\s+//; s/\s+$//; $_; }
273 unshift @configs, $nail;
276 sub get_dependency_tables ($) {
278 my @keys = qw(dependencies build-dependencies dev-dependencies);
282 foreach my $k (@keys) {
283 my $deps = $node->{$k};
284 push @r, $deps if $deps;
288 foreach my $target_node (values %{ $toml->{target} // { } }) {
289 $process->($target_node);
294 our @alt_cargo_lock_stat;
296 sub consider_alt_cargo_lock () {
297 my @ck = qw(alt_cargo_lock);
298 # User should *either* have Cargo.lock in .gitignore,
299 # or expect to commit Cargo.lock.example ($alt_cargo_lock)
301 $alt_cargo_lock = (cfg_uc @ck);
304 if (defined($alt_cargo_lock) && ref($alt_cargo_lock) eq 'HASH') {
305 $force = cfg_bool qw(alt_cargo_lock force);
306 my @ck = qw(alt_cargo_lock file);
307 $alt_cargo_lock = cfg_uc @ck;
309 $alt_cargo_lock //= Types::Serialiser::true;
311 if (Types::Serialiser::is_bool $alt_cargo_lock) {
312 if (!$alt_cargo_lock) { $alt_cargo_lock = undef; return; }
313 $alt_cargo_lock = 'Cargo.lock.example';
316 if (ref($alt_cargo_lock) || $alt_cargo_lock =~ m{/}) {
317 badcfg @ck, "expected boolean, or leafname";
320 if (!stat_exists $alt_cargo_lock, "alt_cargo_lock") {
321 $alt_cargo_lock = undef unless $force;
325 @alt_cargo_lock_stat = stat _;
328 our $oot_dir; # oot.dir or "Build"
331 sub consider_oot () {
332 $oot_dir = cfgs qw(oot dir);
333 my $use = cfgs qw(oot use);
334 unless (defined($oot_dir) || defined($use) ||
335 defined(cfg_uc qw(oot user))) {
338 if (($use//'') eq 'disable') {
342 $oot_dir //= 'Build';
343 $oot_absdir = ($oot_dir !~ m{^/} ? "$worksphere/" : ""). $oot_dir;
351 sub read_manifest ($$$) {
352 my ($subdir, $org_subdir, $why) = @_;
353 my $manifest = "../$subdir/Cargo.toml";
354 print STDERR "$self: reading $manifest...\n" if $verbose>=4;
355 if (defined $manifests{$manifest}) {
357 "$self: warning: $subdir: specified more than once!".
358 " (ignoring $why)\n";
361 foreach my $try ("$manifest.unnailed", "$manifest") {
362 my $toml = toml_or_enoent($try, "manifest, in $why") // next;
363 my $ws = $toml->{workspace};
365 queue_workspace_members($subdir, $org_subdir, $ws, "$subdir, $why");
367 my $p = $toml->{package}{name};
368 if (!defined $p and !defined $ws) {
370 "$self: warning: $subdir, $why: missing package.name in $try, ignoring\n";
373 $manifests{$manifest} = [ $toml, $org_subdir ] if $p;
374 foreach my $dep (get_dependency_tables $toml) {
375 next unless defined $dep->{path};
376 queue_referenced_path($dep->{path}, $org_subdir,
377 "dependency of $subdir, $why");
384 sub queue_workspace_members ($$) {
385 my ($subdir, $org_subdir, $ws_toml, $what) = @_;
386 # We need to (more or less) reimplement the cargo workspace
387 # membership algorithm (see the "workspaces" section of the cargo
388 # reference). How tiresome.
390 # It's not quite the same for us because we aren't interested in
391 # whether cargo thinks things are "in the workspace". But we do
392 # need to do the automatic discover.
394 my @include = @{ $ws_toml->{members} // [ ] };
395 my $exclude = $ws_toml->{exclude} // [ ];
398 s/[^*?0-9a-zA-Z_]/\\$&/g;
403 foreach my $spec (@include) {
404 if ($spec =~ m{^/}) {
406 "$self: warning: absolute workspace member $spec in $what (not nailing, but cargo will probably use it)\n";
409 my $spec_glob = "../$subdir/$spec";
410 my $globflags = GLOB_ERR|GLOB_BRACE|GLOB_NOMAGIC;
411 foreach my $globent (bsd_glob($spec_glob, $globflags)) {
412 next if grep { $globent =~ m{^$_$} } @exclude;
413 queue_referenced_path($globent, $org_subdir,
414 "member of workspace $what");
419 sub queue_referenced_path ($$$) {
420 my ($spec_path, $org_subdir, $why) = @_;
422 qw(realpath), "--relative-to=../$org_subdir", "--", $spec_path
423 or die "$self: fork/pipe/exec for realpath(1)\n";
424 my $rel_path = do { local $/=undef; <REALPATH>; };
426 my $r = close(REALPATH);
427 die "$self: reap realpath: $!\n" if $!;
428 if (!chomp($rel_path) or $?) {
430 "$self: warning: failed to determine realpath for $spec_path in $org_subdir (exit code $?)\n";
433 if ($rel_path =~ m{^\.\./} or $rel_path eq '..') {
435 "$self: warning: $spec_path ($why) points outside $org_subdir, not following so not nailing (although cargo probably will follow it)\n";
439 my $q_subdir = "$org_subdir/$rel_path";
440 print STDERR "$self: making a note to look at $q_subdir, $why)\n"
443 push @queued_paths, [ "$q_subdir", $org_subdir, $why ];
447 foreach my $p (keys %{ $nail->{packages} }) {
448 my $v = $nail->{packages}{$p};
449 my $subdir = ref($v) ? $v->{subdir} : $v;
450 my ($gotpackage, $ws) = read_manifest($subdir, $subdir, "from [packages]");
451 $gotpackage //= '<nothing!>';
452 if ($gotpackage ne $p) {
454 "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
456 die if defined $packagemap{$p};
457 $packagemap{$p} = [ $subdir, $subdir ];
459 foreach my $subdir (@{ $nail->{subdirs} }) {
460 my ($gotpackage,$ws) = read_manifest($subdir, $subdir, "from [subdirs]");
461 if (!defined $gotpackage) {
463 "$self: warning: ignoring subdir $subdir which has no (suitable) Cargo.toml\n"
467 $packagemap{$gotpackage} //= [ $subdir, $subdir ];
469 while (my ($subdir, $org_subdir, $why) = @{ shift @queued_paths or [] }) {
470 next if $manifests{"../$subdir/Cargo.toml"};
471 my ($gotpackage, $ws) = read_manifest($subdir, $org_subdir, $why);
472 next unless $gotpackage;
473 $packagemap{$gotpackage} //= [ $subdir, $org_subdir ];
478 foreach my $p (sort keys %packagemap) {
479 print STDERR "$self: package $p in $packagemap{$p}[0]\n" if $verbose>=2;
481 foreach my $mf (keys %manifests) {
482 my ($toml, $mf_org_subdir) = @{ $manifests{$mf} };
483 foreach my $deps (get_dependency_tables $toml) {
485 foreach my $p (keys %packagemap) {
486 my $info = $deps->{$p};
487 next unless defined $info;
488 next if $packagemap{$p}[1] eq $mf_org_subdir;
489 $deps->{$p} = $info = { } unless ref $info;
490 my $oldpath = $info->{path};
491 delete $info->{version};
492 my $newpath = $worksphere.'/'.$packagemap{$p}[0];
493 print STDERR "in $mf set $p path=$newpath (was ".
494 ($oldpath // '<unset>').")\n"
496 $info->{path} = $newpath;
498 delete $info->{branch};
501 my $nailing = "$mf.nailing~";
502 unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
503 open N, '>', $nailing or die "$self: create new $nailing: $!\n";
504 print N to_toml($toml) or die "$self: write new $nailing: $!\n";
505 close N or die "$self: close new $nailing: $!\n";
510 if (!defined $online) {
511 $_ = cfg_uc qw(misc online);
513 } elsif (Types::Serialiser::is_bool $_) {
518 } elsif (m/^[1ty]/) { # allow booleanish strings
519 $online = 1; # for less user frustration
520 } elsif (m/^[0fn]/) {
523 badcfg qw(misc online), "expected boolean or 'auto', found '$_'";
526 $online //= 1 if subcmd_p('online');
529 $cargo_lock_update //= subcmd_p('lock-update');
533 if (!$cargo_lock_update) {
534 push @add, qw(--locked) unless subcmd_p('!locked');
535 if (defined($oot_dir) && !subcmd_p('!manifest-path')) {
536 my $cargotoml = "${src_absdir}/Cargo.toml";
537 push @args_preface, "--manifest-path=$cargotoml" if $pass_options;
538 push @add, qw(--target-dir=target) unless subcmd_p('!target-dir');
542 if (defined($target) && !subcmd_p('!target')) {
543 if ($target =~ m{^[A-Z]}) {
544 $target = (cfgs 'arch', $target) // $archmap{$target}
545 // die "$self: --target=$target alias specified; not in cfg or map\n";
547 push @add, "--target=$target";
550 push @add, "--offline" unless $online || subcmd_p('!offline');
552 push @args_preface, @add if $pass_options;
553 die if grep { m/ / } @add;
554 $ENV{NAILINGCARGO_CARGO_OPTIONS} = "@add";
556 unshift @ARGV, @args_preface;
559 our $build_absdir; # .../Build/<subdir>
561 sub oot_massage_cmdline () {
562 return unless defined $oot_dir;
564 my $use = cfgs qw(oot use);
565 $use // die "$self: out-of-tree build, but \`oot.use' not configured\n";
566 $build_absdir = "$oot_absdir/$subdir";
568 my ($pre,$post) = ('','');
570 if (!$cargo_lock_update) {
571 push @xargs, $build_absdir;
572 ($pre, $post) = ('cd "$1"; shift; ', '');
574 push @xargs, $oot_absdir, $subdir, $src_absdir;
577 mkdir -p -- "$1"; cd "$1"; shift;
578 clean () { find -lname "$1/*" -print0 | xargs -0r rm --; }; clean;
579 find "$1" -maxdepth 1 \! -name Cargo.lock -print0 | xargs -0r -I_ ln -sf -- _ .;
581 $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
583 cp -- "$1"/Cargo.lock .;
588 # $post = <<'ENDCLEAN';
592 my $addpath = (cfg_uc qw(oot path_add)) //
593 $use eq 'really' ? Types::Serialiser::true : Types::Serialiser::false;
595 !Types::Serialiser::is_bool $addpath ? $addpath :
596 $addpath ? '$HOME/.cargo/bin' :
598 if (defined $addpath) {
600 PATH=$addpath:\${PATH-/usr/local/bin:/bin:/usr/bin};
604 $pre =~ s/^\s+//mg; $pre =~ s/\s+/ /g;
605 $post =~ s/^\s+//mg; $post =~ s/\s+/ /g;
607 my $getuser = sub { cfgsn qw(oot user) };
609 my $xe = $verbose >= 2 ? 'xe' : 'e';
612 @command = (@_, 'sh',"-${xe}c",$pre.'exec "$@"','--',@xargs);
614 @command = (@_, 'sh',"-${xe}c",$pre.'"$@"; '.$post,'--',@xargs);
616 push @command, @ARGV;
618 my $command_sh = sub {
619 my $quoted = join ' ', map {
624 @command = @_, "set -${xe}; $pre $quoted; $post";
626 print STDERR "$self: out-of-tree, building in: \`$build_absdir'\n"
628 if ($use eq 'really') {
629 my $user = $getuser->();
630 my @pw = getpwnam $user or die "$self: oot.user \`$user' lookup failed\n";
631 my $homedir = $pw[7];
632 $sh_ec->('really','-u',$user,'env',"HOME=$homedir");
633 print STDERR "$self: using really to run as user \`$user'\n" if $verbose;
634 } elsif ($use eq 'ssh') {
635 my $user = $getuser->();
636 $user .= '@localhost' unless $user =~ m/\@/;
637 $command_sh->('ssh',$user);
638 print STDERR "$self: using ssh to run as \`$user'\n" if $verbose;
639 } elsif ($use eq 'command_args') {
640 my @c = cfgn_list qw(oot command);
642 print STDERR "$self: out-of-tree, adverbial command: @c\n" if $verbose;
643 } elsif ($use eq 'command_sh') {
644 my @c = cfgn_list qw(oot command);
646 print STDERR "$self: out-of-tree, ssh'ish command: @c\n" if $verbose;
647 } elsif ($use eq 'null') {
650 die "$self: oot.use mode $use not recognised\n";
657 $ENV{CARGO_MANIFEST_DIR} = $src_absdir;
658 $ENV{NAILINGCARGO_MANIFEST_DIR} = $src_absdir;
659 $ENV{NAILINGCARGO_WORKSPHERE} = $worksphere;
660 $ENV{NAILINGCARGO_BUILDSPHERE} = $oot_absdir;
661 delete $ENV{NAILINGCARGO_BUILDSPHERE} unless $oot_absdir;
662 $ENV{NAILINGCARGO_BUILD_DIR} = $build_absdir // $src_absdir;
668 if ($want_uninstall) {
670 foreach my $mf (keys %manifests) {
671 eval { uninstall1($mf,1); 1; } or warn "$@";
673 eval { unaltcargolock(1); 1; } or warn "$@";
677 sub consider_directories () {
678 return unless defined $oot_dir;
679 my $bsubdir = "../$oot_dir/$subdir";
680 return if stat $bsubdir;
681 die "$0: build directory $bsubdir inaccessible\n"
683 return if $cargo_lock_update; # will make it
684 die "$0: build directory $bsubdir does not exist, and not in Cargo.lock update mode!\n";
687 our $cleanup_cargo_lock;
689 foreach my $mf (keys %manifests) {
690 link "$mf", "$mf.unnailed" or $!==EEXIST
691 or die "$self: make backup link $mf.unnailed: $!\n";
694 if (defined($alt_cargo_lock)) {
695 if (@alt_cargo_lock_stat) {
696 print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
698 if (link $alt_cargo_lock, 'Cargo.lock') {
699 print STDERR " linked\n" if $verbose>=3;
700 } elsif ($! != EEXIST) {
701 print STDERR "\n" if $verbose>=3;
702 die "$self: make \`Cargo.lock' available as \`$alt_cargo_lock': $!\n";
704 print STDERR "checking quality." if $verbose>=3;
705 my @lock_stat = stat 'Cargo.lock'
706 or die "$self: stat Cargo.lock (for alt check: $!\n";
707 same_file(\@alt_cargo_lock_stat, \@lock_stat)
709 "$self: \`Cargo.lock' and alt file \`$alt_cargo_lock' both exist and are not the same file!\n";
711 $cleanup_cargo_lock = 1;
713 $cleanup_cargo_lock = 1;
714 # If Cargo.lock exists and alt doesn't, that means either
715 # that a previous run was interrupted, or that the user has
723 my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
728 my @our_unfound_stab = stat_exists('Cargo.toml', 'local Cargo.toml')
730 foreach my $mf (keys %manifests) {
731 if (@our_unfound_stab) {
732 if (stat_exists $mf, "manifest in to-be-nailed directory") {
733 my @mf_stab = stat _ ;
734 if ("@mf_stab[0..1]" eq "@our_unfound_stab[0..1]") {
735 @our_unfound_stab = ();
740 my $nailing = "$mf.nailing~";
741 my $nailed = nailed($mf);
744 if (open NN, '<', $nailed) {
745 $diff = compare($nailing, \*NN);
746 die "$self: compare $nailing and $nailed: $!" if $diff<0;
748 $!==ENOENT or die "$self: check previous $nailed: $!\n";
758 rename $use, $mf or die "$self: install nailed $use: $!\n";
759 unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
760 print STDERR "$self: nailed $mf\n" if $verbose>=3;
763 if (@our_unfound_stab) {
765 "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
770 my $r = system @ARGV;
774 print STDERR "$self: could not execute $ARGV[0]: $!\n";
776 } elsif ($r & 0xff00) {
777 print STDERR "$self: $ARGV[0] failed (exit status $r)\n";
780 print STDERR "$self: $ARGV[0] died due to signal! (wait status $r)\n";
785 sub cargo_lock_update_after () {
786 if ($cargo_lock_update) {
787 # avoids importing File::Copy and the error handling is about as good
789 my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
790 die "$self: run cp: $! $?" if $r<0 || $r & 0xff;
791 die "$self: failed to update local Cargo.lock (wait status $r)\n" if $r;
795 sub uninstall1 ($$) {
796 my ($mf, $enoentok) = @_;
797 my $unnailed = "$mf.unnailed";
798 rename $unnailed, $mf or ($enoentok && $!==ENOENT)
799 or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
802 sub unaltcargolock ($) {
804 return unless $cleanup_cargo_lock;
805 die 'internal error!' unless defined $alt_cargo_lock;
807 # we ignore $enoentok because we don't know if one was supposed to
810 rename('Cargo.lock', $alt_cargo_lock) or $!==ENOENT or die
811 "$self: cleanup: rename possibly-updated \`Cargo.lock' to \`$alt_cargo_lock': $!\n";
813 unlink 'Cargo.lock' or $!==ENOENT or die
814 "$self: cleanup: remove \`Cargo.lock' in favour of \`$alt_cargo_lock': $!\n";
815 # ^ this also helps clean up the stupid rename() corner case
819 foreach my $mf (keys %manifests) {
820 my $nailed = nailed($mf);
821 link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
830 # Loop exit condition:
833 # $is_cargo==1 <cargo-command> <cargo-opts> [--] <subcmd>...
834 # $is_cargo==0 <build-command>...
837 @ARGV or die "$self: need cargo subcommand\n";
842 my $not_a_nailing_opt = sub { # usage 1
843 unshift @ARGV, $orgopt;
844 unshift @ARGV, 'cargo';
846 no warnings qw(exiting);
849 $not_a_nailing_opt->() unless m{^-};
850 $not_a_nailing_opt->() if $_ eq '--';
852 if ($_ eq '---') { # usage 2 or 3
853 die "$self: --- must be followed by build command\n" unless @ARGV;
854 if ($ARGV[0] eq '--') { # usage 3
857 } elsif (grep { $_ eq '--' } @ARGV) { # usage 2
859 } elsif ($ARGV[0] =~ m{[^/]*cargo[^/]*$}) { # usage 2
870 } elsif (s{^-v}{-}) {
872 } elsif (s{^-q}{-}) {
874 } elsif (s{^-n}{-}) {
876 } elsif (s{^-s(.+)}{-}s) {
878 } elsif (s{^-([uU])}{-}) {
879 $cargo_lock_update = $1=~m/[a-z]/;
880 } elsif (s{^-([cC])}{-}) {
881 $pass_options = $1=~m/[a-z]/;
882 } elsif (s{^-D}{-}) {
884 } elsif (s{^-T(.+)}{-}s) {
886 } elsif (s{^-([oO])}{-}) {
887 $online = $1=~m/[a-z]/;
889 die "$self: unknown short option(s) $_\n" unless $_ eq $orgopt;
890 $not_a_nailing_opt->();
893 } elsif (s{^--help$}{}) {
895 } elsif (s{^--target=}{}) {
897 } elsif (m{^--(on|off)line$}) {
898 $online = $1 eq 'on';
899 } elsif (s{^--subcommand-props=}{}) {
900 my @props = split /\,/, $_;
902 if (!%subcmd_prop_ok) {
903 foreach my $v (\@subcmd_xprops, values %subcmd_props) {
904 $subcmd_prop_ok{$_}=1 foreach @$v;
908 or die "$self: unknown subcommand property \`$_'\n"
910 $cargo_subcmd = \@props;
911 } elsif (m{^--(no-)?cargo-lock-update}) {
912 $cargo_lock_update= !!$1;
914 $not_a_nailing_opt->();
922 @args_preface = shift @ARGV;
923 while (defined($_ = shift @ARGV)) {
924 if (!m{^-}) { unshift @ARGV, $_; last; }
925 if ($_ eq '--') { last; }
926 push @args_preface, $_;
928 @ARGV || die "$self: need cargo subcommand\n";
929 $cargo_subcmd //= $ARGV[0];
932 $cargo_subcmd //= '';
935 push @args_preface, shift @ARGV;
937 if (!ref($cargo_subcmd)) {
938 print STDERR " cargo_subcmd lookup $cargo_subcmd\n" if $dump;
939 $cargo_subcmd = $subcmd_props{$cargo_subcmd} // [ ];
942 print STDERR " cargo_subcmd props @$cargo_subcmd\n" if $dump;
944 $cargo_subcmd{$_} = 1 foreach @$cargo_subcmd;
945 $cargo_subcmd = \%cargo_subcmd;
952 consider_alt_cargo_lock();
957 consider_directories();
958 our @display_cmd = @ARGV;
959 oot_massage_cmdline();
965 print STDERR Dumper(\%manifests) if $dump>=2;
966 print STDERR Dumper(\%packagemap, \@ARGV,
967 { src_absdir => $src_absdir,
968 worksphere => $worksphere,
971 oot_absdir => $oot_absdir,
972 build_absdir => $build_absdir });
982 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
983 (scalar keys %manifests), (scalar keys %packagemap),
984 (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
987 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
988 my $estatus = invoke();
990 cargo_lock_update_after();
995 print STDERR "$self: unnailed. status $estatus.\n" if $verbose;