chiark / gitweb /
Provide --no-nail option
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Sep 2020 11:46:17 +0000 (12:46 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Sep 2020 22:28:13 +0000 (23:28 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
nailing-cargo

index fbba6988335daa52772193162ba5d8aa6bb37264..bf80419ac4832c0e45dfbf95d9175b87c7b746a4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -379,6 +379,12 @@ Options
      `.Cargo.toml.nailed~`, so you only need this if you want to run
     cargo by hand or something.
 
+  * `--no-nail` | `--nail` (default): Whether to actually nail - ie,
+    whether to actually modify any `Cargo.toml`s while running the
+    command.  This can be useful, e.g., in out-of-tree mode with
+    commands that don't actually invoke cargo.  Consider passingm
+    `--no-lock` too.
+
   * `--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
index b2f1f8c0268615d69b219998f1f699ce7a7bc503..722b6d803c7035f3190710f63163e96dab8919fe 100755 (executable)
@@ -28,6 +28,7 @@ options:
   --man --manual                  Display complete manual (in w3m)
   --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.
 
   -s<subcommand>                  Treat command as `cargo <subcommand>`
@@ -91,6 +92,7 @@ our $online;
 our $just_linkfarm;
 our $leave_nailed;
 our $oot_clean;
+our $do_nail=1;
 our $do_lock=1;
 
 #
@@ -465,6 +467,10 @@ sub queue_referenced_path ($$$) {
 }
 
 sub readorigs () {
+  # We (and our callees) populate %packagemap and %manifest, so if we
+  # don't run, they remain empty and nothing is nailed.
+  return unless $do_nail;
+
   foreach my $p (keys %{ $nail->{packages} }) {
     my $v = $nail->{packages}{$p};
     my $subdir = ref($v) ? $v->{subdir} : $v;
@@ -500,7 +506,7 @@ sub calculate () {
     print STDERR "$self: package $p in $packagemap{$p}[0]\n" if $verbose>=2;
   }
   foreach my $mf (keys %manifests) {
-    die "internal error" if $do_nail; # belt and braces
+    die "internal error" unless $do_nail; # belt and braces
 
     my ($toml, $mf_org_subdir) = @{ $manifests{$mf} };
     foreach my $deps (get_dependency_tables $toml) {
@@ -790,7 +796,7 @@ sub install () {
     print STDERR "$self: nailed $mf\n" if $verbose>=3;
   }
 
-  if (@our_unfound_stab) {
+  if (@our_unfound_stab && $do_nail) {
     print STDERR
  "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
   }
@@ -940,6 +946,8 @@ sub parse_args () {
       $cargo_lock_update= 1;
     } elsif (m{^--(clean|keep)-linkfarm$}) {
       $oot_clean = $1 eq 'clean';
+    } elsif (m{^--(no)?-nail$}) {
+      $do_nail = !$1;
     } elsif (m{^--(no)?-lock$}) {
       $do_lock = !$1;
     } elsif (m{^--leave-nailed$}) {
@@ -1030,7 +1038,7 @@ install();
 printf STDERR "$self: nailed (%s manifests, %s packages)%s\n",
   (scalar keys %manifests), (scalar keys %packagemap),
   (defined($alt_cargo_lock) and ", using `$alt_cargo_lock'")
-  if $verbose;
+  if $verbose && $do_nail;
 
 print STDERR "$self: invoking: @display_cmd\n" if $verbose;
 my $estatus = invoke();
@@ -1040,6 +1048,7 @@ cargo_lock_update_after();
 uninstall() unless $leave_nailed;
 $want_uninstall = 0;
 
-print STDERR "$self: unnailed.  status $estatus.\n" if $verbose;
+print STDERR "$self: ".($do_nail ? "unnailed" : "finished")
+             .".  status $estatus.\n" if $verbose;
 
 exit $estatus;