diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index 1d592e5..086dda9 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -60,21 +60,15 @@ addBuildTypeFlags(buildsettings, settings.buildType); } - // add all .d files - void addPackageFiles(in Package pack){ - foreach(s; pack.sources){ - if( pack !is m_project.mainPackage && s == Path("source/app.d") ) - continue; - auto relpath = (pack.path ~ s).relativeTo(cwd); - buildsettings.addSourceFiles(relpath.toNativeString()); - } - } - addPackageFiles(m_project.mainPackage); - foreach(dep; m_project.dependencies) - addPackageFiles(dep); - auto generate_binary = !buildsettings.dflags.canFind("-o-"); + // make paths relative to shrink the command line + foreach(ref f; buildsettings.sourceFiles){ + auto fp = Path(f); + if( fp.absolute ) fp = fp.relativeTo(Path(getcwd)); + f = fp.toNativeString(); + } + // setup for command line settings.compiler.prepareBuildSettings(buildsettings, BuildSetting.commandLine); diff --git a/source/dub/generators/monod.d b/source/dub/generators/monod.d index 2881c77..dbf0eee 100644 --- a/source/dub/generators/monod.d +++ b/source/dub/generators/monod.d @@ -236,35 +236,30 @@ void generateSourceEntry(Path path, Path base_path) { auto rel_path = path.relativeTo(pack.path); - if( base_path == pack.path || path.relativeTo(base_path).external ){ + rel_path.normalize(); + + Path pretty_path; + foreach( i; 0 .. rel_path.length ) + if( rel_path[i] != ".." ){ + pretty_path = rel_path[i .. $]; + break; + } + + if( base_path == pretty_path ){ sln.formattedWrite(" \n", rel_path.toNativeString()); } else { sln.formattedWrite(" \n", rel_path.toNativeString()); - sln.formattedWrite(" %s\n", path.relativeTo(base_path).toNativeString()); + sln.formattedWrite(" %s\n", pretty_path.toNativeString()); sln.formattedWrite(" \n"); } } - void generateSources(in Package p) - { - if( p in visited ) return; - visited[p] = true; - - foreach( s; p.sources ){ - if( p !is m_app.mainPackage && s == Path("source/app.d") ) - continue; - generateSourceEntry(p.path ~s, p.path); - } - foreach( s; buildsettings.sourceFiles ) - generateSourceEntry(Path(s), p.path); - } - - sln.put(" \n"); - generateSources(pack); - if( m_singleProject ) - foreach(dep; m_app.dependencies) - generateSources(dep); + foreach( s; buildsettings.sourceFiles ){ + auto sp = Path(s); + if( !sp.absolute ) sp = pack.path ~ sp; + generateSourceEntry(sp, pack.path); + } sln.put(" \n"); sln.put(""); } diff --git a/source/dub/generators/rdmd.d b/source/dub/generators/rdmd.d index 2d11159..50a04df 100644 --- a/source/dub/generators/rdmd.d +++ b/source/dub/generators/rdmd.d @@ -50,6 +50,8 @@ auto buildsettings = settings.buildSettings; m_project.addBuildSettings(buildsettings, settings.platform, settings.config); + // do not pass all source files to RDMD, only the main source file + buildsettings.sourceFiles = buildsettings.sourceFiles.filter!(s => !s.endsWith(".d"))().array(); buildsettings.addDFlags(["-w"/*, "-property"*/]); string dflags = environment.get("DFLAGS"); if( dflags ){ @@ -152,7 +154,13 @@ private Path getMainSourceFile(in Project prj) { - auto p = Path("source") ~ (prj.name ~ ".d"); - return existsFile(p) ? p : Path("source/app.d"); + foreach(p; ["source", "src", "."]){ + foreach(f; [prj.name, "app"]){ + auto fp = Path(p) ~ (f ~ ".d"); + if( existsFile(fp) ) + return fp; + } + } + return Path("app.d"); } diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index 38b5ee3..7c0df1d 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -187,33 +187,36 @@ generateProjectConfiguration(ret, pack, Config.Unittest, settings); // Add all files - bool[SourceFile] sourceFiles; - void gatherSources(const(Package) pack, bool prefixPkgId) { - logTrace("Gathering sources for %s (%s)", pack.name, pack is m_app.mainPackage); - foreach(source; pack.sources) { - if( pack !is m_app.mainPackage && source == Path("source/app.d") ) - continue; - SourceFile f = { - pack.name, - prefixPkgId ? Path(pack.name)~source : source, - (pack.path ~ source).relativeTo(m_app.mainPackage.path) - }; - sourceFiles[f] = true; - logTrace(" pkg file: %s", source); + version(VISUALD_SINGLE_PROJECT_FILE){ + auto files = settings.buildSettings; + + bool[SourceFile] sourceFiles; + foreach(s; files.sourceFiles){ + auto sp = Path(s); + if( !sp.absolute ) sp = m_app.mainPackage.path ~ sp; + SourceFile sf; + sf.pkg = pack.name; + sf.filePath = sp.relativeTo(m_app.mainPackage.path); + sf.structurePath = Path(pack.name) ~ sp.relativeTo(pack.path); + sourceFiles[sf] = true; } } - - version(VISUALD_SINGLE_PROJECT_FILE) { - // gather all sources - enforce(pack == m_app.mainPackage(), "Some setup has gone wrong in VisualD.generateProj()"); - gatherSources(pack, true); - performOnDependencies(pack, (dependency) { gatherSources(dependency, true); }); + + version(VISUALD_SEPERATE_PROJECT_FILES){ + auto files = pack.getBuildSettings(settings.platform, settings.config, pack is m_app.mainPackage); + + bool[SourceFile] sourceFiles; + foreach(s; files.sourceFiles){ + auto sp = Path(s); + if( !sp.absolute ) sp = pack.path ~ sp; + SourceFile sf; + sf.pkg = pack.name; + sf.filePath = sp.relativeTo(m_app.mainPackage.path); + sf.structurePath = sp.relativeTo(pack.path); + sourceFiles[sf] = true; + } } - version(VISUALD_SEPERATE_PROJECT_FILES) { - // gather sources for this package only - gatherSources(pack, false); - } - + // Create folders and files ret.formattedWrite("\n ", pack.name); Path lastFolder; diff --git a/source/dub/package_.d b/source/dub/package_.d index f1d2b2b..902c701 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -142,81 +142,76 @@ } /// Returns all BuildSettings for the given platform and config. - BuildSettings getBuildSettings(BuildPlatform platform, string config) + BuildSettings getBuildSettings(BuildPlatform platform, string config, bool app = false) const { BuildSettings ret; ret.parse(m_meta, platform); if( config.length ){ - auto pcs = "configurations" in m_meta; - if( !pcs ) return ret; - auto pc = config in *pcs; - if( !pc ) return ret; - ret.parse(*pc, platform); - } - - // TODO: add all sources and "source"/"src" as import paths - // TODO: add "views" as string import path - return ret; - } - - /// Returns all sources as relative paths, prepend each with - /// path() to get the absolute one. - @property const(Path[]) sources() const { - Path[] allSources; - - auto spaths = sourcePaths.map!(p => (m_path ~ p).toNativeString()).array; - - foreach(sourcePath; spaths) { - logTrace("Parsing directories for source path: %s", sourcePath); - - if (sourcePath.isDir) { - foreach(d; dirEntries(sourcePath, "*d", SpanMode.depth)) - { - // direct assignment allSources ~= Path(d.name)[...] - // spawns internal compiler/linker error - if(isDir(d.name)) continue; - auto p = Path(d.name); - allSources ~= p[m_path.length..$]; + if( auto pcs = "configurations" in m_meta ){ + if( auto pc = config in *pcs ){ + ret.parse(*pc, platform); } - } else { - auto p = Path(dirEntry(sourcePath).name); - allSources ~= p[m_path.length..$]; } } - logTrace("allSources: %s", allSources); - return allSources; - } - // Every path specified to include as sources - @property Path[] sourcePaths() const { - Path[] spaths; - - if (auto singleSourcePath = "sourcePath" in m_meta) { - spaths ~= Path(singleSourcePath.get!string()); - } - if (auto multipleSourcePaths = "sourcePaths" in m_meta) { - spaths ~= map!(p => Path(p.get!string()))((*multipleSourcePaths)[]).array; - } - if (spaths.empty) { - if( existsFile(path ~ "source") ) spaths ~= Path("source"); - else if( existsFile(path ~ "src") ) spaths ~= Path("src"); + // check for default string import folders + if( ret.stringImportPaths.empty ){ + foreach(defvf; ["views"]){ + auto p = this.path ~ defvf; + if( existsFile(p) ){ + ret.addStringImportPaths(defvf); + } + } } - return spaths; - } - - @property const(Path[]) appSources() - const { - Path[] ret; - if( auto as = "appSources" in m_meta ){ - foreach(src; *as) - ret ~= Path(src.get!string()); - } else { - if( existsFile(m_path ~ "source/app.d") ) ret ~= Path("source/app.d"); - else if( existsFile(m_path ~ ("source/"~name()~".d")) ) ret ~= Path("source/"~name()~".d"); + + // determine all source folders + Path[] source_paths; + if( auto psp = "sourcePath" in m_meta ) + source_paths ~= this.path ~ Path(psp.get!string()); + + if( auto psps = "sourcePaths" in m_meta ){ + foreach(p; *psps) + source_paths ~= this.path ~ p.get!string(); + } else if( source_paths.empty ){ + foreach(defsf; ["source", "src"]){ + auto p = this.path ~ defsf; + if( existsFile(p) ){ + source_paths ~= p; + ret.addImportPaths(defsf); + } + } } + logTrace("Source paths for %s: %s", this.name, source_paths); + + // gather all source files + string[] sources; + foreach(sourcePath; source_paths.map!(p => p.toNativeString())()) { + logTrace("Parsing directories for source path: %s", sourcePath); + + foreach(d; dirEntries(sourcePath, "*d", SpanMode.depth)) + { + // direct assignment allSources ~= Path(d.name)[...] + // spawns internal compiler/linker error + if(isDir(d.name)) continue; + auto p = Path(d.name); + auto src = p.relativeTo(this.path).toNativeString(); + if( app || !isAppSource(src) ) + sources ~= src; + } + } + logTrace("allSources: %s", sources); + ret.addSourceFiles(sources); + return ret; } + + bool isAppSource(string src) + const { + auto ps = Path(src); + if( ps.absolute ) ps = ps.relativeTo(this.path); + return ps == Path("source/app.d") || ps == Path("src/app.d"); + } /// TODO: what is the defaul configuration? string getDefaultConfiguration(BuildPlatform platform) diff --git a/source/dub/project.d b/source/dub/project.d index 3478c88..7dd8004 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -200,17 +200,8 @@ /// Returns the DFLAGS void addBuildSettings(ref BuildSettings dst, BuildPlatform platform, string config) const { - void addImportPath(string path, bool src) - { - if( !exists(path) ) return; - if( src ) dst.addImportPaths([path]); - else dst.addStringImportPaths([path]); - } - foreach(pkg; this.topologicalPackageList){ - processVars(dst, pkg.path.toNativeString(), pkg.getBuildSettings(platform, config)); - addImportPath((pkg.path ~ "source").toNativeString(), true); - addImportPath((pkg.path ~ "views").toNativeString(), false); + processVars(dst, pkg.path.toNativeString(), pkg.getBuildSettings(platform, config, pkg is m_main)); } // add version identifiers for available packages