From: Ian Jackson Date: Sun, 21 Jun 2020 13:08:33 +0000 (+0100) Subject: Pass options right after the cargo subommand X-Git-Tag: nailing-cargo/1.0.0~124 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=012973a87d8ef58452538ec686a967f4d3fbc6bd;p=nailing-cargo.git Pass options right after the cargo subommand This means that the user can pass non-option arguments to cargo (eg for cargo run). Signed-off-by: Ian Jackson --- diff --git a/README.md b/README.md index f989ab6..5eede1e 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,9 @@ Options were cargo. With `-C`, nailing-cargo will not add additional options to the build command. With `-c` it will pass those options - at the end of the build command. + after the cargo subcommand (usages 1 and 2) or right + after the build command (usage 3). + The cargo options are in any case also passed in the environment - see [Environment of the build command]. diff --git a/nailing-cargo b/nailing-cargo index 006e029..4912955 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -43,6 +43,7 @@ our $subdir = $1; # leafname our $lockfile = "../.nailing-cargo.lock"; +our @args_preface; our $cargo_subcmd; our $command_is_cargo; our $alt_cargo_lock; @@ -374,7 +375,8 @@ sub addargs () { if (!$cargo_lock_update) { push @add, qw(--locked) unless subcmd_p('!locked'); if (defined($oot_dir) && !subcmd_p('!manifest-path')) { - push @ARGV, "--manifest-path=${src_absdir}/Cargo.toml" if $pass_options; + my $cargotoml = "${src_absdir}/Cargo.toml"; + push @args_preface, "--manifest-path=$cargotoml" if $pass_options; push @add, qw(--target-dir=target) unless subcmd_p('!target-dir'); } } @@ -389,9 +391,11 @@ sub addargs () { push @add, "--offline" unless $online || subcmd_p('!offline'); - push @ARGV, @add if $pass_options; + push @args_preface, @add if $pass_options; die if grep { m/ / } @add; $ENV{NAILINGCARGO_CARGO_OPTIONS} = "@add"; + + unshift @ARGV, @args_preface; } our $oot_absdir; @@ -744,20 +748,20 @@ sub parse_args () { @ARGV || die; if ($is_cargo) { - my @cargo_and_opts = shift @ARGV; + @args_preface = shift @ARGV; while (defined($_ = shift @ARGV)) { if (!m{^-}) { unshift @ARGV, $_; last; } if ($_ eq '--') { last; } - push @cargo_and_opts, $_; + push @args_preface, $_; } @ARGV || die "$self: need cargo subcommand\n"; $cargo_subcmd //= $ARGV[0]; $pass_options //= 1; - unshift @ARGV, @cargo_and_opts; } else { $cargo_subcmd //= ''; $pass_options //= 0; } + push @args_preface, shift @ARGV; if (!ref($cargo_subcmd)) { print STDERR " cargo_subcmd lookup $cargo_subcmd\n" if $dump;