do not edit — generated by btf.
git.druid.rocksindexdruid520mpsrc/fetch.pl

src/fetch.pl


#!/usr/bin/env perl
use v5.16;
use strict;
use warnings FATAL => 'all';
use FindBin;
use lib "$FindBin::Bin";
use mplib::config qw($CFG);
use mplib::util qw(fail note ok backend slot_key);
use mplib::version qw(parse_dep_token);
use mplib::portformat qw(resolve_port write_phase_scripts resolve_slot);
use mplib::hooks qw(port_env_args);
use mplib::resolve qw(init find_portdir);
 
my $flags = mplib::config::parse_flags(\@ARGV);
mplib::config::load($flags);
fail("fetch needs a package name") unless @ARGV;
init();
 
my $tok = parse_dep_token($ARGV[0]);
my $portdir = find_portdir($tok->{name}, $tok->{slot}, $tok->{repo});
fail("port $tok->{name} not found") unless $portdir;
my $pc = resolve_port($portdir);
fail("failed reading pkg.conf for $portdir") unless $pc;
my $basename = $pc->{pkg_name};
# the real canon (not just the bare name): two statically coexisting
# slots of one pkg_name (the gcc-12/gcc-13 pattern) would otherwise share
# one fetch-cache dir, so fetching one slot falsely reports the OTHER as
# already cached.
my $canon = slot_key($basename, resolve_slot($pc, $basename));
 
# a cache-warming utility, deliberately decoupled from the normal install
# lifecycle: stages into its own fetch-cache dir rather than the real
# $CFG->{WD}/$canon stagedir, so it can never collide with
# install_pkg_body's "already staged" check. a legacy add.sh/del.sh port
# has no separate fetch phase to run at all (its one script does its own
# combined fetch+build+install) -- nothing to pre-fetch there.
unless($pc->{_phases}{fetch} && $pc->{_phases}{fetch} =~ /\S/)
{
	note("$canon has no separate fetch phase, nothing to pre-fetch");
	exit 0;
}
 
my $cachedir = "$CFG->{WD}/fetch-cache/$canon";
if(-e $cachedir)
{
	fail("$canon already has a cached fetch, remove $cachedir first");
}
system('mkdir', '-p', "$CFG->{WD}/fetch-cache") == 0 or fail("failed making $CFG->{WD}/fetch-cache");
backend('stage', $portdir, $cachedir);
write_phase_scripts($cachedir, $pc->{_phases}, ($pc->{_legacy} ? undef : $basename), 'fetch');
backend('runsh', $cachedir, 'fetch.sh', port_env_args($canon), 'MP_SANDBOX=no');
ok("$canon fetched into $cachedir");
powered by btf.