Move environment read outside of DependencyResolver
Reading environment variables from random places in the code makes
the flow harder to follow, and unittesting harder.
This moves one environment reads to the `dub` module,
which performs many of them already.
1 parent 3e70d33 commit 11a8ac8aea63d71a765fbfd05e17264b6733eb39
@Geod24 Geod24 authored on 31 Jul 2022
Jan Jurzitza committed on 31 Jul 2022
Showing 2 changed files
View
34
source/dub/dependencyresolver.d
representation of both can be freely chosen, so that `CONFIGS` for example
can be defined in terms of a version range.
*/
class DependencyResolver(CONFIGS, CONFIG) {
/// Maximum number of loop rounds to do
protected ulong loop_limit;
 
/**
* Construct an instance of this class
*
* Params:
* limit = Maximum number of loop rounds to do
*/
public this (ulong limit) inout scope @safe pure nothrow @nogc
{
this.loop_limit = limit;
}
 
/// Compatibility overload
deprecated("Use the overload that accepts a `ulong limit` argument")
public this () scope @safe
{
// Leave the possibility to opt-out from the loop limit
import std.process : environment;
if (environment.get("DUB_NO_RESOLVE_LIMIT") !is null)
this(ulong.max);
else
this(1_000_000);
}
 
/** Encapsulates a list of outgoing edges in the dependency graph.
 
A value of this type represents a single dependency with multiple
possible configurations for the target package.
}
 
CONFIG[string] resolve(TreeNode root, bool throw_on_failure = true)
{
// Leave the possibility to opt-out from the loop limit
import std.process : environment;
bool no_loop_limit = environment.get("DUB_NO_RESOLVE_LIMIT") !is null;
 
auto rootbase = root.pack.basePackageName;
 
// build up the dependency graph, eliminating as many configurations/
// versions as possible
ResolveContext context;
context.configs[rootbase] = [ResolveConfig(root.config, true)];
ulong loop_counter = no_loop_limit ? ulong.max : 1_000_000;
ulong loop_counter = this.loop_limit;
constrain(root, context, loop_counter);
 
// remove any non-default optional dependencies
purgeOptionalDependencies(root, context.result);
static IntConfigs ics(IntConfig[] cfgs) { return IntConfigs(cfgs); }
 
static class TestResolver : DependencyResolver!(IntConfigs, IntConfig) {
private TreeNodes[][string] m_children;
this(TreeNodes[][string] children) { m_children = children; }
this(TreeNodes[][string] children) { super(ulong.max); m_children = children; }
protected override IntConfig[] getAllConfigs(string pack) {
auto ret = appender!(IntConfig[]);
foreach (p; m_children.byKey) {
if (p.length <= pack.length+1) continue;
View
5
source/dub/dub.d
 
 
this(Dub dub, UpgradeOptions options, Package root, SelectedVersions selected_versions)
{
if (environment.get("DUB_NO_RESOLVE_LIMIT") !is null)
super(ulong.max);
else
super(1_000_000);
 
m_dub = dub;
m_options = options;
m_rootPackage = root;
m_selectedVersions = selected_versions;