diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index f879e1a..2e96292 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -191,6 +191,8 @@ string[] debugVersions; string[] importPaths; string[] stringImportPaths; + string[] importFiles; + string[] stringImportFiles; string[] preGenerateCommands; string[] postGenerateCommands; string[] preBuildCommands; @@ -209,6 +211,9 @@ void addDebugVersions(in string[] value...) { add(debugVersions, value); } void addImportPaths(in string[] value...) { add(importPaths, value); } void addStringImportPaths(in string[] value...) { add(stringImportPaths, value); } + void addImportFiles(in string[] value...) { add(importFiles, value); } + void removeImportFiles(in string[] value...) { removePaths(importFiles, value); } + void addStringImportFiles(in string[] value...) { add(stringImportFiles, value); } void addPreGenerateCommands(in string[] value...) { add(preGenerateCommands, value, false); } void addPostGenerateCommands(in string[] value...) { add(postGenerateCommands, value, false); } void addPreBuildCommands(in string[] value...) { add(preBuildCommands, value, false); } diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index c2ec4f6..0ab6395 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -202,12 +202,23 @@ auto files = pack.getBuildSettings(settings.platform, configs[pack.name]); bool[SourceFile] sourceFiles; if (m_combinedProject) { - bool[const(Package)] basePackagesAdded; // add all package.json files to the project // and all source files performOnDependencies(pack, configs, (prj) { + void addFile(string s, bool build) { + auto sp = Path(s); + if( !sp.absolute ) sp = prj.path ~ sp; + SourceFile sf; + sf.pkg = pack.name; + sf.filePath = sp.relativeTo(project_file_dir); + sf.build = build; + + // regroup in Folder by base package + sf.structurePath = Path(prj.basePackage().name) ~ sp.relativeTo(prj.path); + sourceFiles[sf] = true; + } string[] prjFiles; @@ -217,40 +228,36 @@ { const(Package) base = prj.basePackage(); - if (base !in basePackagesAdded) - { + if (base !in basePackagesAdded) { prjFiles ~= prj.packageInfoFile.toNativeString(); basePackagesAdded[base] = true; } } - prjFiles = prjFiles ~ prj.getBuildSettings(settings.platform, configs[prj.name]).sourceFiles; - - foreach(s; prjFiles){ - auto sp = Path(s); - if( !sp.absolute ) sp = prj.path ~ sp; - SourceFile sf; - sf.pkg = pack.name; - sf.filePath = sp.relativeTo(project_file_dir); - - // regroup in Folder by base package - sf.structurePath = Path(prj.basePackage().name) ~ sp.relativeTo(prj.path); - sourceFiles[sf] = true; - } + auto settings = prj.getBuildSettings(settings.platform, configs[prj.name]); + foreach (f; prjFiles) addFile(f, false); + foreach (f; settings.sourceFiles) addFile(f, true); + foreach (f; settings.importFiles) addFile(f, false); + foreach (f; settings.stringImportFiles) addFile(f, false); }); } files.sourceFiles ~= pack.packageInfoFile.toNativeString(); - foreach(s; files.sourceFiles){ + void addFile(string s, bool build) { auto sp = Path(s); if( !sp.absolute ) sp = pack.path ~ sp; SourceFile sf; sf.pkg = pack.name; sf.filePath = sp.relativeTo(project_file_dir); sf.structurePath = sp.relativeTo(pack.path); + sf.build = build; sourceFiles[sf] = true; } + addFile(pack.packageInfoFile.toNativeString(), false); + foreach(s; files.sourceFiles) addFile(s, true); + foreach(s; files.importFiles) addFile(s, false); + foreach(s; files.stringImportFiles) addFile(s, false); // Create folders and files ret.formattedWrite(" ", getPackageFileName(pack)); @@ -273,7 +280,7 @@ ret.formattedWrite("\n ", cur[same + idx].toString()); lastFolder = cur; } - ret.formattedWrite("\n ", source.filePath.toNativeString()); + ret.formattedWrite("\n ", source.build ? "" : "tool=\"None\" ", source.filePath.toNativeString()); } // Finalize all open folders foreach(unused; 0..lastFolder.length) diff --git a/source/dub/package_.d b/source/dub/package_.d index c92c1e8..4efa919 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -331,6 +331,18 @@ jf["type"] = "source"; files ~= jf; } + foreach (f; bs.importFiles) { + auto jf = Json.EmptyObject; + jf.path = f; + jf["type"] = "import"; + files ~= jf; + } + foreach (f; bs.stringImportFiles) { + auto jf = Json.EmptyObject; + jf.path = f; + jf["type"] = "stringImport"; + files ~= jf; + } dst.files = Json(files); } } @@ -654,27 +666,35 @@ if (!this.targetName.empty) dst.targetName = this.targetName; if (!this.workingDirectory.empty) dst.workingDirectory = this.workingDirectory; - // collect source files from all source folders - foreach(suffix, paths; sourcePaths){ - if( !platform.matchesSpecification(suffix) ) - continue; - - foreach (spath; paths) { - enforce(!spath.empty, "Source paths must not be empty strings."); - auto path = base_path ~ spath; - if (!existsFile(path) || !isDir(path.toNativeString())) { - logWarn("Invalid source path: %s", path.toNativeString()); + void collectFiles(string method)(in string[][string] paths_map, string pattern) + { + foreach (suffix, paths; paths_map) { + if (!platform.matchesSpecification(suffix)) continue; - } - foreach(d; dirEntries(path.toNativeString(), "*.d", SpanMode.depth)){ - if (isDir(d.name)) continue; - auto src = Path(d.name).relativeTo(base_path); - dst.addSourceFiles(src.toNativeString()); + foreach (spath; paths) { + enforce(!spath.empty, "Paths must not be empty strings."); + auto path = base_path ~ spath; + if (!existsFile(path) || !isDir(path.toNativeString())) { + logWarn("Invalid source path: %s", path.toNativeString()); + continue; + } + + foreach (d; dirEntries(path.toNativeString(), pattern, SpanMode.depth)) { + if (isDir(d.name)) continue; + auto src = Path(d.name).relativeTo(base_path); + __traits(getMember, dst, method)(src.toNativeString()); + } } } } + // collect files from all source/import folders + collectFiles!"addSourceFiles"(sourcePaths, "*.d"); + collectFiles!"addImportFiles"(importPaths, "*.{d,di}"); + dst.removeImportFiles(dst.sourceFiles); + collectFiles!"addStringImportFiles"(stringImportPaths, "*"); + getPlatformSetting!("dflags", "addDFlags")(dst, platform); getPlatformSetting!("lflags", "addLFlags")(dst, platform); getPlatformSetting!("libs", "addLibs")(dst, platform);