@@ -29,6 +29,32 @@ import std.string : format, lastIndexOf;
29
29
can be defined in terms of a version range.
30
30
*/
31
31
class DependencyResolver (CONFIGS , CONFIG ) {
32
+ // / Maximum number of loop rounds to do
33
+ protected ulong loop_limit;
34
+
35
+ /**
36
+ * Construct an instance of this class
37
+ *
38
+ * Params:
39
+ * limit = Maximum number of loop rounds to do
40
+ */
41
+ public this (ulong limit) inout scope @safe pure nothrow @nogc
42
+ {
43
+ this .loop_limit = limit;
44
+ }
45
+
46
+ // / Compatibility overload
47
+ deprecated (" Use the overload that accepts a `ulong limit` argument" )
48
+ public this () scope @safe
49
+ {
50
+ // Leave the possibility to opt-out from the loop limit
51
+ import std.process : environment;
52
+ if (environment.get (" DUB_NO_RESOLVE_LIMIT" ) ! is null )
53
+ this (ulong .max);
54
+ else
55
+ this (1_000_000);
56
+ }
57
+
32
58
/* * Encapsulates a list of outgoing edges in the dependency graph.
33
59
34
60
A value of this type represents a single dependency with multiple
@@ -75,17 +101,13 @@ class DependencyResolver(CONFIGS, CONFIG) {
75
101
76
102
CONFIG [string ] resolve (TreeNode root, bool throw_on_failure = true )
77
103
{
78
- // Leave the possibility to opt-out from the loop limit
79
- import std.process : environment;
80
- bool no_loop_limit = environment.get (" DUB_NO_RESOLVE_LIMIT" ) ! is null ;
81
-
82
104
auto rootbase = root.pack.basePackageName;
83
105
84
106
// build up the dependency graph, eliminating as many configurations/
85
107
// versions as possible
86
108
ResolveContext context;
87
109
context.configs[rootbase] = [ResolveConfig(root.config, true )];
88
- ulong loop_counter = no_loop_limit ? ulong .max : 1_000_000 ;
110
+ ulong loop_counter = this .loop_limit ;
89
111
constrain(root, context, loop_counter);
90
112
91
113
// remove any non-default optional dependencies
@@ -358,7 +380,7 @@ unittest {
358
380
359
381
static class TestResolver : DependencyResolver !(IntConfigs, IntConfig) {
360
382
private TreeNodes[][string ] m_children;
361
- this (TreeNodes[][string ] children) { m_children = children; }
383
+ this (TreeNodes[][string ] children) { super ( ulong .max); m_children = children; }
362
384
protected override IntConfig[] getAllConfigs (string pack) {
363
385
auto ret = appender! (IntConfig[]);
364
386
foreach (p; m_children.byKey ) {
0 commit comments