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": {
|
"dependencies": {
|
||||||
"dlangui": "~>0.7.37",
|
"dlangui": "~>0.7.37",
|
||||||
"dcd": "~>0.7.5-3"
|
"dcd": "~>0.7.4"
|
||||||
},
|
},
|
||||||
|
|
||||||
"versions": ["EmbedStandardResources"]
|
"versions": ["EmbedStandardResources"]
|
||||||
|
|
|
@ -1247,7 +1247,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshProject(Project project) {
|
void refreshProject(Project project) {
|
||||||
// TODO
|
if (currentWorkspace && project.loadSelections()) {
|
||||||
|
currentWorkspace.cleanupUnusedDependencies();
|
||||||
|
refreshWorkspace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildProject(BuildOperation buildOp, Project project, BuildResultListener listener = null) {
|
void buildProject(BuildOperation buildOp, Project project, BuildResultListener listener = null) {
|
||||||
|
|
|
@ -642,37 +642,53 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
protected Project[] _dependencies;
|
protected Project[] _dependencies;
|
||||||
@property Project[] dependencies() { return _dependencies; }
|
@property Project[] dependencies() { return _dependencies; }
|
||||||
protected bool addDependency(Project dep) {
|
|
||||||
if (_workspace)
|
Project findDependencyProject(string filename) {
|
||||||
_workspace.addDependencyProject(dep);
|
foreach(dep; _dependencies) {
|
||||||
_dependencies ~= dep;
|
if (dep.filename.equal(filename))
|
||||||
return true;
|
return dep;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadSelections() {
|
bool loadSelections() {
|
||||||
|
Project[] newdeps;
|
||||||
_dependencies.length = 0;
|
_dependencies.length = 0;
|
||||||
DubPackageFinder finder = new DubPackageFinder();
|
DubPackageFinder finder = new DubPackageFinder();
|
||||||
scope(exit) destroy(finder);
|
scope(exit) destroy(finder);
|
||||||
SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json"));
|
SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json"));
|
||||||
if (!selectionsFile.load())
|
if (!selectionsFile.load()) {
|
||||||
|
_dependencies = newdeps;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
Setting versions = selectionsFile.objectByPath("versions");
|
Setting versions = selectionsFile.objectByPath("versions");
|
||||||
if (!versions.isObject)
|
if (!versions.isObject) {
|
||||||
|
_dependencies = newdeps;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
string[string] versionMap = versions.strMap;
|
string[string] versionMap = versions.strMap;
|
||||||
foreach(packageName, packageVersion; versionMap) {
|
foreach(packageName, packageVersion; versionMap) {
|
||||||
string fn = finder.findPackage(packageName, packageVersion);
|
string fn = finder.findPackage(packageName, packageVersion);
|
||||||
Log.d("dependency ", packageName, " ", packageVersion, " : ", fn ? fn : "NOT FOUND");
|
Log.d("dependency ", packageName, " ", packageVersion, " : ", fn ? fn : "NOT FOUND");
|
||||||
if (fn) {
|
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()) {
|
if (p.load()) {
|
||||||
addDependency(p);
|
newdeps ~= p;
|
||||||
|
if (_workspace)
|
||||||
|
_workspace.addDependencyProject(p);
|
||||||
} else {
|
} else {
|
||||||
Log.e("cannot load dependency package ", packageName, " ", packageVersion, " from file ", fn);
|
Log.e("cannot load dependency package ", packageName, " ", packageVersion, " from file ", fn);
|
||||||
destroy(p);
|
destroy(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_dependencies = newdeps;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,31 @@ class Workspace : WorkspaceItem {
|
||||||
fillStartupProject();
|
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) {
|
bool addDependencyProject(Project p) {
|
||||||
for (int i = 0; i < _projects.length; i++) {
|
for (int i = 0; i < _projects.length; i++) {
|
||||||
if (_projects[i].filename.equal(p.filename)) {
|
if (_projects[i].filename.equal(p.filename)) {
|
||||||
|
|
Loading…
Reference in New Issue