From: Ian Jackson Date: Sun, 10 May 2020 10:43:42 +0000 (+0100) Subject: nailing-cargo: wip Cargo.lock manipulation X-Git-Tag: nailing-cargo/1.0.0~218 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8d1fc21c23a35376fe3845f0efa8dd717b5a56da;p=nailing-cargo.git nailing-cargo: wip Cargo.lock manipulation Signed-off-by: Ian Jackson --- diff --git a/nailing-cargo b/nailing-cargo index 32da8fc..eecf01c 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -67,8 +67,11 @@ use File::Compare; use TOML::Tiny::Faithful; our $worksphere = getcwd() // die "$self: getcwd failed: $!\n"; -$worksphere =~ s{/[^/]+$}{} or die "$self: cwd \`$worksphere' unsupported!\n"; +$worksphere =~ s{/([^/]+)$}{} + or die "$self: cwd \`$worksphere' unsupported!\n"; +our $subdir = $1; our $lockfile = "../.nailing-cargo.lock"; +our $oot_cargo_lock_faff; our @configs; our $verbose=1; @@ -249,6 +252,73 @@ sub calculate () { close N or die "$self: close new $nailing: $!\n"; } } +s +our $oot_dir; +our @out_command; + +sub calculate_oot () { + my $oot = $nail->{oot}; + return unless $oot && (defined $oot->{dir} or defined $oot->{use}); + if (@ARGV && $ARGV[0] =~ m/generate-lockfile|update/) { + $oot_cargo_lock_faff = 1; + } + my ($pre,$post); + my @xargs; + if (!$oot_cargo_lock_faff) { + @xargs = $xxx_subdir; + ($pre, $post) = ('cd "$1"; shift', ''); + } else { + @xargs = $xxx_builddir, $xxx_subdir, $xxx_src_abs_dir; + ($pre, $post) = (<<'END', <<'END'); + cd "$1"; shift; + mkdir -p -- "$1"; cd "$1"; shift; + cp -- "$1"/Cargo.toml "$1"/Cargo.lock .; shift; + mkdir -p src; >src/lib.rs; +END + rm -r src Cargo.toml; +END + $pre =~ s/^\s+//mg; $pre =~ s/^\s+\n/ /g; + $post =~ s/^\s+//mg; $post =~ s/^\s+\n/ /g; + } + my $use = $oot->{use} // die "$self: [oot] specified, need oot.use\n"; + my $getuser = sub { + scalar($oot->{user} // die "$self: oot.use $use requires oot.user\n") + }; + my @command; + my $sh_ec = sub { + if (!length $post) { + @command = @_, 'sh','-ec',$pre.' exec "$@"','--',@xargs; + } else { + @command = @_, 'sh','-ec',$pre.' "$@"; '.$post,'--',@xargs; + } + }; + my $command_sh = sub { + my $quoted = join ' ', map { + return $_ if !m/\W/; + s/\'/\'\\'\'/g; + "'$_'" + } @ARGV; + @command = @_, "set -e; $pre $quoted; $post"; + }; + if ($use eq 'really') { + my $user = $getuser->(); + my @pw = getpwnam $user or "die $self: oot.user lookup failed\n"; + my $homedir = $pw[7]; + $sh_ec->('really','-u',$user,'env',"HOME=$homedir"); + } elsif ($use eq 'ssh') { + my $user = $getuser->(); + $user .= '@localhost' unless $user =~ m/\@/; + $command_sh->('ssh',$user); + } elsif ($use eq 'command_sh') { + $command_sh->(@{ $oot->{command} // die "$self: need oot.command\n" }); + } elsif ($use eq 'command_args') { + $sh_ec->(@{ $oot->{command} // die "$self: need oot.command\n" }); + } else { + die "$self: oot.use mode $use not recognised\n"; + } + die unless @command; + @ARGV = @command; +} our $want_uninstall; @@ -344,6 +414,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { $noact++; } elsif (s{^-D}{-}) { $dump++; + } elsif (s{^-L}{-}) { + $oot_cargo_lock_faff=1; } else { die "$self: unknown short option(s) $_\n"; } @@ -359,11 +431,12 @@ takelock(); readnail(); readorigs(); calculate(); +calculate_oot(); if ($dump) { eval ' use Data::Dumper; - print STDERR Dumper(\%manifests, \%packagemap); + print STDERR Dumper(\%manifests, \%packagemap, \@ARGV); ' or die $@; } @@ -381,6 +454,9 @@ my $estatus = invoke(); uninstall(); $want_uninstall = 1; -print STDERR "$self: unnailed.\n" if $verbose; + +get_cargo_lock() if $oot_cargo_lock_faff; + +print STDERR "$self: unnailed. status $estatus.\n" if $verbose; exit $estatus;