chiark / gitweb /
nailing-cargo: offline by default
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jun 2020 22:03:06 +0000 (23:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jun 2020 22:03:06 +0000 (23:03 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
nailing-cargo

index bb555408955196c4864ac5fc6100aea9d91bbf5a..31eefe780dbc2af33d07181686aa525fd9dfbde0 100755 (executable)
 #         Done automatically when nailing-cargo sees that the cargo
 #         subcommand is one which needs it, eg `fetch'.
 #
+#    --online | --offline         
+#         Whether to allow cargo to make network access.
+#         (nailing-cargo always passes --offline to cargo, unless
+#         --online is in force).  The default is offline,
+#         unless the cargo subcommand is one which implies
+#         online (currently, `fetch').
+#
 # Cargo.nail:
 #
 #    # Adds each <subdir> to the list of directories whose
 #  or
 #    use = "null"
 #
+# Other settings:
+#    [misc]
+#    online = true   # forces default to be --online
+#    online = false  # forces default to be --offline
+#
 # Limitations:
 #
 #   Always dirties everyone's Cargo.toml, but tries to put them
@@ -204,6 +216,7 @@ our $cargo_lock_update;
 our $cargo_manifest_args;
 our $cargo_target_arg=1;
 our $alt_cargo_lock;
+our $online;
 
 our @configs;
 our $verbose=1;
@@ -500,6 +513,8 @@ sub calculate () {
 }
 
 sub addargs () {
+  $online //= cfg_bool qw(misc online);
+
   if (@ARGV>=2 &&
       $ARGV[0] =~ m{\bcargo\b}) {
     if ($ARGV[1] =~ m/^(?:generate-lockfile|update)$/) {
@@ -508,12 +523,15 @@ sub addargs () {
     }
     if ($ARGV[1] =~ m/^(?:fetch)$/) {
       $cargo_target_arg=0;
+      $online //= 1;
     }
   }
   $cargo_lock_update //= 0;
   $cargo_manifest_args //=
     (defined $oot_dir) && !$cargo_lock_update;
 
+  $online //= 0;
+
   if ($cargo_manifest_args) {
     push @ARGV, "--manifest-path=${src_absdir}/Cargo.toml",
       qw(--locked);
@@ -527,6 +545,8 @@ sub addargs () {
     }
     push @ARGV, "--target=$target";
   }
+
+  push @ARGV, "--offline" unless $online;
 }
 
 our $oot_absdir;
@@ -806,6 +826,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
     $cargo_manifest_args= !!$1;
   } elsif (m{^--(no-)?cargo-target-arg}) {
     $cargo_target_arg= !!$1;
+  } elsif (m{^--(on|off)line$}) {
+    $online = $1 eq 'on';
   } else {
     die "$self: unknown long option $_\n";
   }