Skip to content

Commit 3c87ebd

Browse files
committed
Dub: Deprecate changing the rootPath
It's an essential part of the setup, and too many properties are derived from it that we don't want to let the library user the ability to mess with it.
1 parent b83f7d6 commit 3c87ebd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

source/dub/commandline.d

+2-3
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,7 @@ class Command {
758758
Dub dub;
759759

760760
if (options.bare) {
761-
dub = new Dub(NativePath(getcwd()));
762-
dub.rootPath = NativePath(options.root_path);
761+
dub = new Dub(NativePath(options.root_path), NativePath(getcwd()));
763762
dub.defaultPlacementLocation = options.placementLocation;
764763

765764
return dub;
@@ -2379,7 +2378,7 @@ class DustmiteCommand : PackageBuildCommand {
23792378
{
23802379
if (!m_testPackage.length)
23812380
return super.prepareDub(options);
2382-
return new Dub(NativePath(getcwd()));
2381+
return new Dub(NativePath(options.root_path), NativePath(getcwd()));
23832382
}
23842383

23852384
override int execute(Dub dub, string[] free_args, string[] app_args)

source/dub/dub.d

+20-3
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,27 @@ class Dub {
183183
loading a package.
184184
185185
This constructor corresponds to the "--bare" option of the command line
186-
interface. Use
186+
interface.
187+
188+
Params:
189+
root = The root path of the Dub instance itself.
190+
pkg_root = The root of the location where packages are located
191+
Only packages under this location will be accessible.
192+
Note that packages at the top levels will be ignored.
187193
*/
188-
this(NativePath override_path)
194+
this(NativePath root, NativePath pkg_root)
189195
{
196+
// Note: We're doing `init()` before setting the `rootPath`,
197+
// to prevent `init` from reading the project's settings.
190198
init();
191-
m_packageManager = new PackageManager(override_path);
199+
this.m_rootPath = root;
200+
m_packageManager = new PackageManager(pkg_root);
201+
}
202+
203+
deprecated("Use the overload that takes `(NativePath pkg_root, NativePath root)`")
204+
this(NativePath pkg_root)
205+
{
206+
this(pkg_root, pkg_root);
192207
}
193208

194209
private void init()
@@ -361,6 +376,8 @@ class Dub {
361376
*/
362377
@property NativePath rootPath() const { return m_rootPath; }
363378
/// ditto
379+
deprecated("Changing the root path is deprecated as it has non-obvious pitfalls " ~
380+
"(e.g. settings aren't reloaded). Instantiate a new `Dub` instead")
364381
@property void rootPath(NativePath root_path)
365382
{
366383
m_rootPath = root_path;

0 commit comments

Comments
 (0)