Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Fixed reloading dub json by restarting dub (hax)
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Jan 4, 2016
1 parent c7ec387 commit 326622b
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions source/com/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public:
setStringImportPathProvider(this);

_dub = new Dub(null, value.dir, SkipRegistry.none);
_dub.packageManager.getOrLoadPackage(Path(value.dir));
_cwdStr = value.dir;
_cwd = Path(value.dir);
_dub.packageManager.getOrLoadPackage(_cwd);
_dub.loadPackageFromCwd();
_dub.project.validate();
string compilerName = defaultCompiler;
Expand All @@ -72,10 +74,10 @@ public:
}
}

bool updateImportPaths()
bool updateImportPaths(bool restartDub = true)
{
_dub.loadPackageFromCwd();
_dub.project.validate();
if(restartDub)
restart();

ProjectDescription desc = dub.project.describe(_platform, _configuration, _buildType);
if (desc.targets.length > 0 && desc.targetLookup.length > 0 && (desc.rootPackage in desc.targetLookup) !is null)
Expand All @@ -97,6 +99,16 @@ public:
{
_dub.shutdown();
}

void restart()
{
_dub.shutdown();

_dub = new Dub(null, _cwdStr, SkipRegistry.none);
_dub.packageManager.getOrLoadPackage(_cwd);
_dub.loadPackageFromCwd();
_dub.project.validate();
}

@property auto dependencies()
{
Expand Down Expand Up @@ -138,7 +150,7 @@ public:
if (!dub.project.configurations.canFind(value))
return false;
_configuration = value;
return updateImportPaths();
return updateImportPaths(false);
}

@property auto buildType()
Expand All @@ -151,7 +163,7 @@ public:
try
{
_buildType = value;
return updateImportPaths();
return updateImportPaths(false);
}
catch (Exception e)
{
Expand Down Expand Up @@ -228,9 +240,11 @@ private:
}

Dub _dub;
Path _cwd;
WatchedFile _dubFileWatch;
string _configuration;
string _buildType = "debug";
string _cwdStr;
BuildSettings _settings;
Compiler _compiler;
BuildPlatform _platform;
Expand Down

0 comments on commit 326622b

Please sign in to comment.