chiark / gitweb /
Provide --no-cargo-lock-manip option
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Sep 2020 23:19:05 +0000 (00:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Sep 2020 23:19:05 +0000 (00:19 +0100)
And clarify docs etc.

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

index bf80419ac4832c0e45dfbf95d9175b87c7b746a4..46086ed53d3860d8892d56d1d19ebaec218d1814 100644 (file)
--- a/README.md
+++ b/README.md
@@ -385,11 +385,18 @@ Options
     commands that don't actually invoke cargo.  Consider passingm
     `--no-lock` too.
 
+  * `--no-cargo-lock-manip` | `--cargo-lock-manip` (default):
+    Whether to manipulate `Cargo.lock`.  For example, whether to copy
+    it to the build tree and back (in out of tree mode) and whether to
+    rename it from an alternative lockfile name, and put it back.
+    Overrides `-u` etc.
+
   * `--no-lock` | `--lock` (default): Whether to take the
     nailing-cargo lock.  Some kind of protection against concurrent
     operation is necessary to prevent multiple instances of
     nailing-cargo trashing each others' work, and possibly mangling
-    your `Cargo.toml`s.
+    your `Cargo.toml`s, `Cargo.lock`, etc., so `--no-lock` is dangerous
+    unless you take other measures against concurrent execution.
 
   * `-h` | `--help`: Print usage summary.
 
index 722b6d803c7035f3190710f63163e96dab8919fe..5d92b037117ee430e2c03b23cfda3e2da4010c27 100755 (executable)
@@ -29,7 +29,8 @@ options:
   --leave-nailed                  Leave the nailed Cargo.toml in place
   --just-linkfarm | --clean-linkfarm | --keep-linkfarm (default)
   --no-nail                       Do not nail, just run the command.
-  --no-lock                       Do not take the lock.
+  --no-cargo-lock-manip           Do not manipulate Cargo.lock.
+  --no-lock                       Do not take the concurrency lock.
 
   -s<subcommand>                  Treat command as `cargo <subcommand>`
   --subcommand-props=<prop>,...   Override command props (see docs)
@@ -93,6 +94,7 @@ our $just_linkfarm;
 our $leave_nailed;
 our $oot_clean;
 our $do_nail=1;
+our $do_cargo_lock=1;
 our $do_lock=1;
 
 #
@@ -320,6 +322,8 @@ sub consider_alt_cargo_lock () {
   # User should *either* have Cargo.lock in .gitignore,
   # or expect to commit Cargo.lock.example ($alt_cargo_lock)
 
+  return unless $do_cargo_lock;
+
   $alt_cargo_lock = (cfg_uc @ck);
 
   my $force = 0;
@@ -614,7 +618,7 @@ sub oot_massage_cmdline () {
        clean () { find -lname "$1/*" -print0 | xargs -0r rm --; }; clean;
        find "$1" -maxdepth 1 \! -name Cargo.lock -print0 | xargs -0r -I_ ln -sf -- _ .;
 END
-    $pre .= <<'ENDLK' if stat_exists 'Cargo.lock', 'working cargo lockfile';
+    $pre .= <<'ENDLK' if $do_cargo_lock && stat_exists 'Cargo.lock', 'working cargo lockfile';
        rm -f Cargo.lock;
         cp -- "$1"/Cargo.lock .;
 ENDLK
@@ -728,6 +732,7 @@ sub makebackups () {
   }
 
   if (defined($alt_cargo_lock)) {
+    die 'internal error' unless $do_cargo_lock;
     if (@alt_cargo_lock_stat) {
       print STDERR "$self: using alt_cargo_lock `$alt_cargo_lock'..."
        if $verbose>=3;
@@ -819,7 +824,7 @@ sub invoke () {
 }
 
 sub cargo_lock_update_after () {
-  if ($cargo_lock_update && !$just_linkfarm) {
+  if ($do_cargo_lock && $cargo_lock_update && !$just_linkfarm) {
     # avoids importing File::Copy and the error handling is about as good
     $!=0; $?=0;
     my $r= system qw(cp --), "$build_absdir/Cargo.lock", "Cargo.lock";
@@ -838,7 +843,7 @@ sub uninstall1 ($$) {
 sub unaltcargolock ($) {
   my ($enoentok) = @_;
   return unless $cleanup_cargo_lock;
-  die 'internal error!' unless defined $alt_cargo_lock;
+  die 'internal error!' unless $do_cargo_lock && defined $alt_cargo_lock;
 
   # we ignore $enoentok because we don't know if one was supposed to
   # have been created.
@@ -948,6 +953,8 @@ sub parse_args () {
       $oot_clean = $1 eq 'clean';
     } elsif (m{^--(no)?-nail$}) {
       $do_nail = !$1;
+    } elsif (m{^--(no)?-cargo-lock-manip$}) {
+      $do_cargo_lock = !$1;
     } elsif (m{^--(no)?-lock$}) {
       $do_lock = !$1;
     } elsif (m{^--leave-nailed$}) {