mirror of https://github.com/buggins/dlangide.git
close #92 - refresh project dependencies after build
This commit is contained in:
parent
52592b3bc4
commit
94c2ad0ca8
2
dub.json
2
dub.json
|
@ -13,7 +13,7 @@
|
|||
|
||||
"dependencies": {
|
||||
"dlangui": "~>0.7.37",
|
||||
"dcd": "~>0.7.5-3"
|
||||
"dcd": "~>0.7.4"
|
||||
},
|
||||
|
||||
"versions": ["EmbedStandardResources"]
|
||||
|
|
|
@ -1247,7 +1247,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
}
|
||||
|
||||
void refreshProject(Project project) {
|
||||
// TODO
|
||||
if (currentWorkspace && project.loadSelections()) {
|
||||
currentWorkspace.cleanupUnusedDependencies();
|
||||
refreshWorkspace();
|
||||
}
|
||||
}
|
||||
|
||||
void buildProject(BuildOperation buildOp, Project project, BuildResultListener listener = null) {
|
||||
|
|
|
@ -642,37 +642,53 @@ class Project : WorkspaceItem {
|
|||
|
||||
protected Project[] _dependencies;
|
||||
@property Project[] dependencies() { return _dependencies; }
|
||||
protected bool addDependency(Project dep) {
|
||||
if (_workspace)
|
||||
_workspace.addDependencyProject(dep);
|
||||
_dependencies ~= dep;
|
||||
return true;
|
||||
|
||||
Project findDependencyProject(string filename) {
|
||||
foreach(dep; _dependencies) {
|
||||
if (dep.filename.equal(filename))
|
||||
return dep;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool loadSelections() {
|
||||
Project[] newdeps;
|
||||
_dependencies.length = 0;
|
||||
DubPackageFinder finder = new DubPackageFinder();
|
||||
scope(exit) destroy(finder);
|
||||
SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json"));
|
||||
if (!selectionsFile.load())
|
||||
if (!selectionsFile.load()) {
|
||||
_dependencies = newdeps;
|
||||
return false;
|
||||
}
|
||||
Setting versions = selectionsFile.objectByPath("versions");
|
||||
if (!versions.isObject)
|
||||
if (!versions.isObject) {
|
||||
_dependencies = newdeps;
|
||||
return false;
|
||||
}
|
||||
string[string] versionMap = versions.strMap;
|
||||
foreach(packageName, packageVersion; versionMap) {
|
||||
string fn = finder.findPackage(packageName, packageVersion);
|
||||
Log.d("dependency ", packageName, " ", packageVersion, " : ", fn ? fn : "NOT FOUND");
|
||||
if (fn) {
|
||||
Project p = new Project(_workspace, fn, packageVersion);
|
||||
Project p = findDependencyProject(fn);
|
||||
if (p) {
|
||||
Log.d("Found existing dependency project ", fn);
|
||||
newdeps ~= p;
|
||||
continue;
|
||||
}
|
||||
p = new Project(_workspace, fn, packageVersion);
|
||||
if (p.load()) {
|
||||
addDependency(p);
|
||||
newdeps ~= p;
|
||||
if (_workspace)
|
||||
_workspace.addDependencyProject(p);
|
||||
} else {
|
||||
Log.e("cannot load dependency package ", packageName, " ", packageVersion, " from file ", fn);
|
||||
destroy(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
_dependencies = newdeps;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,6 +194,31 @@ class Workspace : WorkspaceItem {
|
|||
fillStartupProject();
|
||||
}
|
||||
|
||||
Project removeProject(int index) {
|
||||
if (index < 0 || index > _projects.length)
|
||||
return null;
|
||||
Project res = _projects[index];
|
||||
for (int j = index; j + 1 < _projects.length; j++)
|
||||
_projects[j] = _projects[j + 1];
|
||||
return res;
|
||||
}
|
||||
|
||||
bool isDependencyProjectUsed(string filename) {
|
||||
foreach(p; _projects)
|
||||
if (!p.isDependency && p.findDependencyProject(filename))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void cleanupUnusedDependencies() {
|
||||
for (int i = cast(int)_projects.length - 1; i >= 0; i--) {
|
||||
if (_projects[i].isDependency) {
|
||||
if (!isDependencyProjectUsed(_projects[i].filename))
|
||||
removeProject(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool addDependencyProject(Project p) {
|
||||
for (int i = 0; i < _projects.length; i++) {
|
||||
if (_projects[i].filename.equal(p.filename)) {
|
||||
|
|
Loading…
Reference in New Issue