From: Ian Jackson Date: Mon, 21 Jun 2021 11:45:23 +0000 (+0100) Subject: Implement -EE (copy-edit-all) X-Git-Tag: nailing-cargo/1.0.0~13 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=364a10a94273450cd1895bb2104348b1b300e3b1;p=nailing-cargo.git Implement -EE (copy-edit-all) Signed-off-by: Ian Jackson --- diff --git a/README.md b/README.md index 3269cde..893a698 100644 --- a/README.md +++ b/README.md @@ -418,6 +418,11 @@ WASM="wasm32-unknown-unknown" tracked filles* can be edited by the cargo command; edits to other files, and creation of new files, will be ignored. + When this option is repeated (**`-EE`**), the cargo subcommand can + create new files including dotfiles (but nothing in the toplevel + `target` and nothing called `.git`). (This also enables + `--preclean=src` by default.) + If you are running out of tree builds for privsep reasons, you should use git to review the edits made by the cargo command and either stage and commit them, or reject them. diff --git a/nailing-cargo b/nailing-cargo index bc0114e..af32be0 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -27,7 +27,7 @@ options: -h --help Print this message --doc --man --manual Display complete manual (in w3m) --leave-nailed Leave the nailed Cargo.toml in place - -E | --edits-sources Allow source edits + -E | --edits-sources Allow source edits (repeat: file creation) --linkfarm[=no|shallow|git|full] (default varies, usually "no") --just-linkfarm | --clean-linkfarm | --keep-linkfarm (default is keep) --[no-]preclean-build[=no|src|full] (default is no) @@ -577,6 +577,14 @@ sub addargs () { $online //= 1 if subcmd_p('online'); $online //= 0; + if ($linkfarm_depth eq 'copy-edit-all') { + $oot_preclean //= 'src'; + if ($oot_preclean !~ m/^(?:src|full)$/) { + print STDERR + "$self: *WARNING*: -EE specified, but also --preclean=no; will probably leave your source tree full of junk\n"; + } + } + if (subcmd_p('linkfarm-gitclean')) { $linkfarm_depth //= 'git'; $oot_preclean //= 'src'; @@ -613,7 +621,10 @@ sub addargs () { push @add, "--offline" unless $online || subcmd_p('!offline'); - if (subcmd_p('edits') && $linkfarm_depth ne 'copy-edit') { + if (subcmd_p('creates') && $linkfarm_depth !~ m/^copy-edit-all/) { + print STDERR + "$self: *WARNING*: this subcommand expects to create new source files; you probably want to specify --edits-sources twice aka -EE (which is not the default even now, for safety reasons)\n"; + } elsif (subcmd_p('edits') && $linkfarm_depth !~ m/^copy-edit/) { print STDERR "$self: *WARNING*: this subcommand expects to edit the source code; you probably want to specify --edits-sources aka -E (which is not the default even now, for safety reasons)\n"; } @@ -685,7 +696,7 @@ END_FILES_FULL symlink "$src/$_", "$_" or die "$_ $!"; ' "$src"; END_DEEP - } elsif ($linkfarm_depth eq 'copy-edit') { + } elsif ($linkfarm_depth =~ m/^copy-edit/) { $pre .= <<'END_COPY_EDIT'; find -lname "$src/*" -print0 | xargs -0r rm --; (set -e; cd "$src"; git ls-files -c -z | @@ -694,8 +705,17 @@ END_DEEP (set -e; cd "$src"; git ls-files -c -z) | xargs -0r rm -f --; }; END_COPY_EDIT - $post .= <<'END_COPY_EDIT_BUNDLE'; + if ($linkfarm_depth eq 'copy-edit-all') { + $post .= <<'END_COPY_EDIT_GENFILES_ALL'; + find -xdev \( \( -name .git -o -path ./target -o -path ./nailing-cargo-update.tar \) -prune \) -o + \( -type l -o -type f \) -print0 | +END_COPY_EDIT_GENFILES_ALL + } else { + $post .= <<'END_COPY_EDIT_GENFILES_GIT'; (set -e; cd "$src"; git ls-files -c -z) | +END_COPY_EDIT_GENFILES_GIT + } + $post .= <<'END_COPY_EDIT_BUNDLE'; cpio -Hustar -o0 --quiet >"nailing-cargo-update.tar"; END_COPY_EDIT_BUNDLE } else { @@ -906,12 +926,22 @@ sub invoke () { } sub files_return_after_update () { - if ($linkfarm_depth eq 'copy-edit') { - system qw(sh -ec), <<'END', 'x', "$build_absdir"; + if ($linkfarm_depth =~ m/^copy-edit/) { + my $tar_source_opts; + my $tar_stdin; + if ($linkfarm_depth eq 'copy-edit-all') { + $tar_source_opts = '--null --files-from=-'; + $tar_stdin = <<'END_GIT_FILES'; git ls-files -c -z | \ +END_GIT_FILES + } else { + $tar_source_opts = '--anchored --exclude=.git --exclude="*/.git" --exclude=target --exclude=nailing-cargo-update.tar'; + $tar_stdin = ''; + } + system qw(sh -ec), $tar_stdin . <<'END', 'x', "$build_absdir"; tar -x --keep-newer-files --no-same-permissions --no-same-owner \ --no-acls --no-selinux --no-xattrs --warning=no-ignore-newer \ - -Hustar --null --files-from=- --force-local \ + -Hustar $tar_source_opts --force-local \ -f "$1/nailing-cargo-update.tar" END } elsif ($do_cargo_lock && $cargo_lock_update && !$just_linkfarm) { @@ -985,7 +1015,8 @@ sub parse_args () { $not_a_nailing_opt->() if $_ eq '--'; my $edits_sources = sub { - $linkfarm_depth = 'copy-edit'; + $linkfarm_depth = + ($linkfarm_depth//'') eq 'copy-edit' ? 'copy-edit-all' : 'copy-edit'; }; if ($_ eq '---') { # usage 2 or 3