mirror of https://github.com/buggins/dlangide.git
subpackages support - when specified as paths to subpackage dirs - for #171; todo: subpackages as part of main package file
This commit is contained in:
parent
e8d21b5673
commit
0a8f4decc8
2
dub.json
2
dub.json
|
@ -12,7 +12,7 @@
|
||||||
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"],
|
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"],
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dlangui": "==0.9.30",
|
"dlangui": "==0.9.32",
|
||||||
"dcd": "~>0.9.0-alpha4"
|
"dcd": "~>0.9.0-alpha4"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,7 @@ class WorkspaceItem {
|
||||||
protected string _filename;
|
protected string _filename;
|
||||||
protected string _dir;
|
protected string _dir;
|
||||||
protected dstring _name;
|
protected dstring _name;
|
||||||
|
protected dstring _originalName;
|
||||||
protected dstring _description;
|
protected dstring _description;
|
||||||
|
|
||||||
this(string fname = null) {
|
this(string fname = null) {
|
||||||
|
@ -357,6 +358,8 @@ class Project : WorkspaceItem {
|
||||||
protected SettingsFile _projectFile;
|
protected SettingsFile _projectFile;
|
||||||
protected ProjectSettings _settingsFile;
|
protected ProjectSettings _settingsFile;
|
||||||
protected bool _isDependency;
|
protected bool _isDependency;
|
||||||
|
protected bool _isSubproject;
|
||||||
|
protected dstring _baseProjectName;
|
||||||
protected string _dependencyVersion;
|
protected string _dependencyVersion;
|
||||||
|
|
||||||
protected string[] _sourcePaths;
|
protected string[] _sourcePaths;
|
||||||
|
@ -372,6 +375,17 @@ class Project : WorkspaceItem {
|
||||||
_projectFile = new SettingsFile(fname);
|
_projectFile = new SettingsFile(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBaseProject(Project p) {
|
||||||
|
if (p) {
|
||||||
|
_isSubproject = true;
|
||||||
|
_isDependency = p._isDependency;
|
||||||
|
_baseProjectName = p._originalName;
|
||||||
|
_dependencyVersion = p._dependencyVersion;
|
||||||
|
} else {
|
||||||
|
_isSubproject = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@property ProjectSettings settings() {
|
@property ProjectSettings settings() {
|
||||||
if (!_settingsFile) {
|
if (!_settingsFile) {
|
||||||
_settingsFile = new ProjectSettings(settingsFileName);
|
_settingsFile = new ProjectSettings(settingsFileName);
|
||||||
|
@ -580,7 +594,9 @@ class Project : WorkspaceItem {
|
||||||
return findSourceFileItem(_items, filename, fullFileName);
|
return findSourceFileItem(_items, filename, fullFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Project[] _subPackages;
|
||||||
override bool load(string fname = null) {
|
override bool load(string fname = null) {
|
||||||
|
import dlangui.core.files;
|
||||||
if (!_projectFile)
|
if (!_projectFile)
|
||||||
_projectFile = new SettingsFile();
|
_projectFile = new SettingsFile();
|
||||||
_mainSourceFile = null;
|
_mainSourceFile = null;
|
||||||
|
@ -594,6 +610,10 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_name = toUTF32(_projectFile.getString("name"));
|
_name = toUTF32(_projectFile.getString("name"));
|
||||||
|
_originalName = _name;
|
||||||
|
if (_baseProjectName) {
|
||||||
|
_name = _baseProjectName ~ ":" ~ _name;
|
||||||
|
}
|
||||||
if (_isDependency) {
|
if (_isDependency) {
|
||||||
_name ~= "-"d;
|
_name ~= "-"d;
|
||||||
_name ~= toUTF32(_dependencyVersion.startsWith("~") ? _dependencyVersion[1..$] : _dependencyVersion);
|
_name ~= toUTF32(_dependencyVersion.startsWith("~") ? _dependencyVersion[1..$] : _dependencyVersion);
|
||||||
|
@ -612,6 +632,37 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
_configurations = ProjectConfiguration.load(_projectFile);
|
_configurations = ProjectConfiguration.load(_projectFile);
|
||||||
Log.i("Project configurations: ", _configurations);
|
Log.i("Project configurations: ", _configurations);
|
||||||
|
|
||||||
|
_subPackages.length = 0;
|
||||||
|
Setting subPackages = _projectFile.settingByPath("subPackages", SettingType.ARRAY, false);
|
||||||
|
if (subPackages) {
|
||||||
|
string p = _projectFile.filename.dirName;
|
||||||
|
for(int i = 0; i < subPackages.length; i++) {
|
||||||
|
Setting sp = subPackages[i];
|
||||||
|
if (sp.isString) {
|
||||||
|
// string
|
||||||
|
string path = convertPathDelimiters(sp.str);
|
||||||
|
string relative = relativePath(path, p);
|
||||||
|
path = buildNormalizedPath(absolutePath(relative, p));
|
||||||
|
//Log.d("Subproject path: ", path);
|
||||||
|
string fn = DubPackageFinder.findPackageFile(path);
|
||||||
|
//Log.d("Subproject file: ", fn);
|
||||||
|
Project prj = new Project(_workspace, fn);
|
||||||
|
prj.setBaseProject(this);
|
||||||
|
if (prj.load()) {
|
||||||
|
Log.d("Loaded subpackage from file: ", fn);
|
||||||
|
_subPackages ~= prj;
|
||||||
|
if (_workspace)
|
||||||
|
_workspace.addDependencyProject(prj);
|
||||||
|
} else {
|
||||||
|
Log.w("Failed to load subpackage from file: ", fn);
|
||||||
|
}
|
||||||
|
} else if (sp.isObject) {
|
||||||
|
// object - file inside base project dub.json
|
||||||
|
Log.d("Subpackage is JSON object; TODO");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("Cannot read project file", e);
|
Log.e("Cannot read project file", e);
|
||||||
|
@ -699,22 +750,27 @@ class DubPackageFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// find package file (dub.json, package.json) in specified dir; returns absoulute path to found file or null if not found
|
||||||
|
static string findPackageFile(string pathName) {
|
||||||
|
string fn = buildNormalizedPath(pathName, "dub.json");
|
||||||
|
if (fn.exists && fn.isFile)
|
||||||
|
return fn;
|
||||||
|
fn = buildNormalizedPath(pathName, "package.json");
|
||||||
|
if (fn.exists && fn.isFile)
|
||||||
|
return fn;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected string findPackage(string packageDir, string packageName, string packageVersion) {
|
protected string findPackage(string packageDir, string packageName, string packageVersion) {
|
||||||
string fullName = packageVersion.startsWith("~") ? packageName ~ "-" ~ packageVersion[1..$] : packageName ~ "-" ~ packageVersion;
|
string fullName = packageVersion.startsWith("~") ? packageName ~ "-" ~ packageVersion[1..$] : packageName ~ "-" ~ packageVersion;
|
||||||
string pathName = absolutePath(buildNormalizedPath(packageDir, fullName));
|
string pathName = absolutePath(buildNormalizedPath(packageDir, fullName));
|
||||||
if (pathName.exists && pathName.isDir) {
|
if (pathName.exists && pathName.isDir) {
|
||||||
string fn = buildNormalizedPath(pathName, "dub.json");
|
string fn = findPackageFile(pathName);
|
||||||
if (fn.exists && fn.isFile)
|
if (fn)
|
||||||
return fn;
|
|
||||||
fn = buildNormalizedPath(pathName, "package.json");
|
|
||||||
if (fn.exists && fn.isFile)
|
|
||||||
return fn;
|
return fn;
|
||||||
// new DUB support - with package subdirectory
|
// new DUB support - with package subdirectory
|
||||||
fn = buildNormalizedPath(pathName, packageName, "dub.json");
|
fn = findPackageFile(buildNormalizedPath(pathName, packageName));
|
||||||
if (fn.exists && fn.isFile)
|
if (fn)
|
||||||
return fn;
|
|
||||||
fn = buildNormalizedPath(pathName, packageName, "package.json");
|
|
||||||
if (fn.exists && fn.isFile)
|
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue