#
# The arguments are
# --manifest-path=<path/to/Cargo.toml>
-# --locked --target-dir=target
+# --locked
+# --target-dir=target
+#
+# -T | --no-cargo-target-arg
+# -t | --cargo-target-arg
+# Suppress --target (or un-suppress it). Only useful with -m.
+# Done automatically when nailing-cargo sees that the cargo
+# subcommand is one which needs it, eg `fetch'.
+#
+# --online | -o
+# --offline | -O
+# Whether to allow cargo to make network access.
+# (nailing-cargo always passes --offline to cargo, unless
+# --online is in force). The default is offline,
+# unless the cargo subcommand is one which implies
+# online (currently, `fetch').
#
# Cargo.nail:
#
# <package> = <subdir>
# <package> = { <subdir> = ... }
#
-# To control use of alternative Cargo.lock filename:
+# Configuration is read from
+#
+# /etc/nailing-cargo/cfg.toml
+# ~/.nailing-cargo.toml
+# ./.nailing-cargo.toml
+# ../Nailing-Cargo.toml
+# ../Cargo.nail
+#
+# To control use of alternative Cargo.lock filename:
# [alt_cargolock]
#
# file = true # equivalent to "Cargo.lock.example"
# or
# use = "null"
#
+# Other settings:
+# [misc]
+# online = true # forces default to be --online
+# online = false # forces default to be --offline
+#
# Limitations:
#
# Always dirties everyone's Cargo.toml, but tries to put them
our $cargo_lock_update;
our $cargo_manifest_args;
+our $cargo_target_arg=1;
our $alt_cargo_lock;
+our $online;
our @configs;
our $verbose=1;
sub toml_or_enoent ($$) {
my ($f,$what) = @_;
my $toml = read_or_enoent($f) // return;
+ print STDERR "Read TOML from $f\n" if $dump;
my ($v,$e) = from_toml($toml);
if (!defined $v) {
chomp $e;
}
sub loadconfigs () {
- my $cfgleaf = ".nailing-cargo-cfg.toml";
+ my $dotfile = ".nailing-cargo.toml";
+ load1config("../Nailing-Cargo.toml");
+ load1config($dotfile);
+ load1config("$ENV{HOME}/$dotfile") if defined $ENV{HOME};
load1config("/etc/nailing-cargo/cfg.toml");
- load1config("$worksphere/$cfgleaf");
- load1config("$ENV{HOME}/$cfgleaf") if defined $ENV{HOME};
-}
-
-sub getcfg ($$) {
- my ($k, $def) = @_;
- foreach my $cfg (@configs) {
- my $v = $cfg->{$k};
- return $v if defined $v;
- }
- return $def;
}
sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
}
sub cfg_uc {
- my $v = $nail;
- foreach my $k (@_) {
- last unless defined $v;
- ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
- $v = $v->{$k};
+ foreach my $cfg (@configs) {
+ my $v = $cfg;
+ foreach my $k (@_) {
+ last unless defined $v;
+ ref($v) eq 'HASH' or badcfg @_, "parent key \`$k' is not a hash";
+ $v = $v->{$k};
+ }
+ return $v if defined $v;
}
- return $v;
+ return undef;
}
sub cfge {
$nail->{subdirs}
];
}
+
+ unshift @configs, $nail;
}
our @alt_cargo_lock_stat;
}
sub addargs () {
+ $online //= cfg_bool qw(misc online);
+
if (@ARGV>=2 &&
- $ARGV[0] =~ m{\bcargo\b} &&
- $ARGV[1] =~ m/^(?:generate-lockfile|update)$/) {
- $cargo_lock_update //= 1;
- $target = undef;
- } else {
- $cargo_lock_update //= 0;
+ $ARGV[0] =~ m{\bcargo\b}) {
+ if ($ARGV[1] =~ m/^(?:generate-lockfile|update)$/) {
+ $cargo_lock_update //= 1;
+ $target = undef;
+ }
+ if ($ARGV[1] =~ m/^(?:fetch)$/) {
+ $cargo_target_arg=0;
+ $online //= 1;
+ }
}
+ $cargo_lock_update //= 0;
$cargo_manifest_args //=
(defined $oot_dir) && !$cargo_lock_update;
+ $online //= 0;
+
if ($cargo_manifest_args) {
push @ARGV, "--manifest-path=${src_absdir}/Cargo.toml",
- qw(--locked --target-dir=target);
+ qw(--locked);
+ push @ARGV, qw(--target-dir=target) if $cargo_target_arg;
}
if (defined $target) {
}
push @ARGV, "--target=$target";
}
+
+ push @ARGV, "--offline" unless $online;
}
our $oot_absdir;
}
sub install () {
+ my @our_unfound_stab = stat_exists('Cargo.toml', 'local Cargo.toml')
+ ? (stat _) : ();
foreach my $mf (keys %manifests) {
+ if (@our_unfound_stab) {
+ if (stat_exists $mf, "manifest in to-be-nailed directory") {
+ my @mf_stab = stat _ ;
+ if ("@mf_stab[0..1]" eq "@our_unfound_stab[0..1]") {
+ @our_unfound_stab = ();
+ }
+ }
+ }
+
my $nailing = "$mf.nailing~";
my $nailed = nailed($mf);
my ($use, $rm);
unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
print STDERR "$self: nailed $mf\n" if $verbose>=3;
}
+
+ if (@our_unfound_stab) {
+ print STDERR
+ "$self: *WARNING* cwd is not in Cargo.nail thbough it has Cargo.toml!\n";
+ }
}
sub invoke () {
$cargo_lock_update= $1=~m/[a-z]/;
} elsif (s{^-([mM])}{-}) {
$cargo_manifest_args= $1=~m/[a-z]/;
+ } elsif (s{^-([tT])}{-}) {
+ $cargo_target_arg= $1=~m/[a-z]/;
+ } elsif (s{^-([oO])}{-}) {
+ $online= $1=~m/[a-z]/;
} else {
die "$self: unknown short option(s) $_\n";
}
$cargo_lock_update= !!$1;
} elsif (m{^--(no-)?cargo-manifest-args}) {
$cargo_manifest_args= !!$1;
+ } elsif (m{^--(no-)?cargo-target-arg}) {
+ $cargo_target_arg= !!$1;
+ } elsif (m{^--(on|off)line$}) {
+ $online = $1 eq 'on';
} else {
die "$self: unknown long option $_\n";
}
die "$self: need command to run\n" unless @ARGV || $noact;
+loadconfigs();
takelock();
readnail();
consider_alt_cargo_lock();