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

src/use.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 set_pkgconf);
use mplib::util qw(fail ok confirm bare_name);
use mplib::version qw(parse_dep_token);
use mplib::portformat qw(parse_pkg_use enabled_use USE_NONE);
use mplib::resolve qw(init find_portdir pkgconf);
 
my $flags = mplib::config::parse_flags(\@ARGV);
mplib::config::load($flags);
fail("use needs a package name") unless @ARGV;
init();
 
# a "name:slot" argument only disambiguates WHICH port directory to read
# pkg_use from (two raw slots of one pkg_name can declare different USE
# flags) -- $canon itself stays the bare name, since USE= is always
# persisted/read under the bare name regardless of raw slot (see below).
my $tok = parse_dep_token(shift @ARGV);
my $canon = bare_name($tok->{name});
my $portdir = find_portdir($canon, $tok->{slot}, $tok->{repo});
fail("port $canon not found") unless $portdir;
my $pc = pkgconf($portdir);
my $declared = parse_pkg_use($pc->{pkg_use});
 
# no +flag/-flag args: read-only listing of every USE flag this port
# declares, its current state (same "*" convention info.pl uses), whether
# it's build-only, and its deps -- everything pkg_use itself carries.
unless(@ARGV)
{
	fail("$canon declares no USE flags") unless %$declared;
	my $en = enabled_use($canon, $declared);
	for my $flag (sort keys %$declared)
	{
		my $mark = $en->{$flag} ? '*' : ' ';
		my $kind = $declared->{$flag}{build} ? ' (build-only)' : '';
		my @deps = @{$declared->{$flag}{deps}};
		my $depstr = @deps ? " -> " . join(',', @deps) : '';
		print "$mark$flag$kind$depstr\n";
	}
	exit 0;
}
 
# +flag/-flag: toggle relative to whatever is CURRENTLY effectively
# enabled (enabled_use already merges the mp-managed overlay/mp.conf/
# global default), then persist the resulting full set under this port's
# bare name -- the only key resolve_slot's own pkg_slot_use composition
# can read before a USE-driven slot exists (see mplib::portformat).
my %en = %{enabled_use($canon, $declared)};
for my $tok (@ARGV)
{
	if($tok =~ /^\+(.+)$/)    { $en{$1} = 1; }
	elsif($tok =~ /^-(.+)$/)  { delete $en{$1}; }
	else                      { fail("use flags must be +flag or -flag, got: $tok"); }
}
my $result = join(' ', sort keys %en);
# USE_NONE (not undef) for the empty case, always -- set_pkgconf treats an
# empty value as "no override, fall back to the default" same as every
# other config key, which for a port with at least one "+flag" default-on
# would silently UNDO exactly the "-lastflag" toggle that just ran.
confirm("use: $canon -> " . ($result eq '' ? '(none)' : $result) . " -- continue?");
set_pkgconf($canon, 'USE', $result eq '' ? USE_NONE : $result);
ok("$canon USE set to: " . ($result eq '' ? '(none)' : $result));
powered by btf.