our $lockfile = "../.nailing-cargo-sphere.lock";
our @configs;
+our ($verbose,$noact,$dump);
sub read_or_enoent ($) {
my ($fn) = @_;
# old non-toml syntax
$toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
$toml =~ s{^}{[packages\]\n};
+ my @sd;
+ $toml =~ s{^[ \t]*\-[ \t]*\=[ \t]*(\"[-_0-9a-z]+\"\n?)$}{
+ push @sd, $1; '';
+ }mige;
+ $toml = "subdirs = [\n".(join '', map { "$_\n" } @sd)."]\n".$toml;
$transformed = 1;
}
my $e;
sub read_manifest ($) {
my ($subdir) = @_;
my $manifest = "../$subdir/Cargo.toml";
+ print STDERR "$self: reading $manifest...\n" if $verbose>=3;
if (defined $manifests{$manifest}) {
print STDERR
"$self: warning: $subdir: specified more than once!\n";
my $gotpackage = read_manifest($subdir) // '<nothing!>';
if ($gotpackage ne $p) {
print STDERR
- "$self: warning: honouring Cargo.nail [packages.$subdir]=$p even though $subdir contains package $gotpackage!\n";
+ "$self: warning: honouring Cargo.nail packages.$subdir=$p even though $subdir contains package $gotpackage!\n";
}
die if defined $packagemap{$p};
$packagemap{$p} = $subdir;
sub install () {
foreach my $mf (keys %manifests) {
my $nailing = "$mf.nailing~";
- my $nailed = "$mf.nailed~";
+ my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
my ($use, $rm);
my $diff;
if (open NN, '<', $nailed) {
}
rename $use, $mf or die "$self: install nailed $use: $!\n";
unlink $rm or $!==ENOENT or die "$self: remove old $rm: $!\n";
+ print STDERR "Nailed $mf\n" if $verbose>=2;
}
}
while (@ARGV && $ARGV[0] =~ m/^-/) {
$_ = shift @ARGV;
- last if m/^--$/;
+ last if m{^--$};
+ if (m{^-[^-]}) {
+ while (m{^-.}) {
+ if (s{^-v}{-}) {
+ $verbose++;
+ } elsif (s{^-n}{-}) {
+ $noact++;
+ } elsif (s{^-D}{-}) {
+ $dump++;
+ } else {
+ die "$self: unknown short option(s) $_\n";
+ }
+ }
+ } else {
+ die "$self: unknown long option $_\n";
+ }
}
takelock();
readnail();
readorigs();
calculate();
+
+if ($dump) {
+ eval '
+ use Data::Dumper;
+ print STDERR Dumper(\%manifests, \%packagemap);
+ ' or die $@;
+}
+
+exit 0 if $noact;
+
$want_uninstall = 1;
makebackups();
install();