X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=nailing-cargo;h=c9ee071e3f578305207da6ba4440408434ff54cf;hb=refs%2Fheads%2Fmain;hp=9a636e10863b0c7b7e8888331931998c69955b26;hpb=b70e7c1d27eca5c8357dc72b6fdba3155fa149fc;p=nailing-cargo.git diff --git a/nailing-cargo b/nailing-cargo index 9a636e1..c9ee071 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -27,8 +27,11 @@ 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 (repeat: file creation) + -f | --force Override some warnings + --linkfarm[=no|shallow|git|full] (default varies, usually "no") --just-linkfarm | --clean-linkfarm | --keep-linkfarm (default is keep) - --[no-]preclean-linkfarm[=no|src|full] (default is no) + --[no-]preclean-build[=no|src|full] (default is no) --just-run Run the command, don't do cargo stuff --no-nail Do not nail, just run the command. --no-cargo-lock-manip Do not manipulate Cargo.lock. @@ -105,11 +108,14 @@ our $linkfarm_depth; # our %subcmd_props = ( # build (default) =>[qw( )], -'generate-lockfile'=>[qw( lock-update !target !target-dir )], - update =>[qw( lock-update !target online )], fetch =>[qw( online !target-dir )], fmt =>[qw( !locked !target !offline !target-dir edits )], +'generate-lockfile'=>[qw( lock-update !target !target-dir )], + init =>[qw( creates )], + metadata =>[qw( !target-dir )], miri =>[qw( !locked !offline linkfarm-shallow )], + publish =>[qw( !offline linkfarm-gitclean )], + update =>[qw( lock-update !target online )], upgrades =>[qw( !locked !target-dir )], ); @@ -117,6 +123,8 @@ our @subcmd_xprops = qw(!manifest-path); our @configs; our $verbose=1; +our $force=0; +our $forced=0; our ($noact,$dump); our $target; @@ -132,6 +140,17 @@ sub show_manual () { die "$self: exec sh failed: $!"; } +sub forceable_warning ($) { + my ($m) = @_; + print STDERR "$self: *WARNING*: $m\n"; + if ($force) { + print STDERR "$self: continuing because of --force...\n" unless $forced++; + return; + } else { + die "$self: Stopping due to warning (override with -f | --force)\n"; + } +} + sub read_or_enoent ($) { my ($fn) = @_; if (!open R, '<', $fn) { @@ -523,11 +542,12 @@ sub calculate () { my ($toml, $mf_org_subdir) = @{ $manifests{$mf} }; foreach my $deps (get_dependency_tables $toml) { next unless $deps; - foreach my $p (keys %packagemap) { - my $info = $deps->{$p}; - next unless defined $info; + foreach my $dep_key (keys %$deps) { + my $info = $deps->{$dep_key}; + my $p = (ref $info ? $info->{package} : undef) // $dep_key; + next unless defined $packagemap{$p}; next if $packagemap{$p}[1] eq $mf_org_subdir; - $deps->{$p} = $info = { } unless ref $info; + $deps->{$dep_key} = $info = { } unless ref $info; # was just version my $oldpath = $info->{path}; delete $info->{version}; my $newpath = $worksphere.'/'.$packagemap{$p}[0]; @@ -574,6 +594,19 @@ 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)$/) { + forceable_warning + "-EE specified, but also --preclean=no; will probably leave your source tree full of junk"; + } + } + + if (subcmd_p('linkfarm-gitclean')) { + $linkfarm_depth //= 'git'; + $oot_preclean //= 'src'; + } + $cargo_lock_update //= subcmd_p('lock-update'); $linkfarm_depth //= subcmd_p('linkfarm-shallow') ? 'shallow' : @@ -605,9 +638,12 @@ sub addargs () { push @add, "--offline" unless $online || subcmd_p('!offline'); - if (subcmd_p('edits') && $linkfarm_depth ne '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"; + if (subcmd_p('creates') && $linkfarm_depth !~ m/^copy-edit-all/) { + forceable_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)"; + } elsif (subcmd_p('edits') && $linkfarm_depth !~ m/^copy-edit/) { + forceable_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)"; } push @args_preface, @add if $pass_options; @@ -677,7 +713,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 | @@ -686,8 +722,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 { @@ -898,12 +943,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) { @@ -976,6 +1031,11 @@ sub parse_args () { $not_a_nailing_opt->() unless m{^-}; $not_a_nailing_opt->() if $_ eq '--'; + my $edits_sources = sub { + $linkfarm_depth = + ($linkfarm_depth//'') eq 'copy-edit' ? 'copy-edit-all' : 'copy-edit'; + }; + if ($_ eq '---') { # usage 2 or 3 if (!@ARGV) { die "$self: --- must be followed by build command\n" unless $noact; @@ -1003,6 +1063,8 @@ sub parse_args () { $verbose=0; } elsif (s{^-n}{-}) { $noact++; + } elsif (s{^-f}{-}) { + $force++; } elsif (s{^-s(.+)}{-}s) { $cargo_subcmd = $1; } elsif (s{^-([uU])}{-}) { @@ -1012,7 +1074,7 @@ sub parse_args () { } elsif (s{^-D}{-}) { $dump++; } elsif (s{^-E}{-}) { - $linkfarm_depth = 'copy-edit'; + $edits_sources->(); } elsif (s{^-T(.+)}{-}s) { $target = $1; } elsif (s{^-([oO])}{-}) { @@ -1037,14 +1099,16 @@ sub parse_args () { } elsif (m{^--linkfarm(?:=(no|shallow|git|full))?$}) { $linkfarm_depth = $1 || 'git'; } elsif (m{^--edits?-sources?$}) { - $linkfarm_depth = 'copy-edit'; + $edits_sources->(); + } elsif (m{^--force$}) { + $force++; } elsif (m{^--just-run$}) { $do_nail = $do_cargo_lock = $do_lock = 0; } elsif (m{^--(clean|keep)-linkfarm$}) { $oot_clean = $1 eq 'clean'; - } elsif (m{^--(no-)?preclean-linkfarm$}) { + } elsif (m{^--(no-)?preclean-build$}) { $oot_preclean = $1 ? 'no' : 'src'; - } elsif (m{^--preclean-linkfarm=(no|src|full)$}) { + } elsif (m{^--preclean-build=(no|src|full)$}) { $oot_preclean = $1; } elsif (m{^--(no-)?nail$}) { $do_nail = !$1; @@ -1127,7 +1191,11 @@ if ($dump) { subdir => $subdir, oot_dir => $oot_dir, oot_absdir => $oot_absdir, - build_absdir => $build_absdir }); + build_absdir => $build_absdir, + linkfarm_depth => $linkfarm_depth, + oot_preclean => $oot_preclean, + force => $force,, + forced => $forced,}); ' or die $@; }