chiark / gitweb /
Pass options right after the cargo subommand
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 13:08:33 +0000 (14:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 13:08:33 +0000 (14:08 +0100)
This means that the user can pass non-option arguments to cargo (eg
for cargo run).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
nailing-cargo

index f989ab6b2427bc629db899d2ca2102159f7a32d5..5eede1eb025214a7bdd012cc81b7b09776460817 100644 (file)
--- 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].
 
index 006e02930d61c1814ad201bbae007329b4fc8e7c..491295572644623f0cbb7f4e5babe0fc2e8bdeb6 100755 (executable)
@@ -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;