Skip to content

Commit a300f61

Browse files
committed
Dependency: Deprecate path/repository setters
There is no real use case for changing a dependency in place, instead we better let the user overwrite the dependency itself.
1 parent d561419 commit a300f61

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

source/dub/commandline.d

+7-4
Original file line numberDiff line numberDiff line change
@@ -2427,10 +2427,13 @@ class DustmiteCommand : PackageBuildCommand {
24272427
}
24282428

24292429
static void fixPathDependency(string pack, ref Dependency dep) {
2430-
if (!dep.path.empty) {
2431-
auto mainpack = getBasePackageName(pack);
2432-
dep.path = NativePath("../") ~ mainpack;
2433-
}
2430+
dep.visit!(
2431+
(NativePath path) {
2432+
auto mainpack = getBasePackageName(pack);
2433+
dep = Dependency(NativePath("../") ~ mainpack);
2434+
},
2435+
(any) { /* Nothing to do */ },
2436+
);
24342437
}
24352438

24362439
void fixPathDependencies(ref PackageRecipe recipe, NativePath base_path)

source/dub/dependency.d

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct Dependency {
112112
}
113113

114114
/// If set, overrides any version based dependency selection.
115+
deprecated("Construct a new `Dependency` object instead")
115116
@property void path(NativePath value) @trusted
116117
{
117118
this.m_value = value;
@@ -126,6 +127,7 @@ struct Dependency {
126127
}
127128

128129
/// If set, overrides any version based dependency selection.
130+
deprecated("Construct a new `Dependency` object instead")
129131
@property void repository(Repository value) @trusted
130132
{
131133
this.m_value = value;
@@ -323,8 +325,7 @@ struct Dependency {
323325
if (auto pv = "version" in verspec)
324326
logDiagnostic("Ignoring version specification (%s) for path based dependency %s", pv.get!string, pp.get!string);
325327

326-
dep = Dependency.any;
327-
dep.path = NativePath(verspec["path"].get!string);
328+
dep = Dependency(NativePath(verspec["path"].get!string));
328329
} else if (auto repository = "repository" in verspec) {
329330
enforce("version" in verspec, "No version field specified!");
330331
enforce(repository.length > 0, "No repository field specified!");
@@ -357,10 +358,9 @@ struct Dependency {
357358
"path": "path/to/package"
358359
}
359360
`));
360-
Dependency d = Dependency.any; // supposed to ignore the version spec
361+
Dependency d = NativePath("path/to/package"); // supposed to ignore the version spec
361362
d.optional = true;
362363
d.default_ = true;
363-
d.path = NativePath("path/to/package");
364364
assert(d == parsed);
365365
// optional and path not checked by opEquals.
366366
assert(d.optional == parsed.optional);

0 commit comments

Comments
 (0)