diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 6c4956e..e96db83 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -218,8 +218,8 @@ // initialize the root package if (!cmd.skipDubInitialization) { if (options.bare) { - dub = new Dub(Path(getcwd())); - dub.rootPath = Path(options.root_path); + dub = new Dub(NativePath(getcwd())); + dub.rootPath = NativePath(options.root_path); dub.defaultPlacementLocation = options.placementLocation; } else { // initialize DUB @@ -230,7 +230,7 @@ // make the CWD package available so that for example sub packages can reference their // parent package. - try dub.packageManager.getOrLoadPackage(Path(options.root_path)); + try dub.packageManager.getOrLoadPackage(NativePath(options.root_path)); catch (Exception e) { logDiagnostic("No package found in current working directory."); } } } @@ -545,7 +545,7 @@ logInfo("Deprecated use of init type. Use --type=[vibe.d | deimos | minimal] in future."); } } - dub.createEmptyPackage(Path(dir), free_args, m_templateType, m_format, &depCallback); + dub.createEmptyPackage(NativePath(dir), free_args, m_templateType, m_format, &depCallback); logInfo("Package successfully created in %s", dir.length ? dir : "."); return 0; @@ -930,7 +930,7 @@ settings.run = true; settings.runArgs = app_args; - dub.testProject(settings, m_buildConfig, Path(m_mainFile)); + dub.testProject(settings, m_buildConfig, NativePath(m_mainFile)); return 0; } } @@ -1529,9 +1529,9 @@ auto scope_ = m_system ? LocalPackageType.system : LocalPackageType.user; auto pack = free_args[0]; auto ver = Dependency(free_args[1]); - if (existsFile(Path(free_args[2]))) { - auto target = Path(free_args[2]); - if (!target.absolute) target = Path(getcwd()) ~ target; + if (existsFile(NativePath(free_args[2]))) { + auto target = NativePath(free_args[2]); + if (!target.absolute) target = NativePath(getcwd()) ~ target; dub.packageManager.addOverride(scope_, pack, ver, target); logInfo("Added override %s %s => %s", pack, ver, target); } else { @@ -1680,7 +1680,7 @@ import std.format : formattedWrite; if (m_testPackage.length) { - dub = new Dub(Path(getcwd())); + dub = new Dub(NativePath(getcwd())); setupPackage(dub, m_testPackage); m_defaultConfig = dub.project.getDefaultConfiguration(m_buildPlatform); @@ -1709,10 +1709,10 @@ } } else { enforceUsage(free_args.length == 1, "Expected destination path."); - auto path = Path(free_args[0]); + auto path = NativePath(free_args[0]); path.normalize(); enforceUsage(!path.empty, "Destination path must not be empty."); - if (!path.absolute) path = Path(getcwd()) ~ path; + if (!path.absolute) path = NativePath(getcwd()) ~ path; enforceUsage(!path.startsWith(dub.rootPath), "Destination path must not be a sub directory of the tested package!"); setupPackage(dub, null); @@ -1720,7 +1720,7 @@ if (m_buildConfig.empty) m_buildConfig = prj.getDefaultConfiguration(m_buildPlatform); - void copyFolderRec(Path folder, Path dstfolder) + void copyFolderRec(NativePath folder, NativePath dstfolder) { mkdirRecurse(dstfolder.toNativeString()); foreach (de; iterateDirectory(folder.toNativeString())) { @@ -1741,11 +1741,11 @@ static void fixPathDependency(string pack, ref Dependency dep) { if (!dep.path.empty) { auto mainpack = getBasePackageName(pack); - dep.path = Path("../") ~ mainpack; + dep.path = NativePath("../") ~ mainpack; } } - void fixPathDependencies(ref PackageRecipe recipe, Path base_path) + void fixPathDependencies(ref PackageRecipe recipe, NativePath base_path) { foreach (name, ref dep; recipe.buildSettings.dependencies) fixPathDependency(name, dep); @@ -1756,7 +1756,7 @@ foreach (ref subp; recipe.subPackages) if (subp.path.length) { - auto sub_path = base_path ~ Path(subp.path); + auto sub_path = base_path ~ NativePath(subp.path); auto pack = prj.packageManager.getOrLoadPackage(sub_path); fixPathDependencies(pack.recipe, sub_path); pack.storeInfo(sub_path); diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index 0e9a1ce..9f54140 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -167,9 +167,9 @@ static void addSI(ref string[] arr, in string[] vals) { bool[string] existing; - foreach (v; arr) existing[Path(v).head.toString()] = true; + foreach (v; arr) existing[NativePath(v).head.toString()] = true; foreach (v; vals) { - auto s = Path(v).head.toString(); + auto s = NativePath(v).head.toString(); if (s !in existing) { existing[s] = true; arr ~= v; @@ -191,7 +191,7 @@ bool matches(string s) { foreach (p; vals) - if (Path(s) == Path(p) || globMatch(s, p)) + if (NativePath(s) == NativePath(p) || globMatch(s, p)) return true; return false; } diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 28367d0..f70556d 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -192,7 +192,7 @@ } if (tpath is null) - tpath = (Path(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); + tpath = (NativePath(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); settings.addDFlags("-of"~tpath); } @@ -210,7 +210,7 @@ void invokeLinker(in BuildSettings settings, in BuildPlatform platform, string[] objects, void delegate(int, string) output_callback) { import std.string; - auto tpath = Path(settings.targetPath) ~ getTargetFileName(settings, platform); + auto tpath = NativePath(settings.targetPath) ~ getTargetFileName(settings, platform); auto args = ["-of"~tpath.toNativeString()]; args ~= objects; args ~= settings.sourceFiles; diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 1718cad..063c60e 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -182,7 +182,7 @@ } if (tpath is null) - tpath = (Path(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); + tpath = (NativePath(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); settings.addDFlags("-o", tpath); } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 7d25884..dbc77fd 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -195,7 +195,7 @@ } if (tpath is null) - tpath = (Path(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); + tpath = (NativePath(settings.targetPath) ~ getTargetFileName(settings, platform)).toNativeString(); settings.addDFlags("-of"~tpath); } diff --git a/source/dub/compilers/utils.d b/source/dub/compilers/utils.d index f28f878..81983ee 100644 --- a/source/dub/compilers/utils.d +++ b/source/dub/compilers/utils.d @@ -242,7 +242,7 @@ See_Also: `readPlatformProbe` */ -Path generatePlatformProbeFile() +NativePath generatePlatformProbeFile() { import dub.internal.vibecompat.core.file; import dub.internal.vibecompat.data.json; diff --git a/source/dub/dependency.d b/source/dub/dependency.d index 297e392..cd6c01d 100644 --- a/source/dub/dependency.d +++ b/source/dub/dependency.d @@ -53,7 +53,7 @@ Version m_versA; bool m_inclusiveB = true; // B comparison < (true) or <= (false) Version m_versB; - Path m_path; + NativePath m_path; bool m_optional = false; bool m_default = false; } @@ -87,16 +87,16 @@ /** Constructs a new dependency specification that matches a specific path. */ - this(Path path) + this(NativePath path) { this(ANY_IDENT); m_path = path; } /// If set, overrides any version based dependency selection. - @property void path(Path value) { m_path = value; } + @property void path(NativePath value) { m_path = value; } /// ditto - @property Path path() const { return m_path; } + @property NativePath path() const { return m_path; } /// Determines if the dependency is required or optional. @property bool optional() const { return m_optional; } @@ -239,7 +239,7 @@ based. Otherwise, the given `path` will be prefixed to the existing path. */ - Dependency mapToPath(Path path) + Dependency mapToPath(NativePath path) const @trusted { // NOTE Path is @system in vibe.d 0.7.x and in the compatibility layer if (m_path.empty || m_path.absolute) return this; else { @@ -311,7 +311,7 @@ logDiagnostic("Ignoring version specification (%s) for path based dependency %s", pv.get!string, pp.get!string); dep = Dependency.any; - dep.path = Path(verspec["path"].get!string); + dep.path = NativePath(verspec["path"].get!string); } else { enforce("version" in verspec, "No version field specified!"); auto ver = verspec["version"].get!string; @@ -341,7 +341,7 @@ Dependency d = Dependency.any; // supposed to ignore the version spec d.optional = true; d.default_ = true; - d.path = Path("path/to/package"); + d.path = NativePath("path/to/package"); assert(d == parsed); // optional and path not checked by opEquals. assert(d.optional == parsed.optional); diff --git a/source/dub/dub.d b/source/dub/dub.d index 6fc954a..b6c6821 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -99,12 +99,12 @@ bool m_dryRun = false; PackageManager m_packageManager; PackageSupplier[] m_packageSuppliers; - Path m_rootPath; + NativePath m_rootPath; SpecialDirs m_dirs; DubConfig m_config; - Path m_projectPath; + NativePath m_projectPath; Project m_project; - Path m_overrideSearchPath; + NativePath m_overrideSearchPath; string m_defaultCompiler; } @@ -133,8 +133,8 @@ this(string root_path = ".", PackageSupplier[] additional_package_suppliers = null, SkipPackageSuppliers skip_registry = SkipPackageSuppliers.none) { - m_rootPath = Path(root_path); - if (!m_rootPath.absolute) m_rootPath = Path(getcwd()) ~ m_rootPath; + m_rootPath = NativePath(root_path); + if (!m_rootPath.absolute) m_rootPath = NativePath(getcwd()) ~ m_rootPath; init(); @@ -185,11 +185,11 @@ This constructor corresponds to the "--bare" option of the command line interface. Use */ - this(Path override_path) + this(NativePath override_path) { init(); m_overrideSearchPath = override_path; - m_packageManager = new PackageManager(Path(), Path(), false); + m_packageManager = new PackageManager(NativePath(), NativePath(), false); updatePackageSearchPath(); } @@ -197,19 +197,19 @@ { import std.file : tempDir; version(Windows) { - m_dirs.systemSettings = Path(environment.get("ProgramData")) ~ "dub/"; - m_dirs.userSettings = Path(environment.get("APPDATA")) ~ "dub/"; + m_dirs.systemSettings = NativePath(environment.get("ProgramData")) ~ "dub/"; + m_dirs.userSettings = NativePath(environment.get("APPDATA")) ~ "dub/"; } else version(Posix){ - m_dirs.systemSettings = Path("/var/lib/dub/"); - m_dirs.userSettings = Path(environment.get("HOME")) ~ ".dub/"; + m_dirs.systemSettings = NativePath("/var/lib/dub/"); + m_dirs.userSettings = NativePath(environment.get("HOME")) ~ ".dub/"; if (!m_dirs.userSettings.absolute) - m_dirs.userSettings = Path(getcwd()) ~ m_dirs.userSettings; + m_dirs.userSettings = NativePath(getcwd()) ~ m_dirs.userSettings; } - m_dirs.temp = Path(tempDir); + m_dirs.temp = NativePath(tempDir); m_config = new DubConfig(jsonFromFile(m_dirs.systemSettings ~ "settings.json", true), m_config); - m_config = new DubConfig(jsonFromFile(Path(thisExePath).parentPath ~ "../etc/dub/settings.json", true), m_config); + m_config = new DubConfig(jsonFromFile(NativePath(thisExePath).parentPath ~ "../etc/dub/settings.json", true), m_config); m_config = new DubConfig(jsonFromFile(m_dirs.userSettings ~ "settings.json", true), m_config); determineDefaultCompiler(); @@ -219,19 +219,19 @@ /** Returns the root path (usually the current working directory). */ - @property Path rootPath() const { return m_rootPath; } + @property NativePath rootPath() const { return m_rootPath; } /// ditto - @property void rootPath(Path root_path) + @property void rootPath(NativePath root_path) { m_rootPath = root_path; - if (!m_rootPath.absolute) m_rootPath = Path(getcwd()) ~ m_rootPath; + if (!m_rootPath.absolute) m_rootPath = NativePath(getcwd()) ~ m_rootPath; } /// Returns the name listed in the dub.json of the current /// application. @property string projectName() const { return m_project.name; } - @property Path projectPath() const { return m_projectPath; } + @property NativePath projectPath() const { return m_projectPath; } @property string[] configurations() const { return m_project.configurations; } @@ -258,7 +258,7 @@ } /// Loads the package from the specified path as the main project package. - void loadPackage(Path path) + void loadPackage(NativePath path) { m_projectPath = path; updatePackageSearchPath(); @@ -303,7 +303,7 @@ The script above can be invoked with "dub --single test.d". */ - void loadSingleFilePackage(Path path) + void loadSingleFilePackage(NativePath path) { import dub.recipe.io : parsePackageRecipe; import std.file : mkdirRecurse, readText; @@ -356,15 +356,15 @@ /// ditto void loadSingleFilePackage(string path) { - loadSingleFilePackage(Path(path)); + loadSingleFilePackage(NativePath(path)); } /** Disables the default search paths and only searches a specific directory for packages. */ - void overrideSearchPath(Path path) + void overrideSearchPath(NativePath path) { - if (!path.absolute) path = Path(getcwd()) ~ path; + if (!path.absolute) path = NativePath(getcwd()) ~ path; m_overrideSearchPath = path; updatePackageSearchPath(); } @@ -486,7 +486,7 @@ if ((options & UpgradeOptions.select) && p != m_project.rootPackage.name) { if (ver.path.empty) m_project.selections.selectVersion(p, ver.version_); else { - Path relpath = ver.path; + NativePath relpath = ver.path; if (relpath.absolute) relpath = relpath.relativeTo(m_project.rootPackage.path); m_project.selections.selectVersion(p, relpath); } @@ -514,7 +514,7 @@ Throws an exception, if unittests failed. */ - void testProject(GeneratorSettings settings, string config, Path custom_main_file) + void testProject(GeneratorSettings settings, string config, NativePath custom_main_file) { if (!custom_main_file.empty && !custom_main_file.absolute) custom_main_file = getWorkingDirectory() ~ custom_main_file; @@ -576,8 +576,8 @@ string[] import_modules; foreach (file; lbuildsettings.sourceFiles) { if (file.endsWith(".d")) { - auto fname = Path(file).head.toString(); - if (Path(file).relativeTo(m_project.rootPackage.path) == Path(mainfil)) { + auto fname = NativePath(file).head.toString(); + if (NativePath(file).relativeTo(m_project.rootPackage.path) == NativePath(mainfil)) { logWarn("Excluding main source file %s from test.", mainfil); tcinfo.excludedSourceFiles[""] ~= mainfil; continue; @@ -586,12 +586,12 @@ logWarn("Excluding package.d file from test due to https://issues.dlang.org/show_bug.cgi?id=11847"); continue; } - import_modules ~= dub.internal.utils.determineModuleName(lbuildsettings, Path(file), m_project.rootPackage.path); + import_modules ~= dub.internal.utils.determineModuleName(lbuildsettings, NativePath(file), m_project.rootPackage.path); } } // generate main file - Path mainfile = getTempFile("dub_test_root", ".d"); + NativePath mainfile = getTempFile("dub_test_root", ".d"); tcinfo.sourceFiles[""] ~= mainfile.toNativeString(); tcinfo.mainSourceFile = mainfile.toNativeString(); if (!m_dryRun) { @@ -665,7 +665,7 @@ } /// Cleans intermediate/cache files of the given package - void cleanPackage(Path path) + void cleanPackage(NativePath path) { logInfo("Cleaning package at %s...", path.toNativeString()); enforce(!Package.findPackageFile(path).empty, "No package found.", path.toNativeString()); @@ -696,7 +696,7 @@ enforce(pinfo.type != Json.Type.undefined, "No package "~packageId~" was found matching the dependency "~dep.toString()); string ver = pinfo["version"].get!string; - Path placement; + NativePath placement; final switch (location) { case PlacementLocation.local: placement = m_rootPath; break; case PlacementLocation.user: placement = m_dirs.userSettings ~ "packages/"; break; @@ -740,7 +740,7 @@ clean_package_version = clean_package_version.replace("+", "_"); // + has special meaning for Optlink if (!placement.existsFile()) mkdirRecurse(placement.toNativeString()); - Path dstpath = placement ~ (packageId ~ "-" ~ clean_package_version); + NativePath dstpath = placement ~ (packageId ~ "-" ~ clean_package_version); if (!dstpath.existsFile()) mkdirRecurse(dstpath.toNativeString()); @@ -1036,7 +1036,7 @@ recipe_callback = Optional callback that can be used to customize the recipe before it gets written. */ - void createEmptyPackage(Path path, string[] deps, string type, + void createEmptyPackage(NativePath path, string[] deps, string type, PackageFormat format = PackageFormat.sdl, scope void delegate(ref PackageRecipe, ref PackageFormat) recipe_callback = null) { @@ -1170,11 +1170,11 @@ m_packageManager.searchPath = [m_overrideSearchPath]; } else { auto p = environment.get("DUBPATH"); - Path[] paths; + NativePath[] paths; version(Windows) enum pathsep = ";"; else enum pathsep = ":"; - if (p.length) paths ~= p.split(pathsep).map!(p => Path(p))().array(); + if (p.length) paths ~= p.split(pathsep).map!(p => NativePath(p))().array(); m_packageManager.disableDefaultSearchPaths = false; m_packageManager.searchPath = paths; } @@ -1193,13 +1193,13 @@ auto compilers = ["dmd", "gdc", "gdmd", "ldc2", "ldmd2"]; - auto paths = environment.get("PATH", "").splitter(sep).map!Path; + auto paths = environment.get("PATH", "").splitter(sep).map!NativePath; auto res = compilers.find!(bin => paths.canFind!(p => existsFile(p ~ (bin~exe)))); m_defaultCompiler = res.empty ? compilers[0] : res.front; } - private Path makeAbsolute(Path p) const { return p.absolute ? p : m_rootPath ~ p; } - private Path makeAbsolute(string p) const { return makeAbsolute(Path(p)); } + private NativePath makeAbsolute(NativePath p) const { return p.absolute ? p : m_rootPath ~ p; } + private NativePath makeAbsolute(string p) const { return makeAbsolute(NativePath(p)); } } @@ -1512,9 +1512,9 @@ } private struct SpecialDirs { - Path temp; - Path userSettings; - Path systemSettings; + NativePath temp; + NativePath userSettings; + NativePath systemSettings; } private class DubConfig { diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index 8947bd8..6bf82aa 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -33,8 +33,8 @@ class BuildGenerator : ProjectGenerator { private { PackageManager m_packageMan; - Path[] m_temporaryFiles; - Path m_targetExecutablePath; + NativePath[] m_temporaryFiles; + NativePath m_targetExecutablePath; } this(Project project) @@ -52,7 +52,7 @@ bool any_cached = false; - Path[string] target_paths; + NativePath[string] target_paths; bool[string] visited; void buildTargetRec(string target) @@ -65,7 +65,7 @@ foreach (dep; ti.dependencies) buildTargetRec(dep); - Path[] additional_dep_files; + NativePath[] additional_dep_files; auto bs = ti.buildSettings.dup; foreach (ldep; ti.linkDependencies) { auto dbs = targets[ldep].buildSettings; @@ -75,7 +75,7 @@ additional_dep_files ~= target_paths[ldep]; } } - Path tpath; + NativePath tpath; if (buildTarget(settings, bs, ti.pack, ti.config, ti.packages, additional_dep_files, tpath)) any_cached = true; target_paths[target] = tpath; @@ -86,7 +86,7 @@ if (settings.rdmd || root_ti.buildSettings.targetType == TargetType.staticLibrary) { // RDMD always builds everything at once and static libraries don't need their // dependencies to be built - Path tpath; + NativePath tpath; buildTarget(settings, root_ti.buildSettings.dup, m_project.rootPackage, root_ti.config, root_ti.packages, null, tpath); } else { buildTargetRec(m_project.rootPackage.name); @@ -102,7 +102,7 @@ // run the generated executable auto buildsettings = targets[m_project.rootPackage.name].buildSettings.dup; if (settings.run && !(buildsettings.options & BuildOption.syntaxOnly)) { - Path exe_file_path; + NativePath exe_file_path; if (m_targetExecutablePath.empty) exe_file_path = getTargetPath(buildsettings, settings); else @@ -111,15 +111,15 @@ } } - private bool buildTarget(GeneratorSettings settings, BuildSettings buildsettings, in Package pack, string config, in Package[] packages, in Path[] additional_dep_files, out Path target_path) + private bool buildTarget(GeneratorSettings settings, BuildSettings buildsettings, in Package pack, string config, in Package[] packages, in NativePath[] additional_dep_files, out NativePath target_path) { - auto cwd = Path(getcwd()); + auto cwd = NativePath(getcwd()); bool generate_binary = !(buildsettings.options & BuildOption.syntaxOnly); auto build_id = computeBuildID(config, buildsettings, settings); // make all paths relative to shrink the command line - string makeRelative(string path) { return shrinkPath(Path(path), cwd); } + string makeRelative(string path) { return shrinkPath(NativePath(path), cwd); } foreach (ref f; buildsettings.sourceFiles) f = makeRelative(f); foreach (ref p; buildsettings.importPaths) p = makeRelative(p); foreach (ref p; buildsettings.stringImportPaths) p = makeRelative(p); @@ -149,11 +149,11 @@ } private bool performCachedBuild(GeneratorSettings settings, BuildSettings buildsettings, in Package pack, string config, - string build_id, in Package[] packages, in Path[] additional_dep_files, out Path target_binary_path) + string build_id, in Package[] packages, in NativePath[] additional_dep_files, out NativePath target_binary_path) { - auto cwd = Path(getcwd()); + auto cwd = NativePath(getcwd()); - Path target_path; + NativePath target_path; if (settings.tempBuild) { string packageName = pack.basePackage is null ? pack.name : pack.basePackage.name; m_targetExecutablePath = target_path = getTempDir() ~ format(".dub/build/%s-%s/%s/", packageName, pack.version_, build_id); @@ -198,14 +198,14 @@ return false; } - private void performRDMDBuild(GeneratorSettings settings, ref BuildSettings buildsettings, in Package pack, string config, out Path target_path) + private void performRDMDBuild(GeneratorSettings settings, ref BuildSettings buildsettings, in Package pack, string config, out NativePath target_path) { - auto cwd = Path(getcwd()); + auto cwd = NativePath(getcwd()); //Added check for existence of [AppNameInPackagejson].d //If exists, use that as the starting file. - Path mainsrc; + NativePath mainsrc; if (buildsettings.mainSourceFile.length) { - mainsrc = Path(buildsettings.mainSourceFile); + mainsrc = NativePath(buildsettings.mainSourceFile); if (!mainsrc.absolute) mainsrc = pack.path ~ mainsrc; } else { mainsrc = getMainSourceFile(pack); @@ -223,7 +223,7 @@ // or with "/" instead of "\" bool tmp_target = false; if (generate_binary) { - if (settings.tempBuild || (settings.run && !isWritableDir(Path(buildsettings.targetPath), true))) { + if (settings.tempBuild || (settings.run && !isWritableDir(NativePath(buildsettings.targetPath), true))) { import std.random; auto rnd = to!string(uniform(uint.min, uint.max)) ~ "-"; auto tmpdir = getTempDir()~".rdmd/source/"; @@ -259,20 +259,20 @@ if (tmp_target) { m_temporaryFiles ~= target_path; foreach (f; buildsettings.copyFiles) - m_temporaryFiles ~= Path(buildsettings.targetPath).parentPath ~ Path(f).head; + m_temporaryFiles ~= NativePath(buildsettings.targetPath).parentPath ~ NativePath(f).head; } } - private void performDirectBuild(GeneratorSettings settings, ref BuildSettings buildsettings, in Package pack, string config, out Path target_path) + private void performDirectBuild(GeneratorSettings settings, ref BuildSettings buildsettings, in Package pack, string config, out NativePath target_path) { - auto cwd = Path(getcwd()); + auto cwd = NativePath(getcwd()); auto generate_binary = !(buildsettings.options & BuildOption.syntaxOnly); auto is_static_library = buildsettings.targetType == TargetType.staticLibrary || buildsettings.targetType == TargetType.library; // make file paths relative to shrink the command line foreach (ref f; buildsettings.sourceFiles) { - auto fp = Path(f); + auto fp = NativePath(f); if( fp.absolute ) fp = fp.relativeTo(cwd); f = fp.toNativeString(); } @@ -281,7 +281,7 @@ // make all target/import paths relative string makeRelative(string path) { - auto p = Path(path); + auto p = NativePath(path); // storing in a separate temprary to work around #601 auto prel = p.absolute ? p.relativeTo(cwd) : p; return prel.toNativeString(); @@ -292,7 +292,7 @@ bool is_temp_target = false; if (generate_binary) { - if (settings.tempBuild || (settings.run && !isWritableDir(Path(buildsettings.targetPath), true))) { + if (settings.tempBuild || (settings.run && !isWritableDir(NativePath(buildsettings.targetPath), true))) { import std.random; auto rnd = to!string(uniform(uint.min, uint.max)); auto tmppath = getTempDir()~("dub/"~rnd~"/"); @@ -313,7 +313,7 @@ if (is_temp_target) { m_temporaryFiles ~= target_path; foreach (f; buildsettings.copyFiles) - m_temporaryFiles ~= Path(buildsettings.targetPath).parentPath ~ Path(f).head; + m_temporaryFiles ~= NativePath(buildsettings.targetPath).parentPath ~ NativePath(f).head; } } @@ -347,17 +347,17 @@ settings.platform.compiler, settings.platform.frontendVersion, hashstr); } - private void copyTargetFile(Path build_path, BuildSettings buildsettings, GeneratorSettings settings) + private void copyTargetFile(NativePath build_path, BuildSettings buildsettings, GeneratorSettings settings) { auto filename = settings.compiler.getTargetFileName(buildsettings, settings.platform); auto src = build_path ~ filename; logDiagnostic("Copying target from %s to %s", src.toNativeString(), buildsettings.targetPath); - if (!existsFile(Path(buildsettings.targetPath))) + if (!existsFile(NativePath(buildsettings.targetPath))) mkdirRecurse(buildsettings.targetPath); - hardLinkFile(src, Path(buildsettings.targetPath) ~ filename, true); + hardLinkFile(src, NativePath(buildsettings.targetPath) ~ filename, true); } - private bool isUpToDate(Path target_path, BuildSettings buildsettings, GeneratorSettings settings, in Package main_pack, in Package[] packages, in Path[] additional_dep_files) + private bool isUpToDate(NativePath target_path, BuildSettings buildsettings, GeneratorSettings settings, in Package main_pack, in Package[] packages, in NativePath[] additional_dep_files) { import std.datetime; @@ -374,7 +374,7 @@ allfiles ~= buildsettings.stringImportFiles; // TODO: add library files foreach (p; packages) - allfiles ~= (p.recipePath != Path.init ? p : p.basePackage).recipePath.toNativeString(); + allfiles ~= (p.recipePath != NativePath.init ? p : p.basePackage).recipePath.toNativeString(); foreach (f; additional_dep_files) allfiles ~= f.toNativeString(); if (main_pack is m_project.rootPackage && m_project.rootPackage.getAllDependencies().length > 0) allfiles ~= (main_pack.path ~ SelectedVersions.defaultFile).toNativeString(); @@ -407,7 +407,7 @@ /// Compile a single source file (srcFile), and write the object to objName. static string compileUnit(string srcFile, string objName, BuildSettings bs, GeneratorSettings gs) { - Path tempobj = Path(bs.targetPath)~objName; + NativePath tempobj = NativePath(bs.targetPath)~objName; string objPath = tempobj.toNativeString(); bs.libs = null; bs.lflags = null; @@ -424,7 +424,7 @@ auto generate_binary = !(buildsettings.options & BuildOption.syntaxOnly); auto is_static_library = buildsettings.targetType == TargetType.staticLibrary || buildsettings.targetType == TargetType.library; - Path target_file; + NativePath target_file; scope (failure) { logDiagnostic("FAIL %s %s %s" , buildsettings.targetPath, buildsettings.targetName, buildsettings.targetType); auto tpath = getTargetPath(buildsettings, settings); @@ -473,7 +473,7 @@ } else { // determine path for the temporary object file string tempobjname = buildsettings.targetName ~ objSuffix; - Path tempobj = Path(buildsettings.targetPath) ~ tempobjname; + NativePath tempobj = NativePath(buildsettings.targetPath) ~ tempobjname; // setup linker command line auto lbuildsettings = buildsettings; @@ -498,13 +498,13 @@ } } - private void runTarget(Path exe_file_path, in BuildSettings buildsettings, string[] run_args, GeneratorSettings settings) + private void runTarget(NativePath exe_file_path, in BuildSettings buildsettings, string[] run_args, GeneratorSettings settings) { if (buildsettings.targetType == TargetType.executable) { - auto cwd = Path(getcwd()); + auto cwd = NativePath(getcwd()); auto runcwd = cwd; if (buildsettings.workingDirectory.length) { - runcwd = Path(buildsettings.workingDirectory); + runcwd = NativePath(buildsettings.workingDirectory); if (!runcwd.absolute) runcwd = cwd ~ runcwd; logDiagnostic("Switching to %s", runcwd.toNativeString()); chdir(runcwd.toNativeString()); @@ -548,7 +548,7 @@ } } -private Path getMainSourceFile(in Package prj) +private NativePath getMainSourceFile(in Package prj) { foreach (f; ["source/app.d", "src/app.d", "source/"~prj.name~".d", "src/"~prj.name~".d"]) if (existsFile(prj.path ~ f)) @@ -556,12 +556,12 @@ return prj.path ~ "source/app.d"; } -private Path getTargetPath(in ref BuildSettings bs, in ref GeneratorSettings settings) +private NativePath getTargetPath(in ref BuildSettings bs, in ref GeneratorSettings settings) { - return Path(bs.targetPath) ~ settings.compiler.getTargetFileName(bs, settings.platform); + return NativePath(bs.targetPath) ~ settings.compiler.getTargetFileName(bs, settings.platform); } -private string shrinkPath(Path path, Path base) +private string shrinkPath(NativePath path, NativePath base) { auto orig = path.toNativeString(); if (!path.absolute) return orig; @@ -570,10 +570,10 @@ } unittest { - assert(shrinkPath(Path("/foo/bar/baz"), Path("/foo")) == Path("bar/baz").toNativeString()); - assert(shrinkPath(Path("/foo/bar/baz"), Path("/foo/baz")) == Path("../bar/baz").toNativeString()); - assert(shrinkPath(Path("/foo/bar/baz"), Path("/bar/")) == Path("/foo/bar/baz").toNativeString()); - assert(shrinkPath(Path("/foo/bar/baz"), Path("/bar/baz")) == Path("/foo/bar/baz").toNativeString()); + assert(shrinkPath(NativePath("/foo/bar/baz"), NativePath("/foo")) == NativePath("bar/baz").toNativeString()); + assert(shrinkPath(NativePath("/foo/bar/baz"), NativePath("/foo/baz")) == NativePath("../bar/baz").toNativeString()); + assert(shrinkPath(NativePath("/foo/bar/baz"), NativePath("/bar/")) == NativePath("/foo/bar/baz").toNativeString()); + assert(shrinkPath(NativePath("/foo/bar/baz"), NativePath("/bar/baz")) == NativePath("/foo/bar/baz").toNativeString()); } unittest { // issue #1235 - pass no library files to compiler command line when building a static lib @@ -585,8 +585,8 @@ else auto libfile = "bar.a"; auto desc = parseJsonString(`{"name": "test", "targetType": "library", "sourceFiles": ["foo.d", "`~libfile~`"]}`); - auto pack = new Package(desc, Path("/tmp/fooproject")); - auto pman = new PackageManager(Path("/tmp/foo/"), Path("/tmp/foo/"), false); + auto pack = new Package(desc, NativePath("/tmp/fooproject")); + auto pman = new PackageManager(NativePath("/tmp/foo/"), NativePath("/tmp/foo/"), false); auto prj = new Project(pman, pack); final static class TestCompiler : GDCCompiler { diff --git a/source/dub/generators/cmake.d b/source/dub/generators/cmake.d index 269c136..595442d 100644 --- a/source/dub/generators/cmake.d +++ b/source/dub/generators/cmake.d @@ -32,8 +32,8 @@ auto script = appender!(char[]); auto scripts = appender!(string[]); bool[string] visited; - Path projectRoot = m_project.rootPackage.path; - Path cmakeListsPath = projectRoot ~ "CMakeLists.txt"; + NativePath projectRoot = m_project.rootPackage.path; + NativePath cmakeListsPath = projectRoot ~ "CMakeLists.txt"; foreach(name, info; targets) { diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 6154bfb..dfb0670 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -112,7 +112,7 @@ BuildSettings buildsettings; buildsettings.processVars(m_project, pack, pack.getBuildSettings(settings.platform, configs[pack.name]), true); bool generate_binary = !(buildsettings.options & BuildOption.syntaxOnly); - finalizeGeneration(pack, m_project, settings, buildsettings, Path(bs.targetPath), generate_binary); + finalizeGeneration(pack, m_project, settings, buildsettings, NativePath(bs.targetPath), generate_binary); } performPostGenerateActions(settings, targets); @@ -246,7 +246,7 @@ // override string import files (used for up to date checking) foreach (ref f; ti.buildSettings.stringImportFiles) foreach (fi; root_settings.stringImportFiles) - if (f != fi && Path(f).head == Path(fi).head) { + if (f != fi && NativePath(f).head == NativePath(fi).head) { f = fi; } @@ -364,7 +364,7 @@ Runs post-build commands and copies required files to the binary directory. */ private void finalizeGeneration(in Package pack, in Project proj, in GeneratorSettings settings, - in BuildSettings buildsettings, Path target_path, bool generate_binary) + in BuildSettings buildsettings, NativePath target_path, bool generate_binary) { import std.path : globMatch; @@ -378,7 +378,7 @@ mkdirRecurse(buildsettings.targetPath); if (buildsettings.copyFiles.length) { - void copyFolderRec(Path folder, Path dstfolder) + void copyFolderRec(NativePath folder, NativePath dstfolder) { mkdirRecurse(dstfolder.toNativeString()); foreach (de; iterateDirectory(folder.toNativeString())) { @@ -395,9 +395,9 @@ void tryCopyDir(string file) { - auto src = Path(file); + auto src = NativePath(file); if (!src.absolute) src = pack.path ~ src; - auto dst = target_path ~ Path(file).head; + auto dst = target_path ~ NativePath(file).head; if (src == dst) { logDiagnostic("Skipping copy of %s (same source and destination)", file); return; @@ -410,9 +410,9 @@ void tryCopyFile(string file) { - auto src = Path(file); + auto src = NativePath(file); if (!src.absolute) src = pack.path ~ src; - auto dst = target_path ~ Path(file).head; + auto dst = target_path ~ NativePath(file).head; if (src == dst) { logDiagnostic("Skipping copy of %s (same source and destination)", file); return; diff --git a/source/dub/generators/targetdescription.d b/source/dub/generators/targetdescription.d index d2aec6e..a84883c 100644 --- a/source/dub/generators/targetdescription.d +++ b/source/dub/generators/targetdescription.d @@ -52,7 +52,7 @@ foreach (ld; ti.linkDependencies) { auto ltarget = targets[ld]; auto ltbs = ltarget.buildSettings; - auto targetfil = (Path(ltbs.targetPath) ~ settings.compiler.getTargetFileName(ltbs, settings.platform)).toNativeString(); + auto targetfil = (NativePath(ltbs.targetPath) ~ settings.compiler.getTargetFileName(ltbs, settings.platform)).toNativeString(); d.buildSettings.addLinkerFiles(targetfil); } diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index 3f94f6e..6cc1b47 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -170,7 +170,7 @@ // Add all files auto files = targets[packname].buildSettings; SourceFile[string] sourceFiles; - void addSourceFile(Path file_path, Path structure_path, bool build) + void addSourceFile(NativePath file_path, NativePath structure_path, bool build) { auto key = file_path.toString(); auto sf = sourceFiles.get(key, SourceFile.init); @@ -183,7 +183,7 @@ } void addFile(string s, bool build) { - auto sp = Path(s); + auto sp = NativePath(s); assert(sp.absolute, format("Source path in %s expected to be absolute: %s", packname, s)); //if( !sp.absolute ) sp = pack.path ~ sp; addSourceFile(sp.relativeTo(project_file_dir), determineStructurePath(sp, targets[packname]), build); @@ -203,7 +203,7 @@ // Create folders and files ret.formattedWrite(" ", getPackageFileName(packname)); - typeof(Path.init.head)[] lastFolder; + typeof(NativePath.init.head)[] lastFolder; foreach(source; sortedSources(sourceFiles.values)) { logDebug("source looking at %s", source.structurePath); auto cur = source.structurePath.parentPath.bySegment.array; @@ -248,7 +248,7 @@ auto ret = new string[settings.length]; foreach (i; 0 .. settings.length) { // \" is interpreted as an escaped " by cmd.exe, so we need to avoid that - auto p = Path(settings[i]).relativeTo(project_file_dir); + auto p = NativePath(settings[i]).relativeTo(project_file_dir); p.endsWithSlash = false; ret[i] = '"' ~ p.toNativeString() ~ '"'; } @@ -285,7 +285,7 @@ output_type = DynamicLib; output_ext = "dll"; } - auto bin_path = pack == m_project.rootPackage.name ? Path(buildsettings.targetPath) : Path("lib/"); + auto bin_path = pack == m_project.rootPackage.name ? NativePath(buildsettings.targetPath) : NativePath("lib/"); bin_path.endsWithSlash = true; ret.formattedWrite(" %s\n", output_type); ret.formattedWrite(" %s%s.%s\n", bin_path.toNativeString(), buildsettings.targetName, output_ext); @@ -315,7 +315,7 @@ // compute directory for intermediate files (need dummy/ because of how -op determines the resulting path) size_t ndummy = 0; foreach (f; buildsettings.sourceFiles) { - auto rpath = Path(f).relativeTo(project_file_dir); + auto rpath = NativePath(f).relativeTo(project_file_dir); size_t nd = 0; foreach (s; rpath.bySegment) if (s == "..") @@ -406,7 +406,7 @@ ret.put(" \n"); ret.put(" \n"); ret.put(" \n"); - auto wdir = Path(buildsettings.workingDirectory); + auto wdir = NativePath(buildsettings.workingDirectory); if (!wdir.absolute) wdir = m_project.rootPackage.path ~ wdir; ret.formattedWrite(" %s\n", wdir.relativeTo(project_file_dir).toNativeString()); @@ -441,8 +441,8 @@ else return getPackageFileName(m_project.rootPackage.name) ~ ".sln"; } - Path projFileName(string pack) const { - auto basepath = Path(".dub/"); + NativePath projFileName(string pack) const { + auto basepath = NativePath(".dub/"); version(DUBBING) return basepath ~ (getPackageFileName(pack) ~ ".dubbed.visualdproj"); else return basepath ~ (getPackageFileName(pack) ~ ".visualdproj"); } @@ -450,8 +450,8 @@ // TODO: nice folders private struct SourceFile { - Path structurePath; - Path filePath; + NativePath structurePath; + NativePath filePath; bool build; hash_t toHash() const nothrow @trusted { return structurePath.toHash() ^ filePath.toHash() ^ (build * 0x1f3e7b2c); } @@ -487,33 +487,33 @@ unittest { SourceFile[] sfs = [ - { Path("b/file.d"), Path("") }, - { Path("b/b/fileA.d"), Path("") }, - { Path("a/file.d"), Path("") }, - { Path("b/b/fileB.d"), Path("") }, - { Path("b/b/b/fileA.d"), Path("") }, - { Path("b/c/fileA.d"), Path("") }, + { NativePath("b/file.d"), NativePath("") }, + { NativePath("b/b/fileA.d"), NativePath("") }, + { NativePath("a/file.d"), NativePath("") }, + { NativePath("b/b/fileB.d"), NativePath("") }, + { NativePath("b/b/b/fileA.d"), NativePath("") }, + { NativePath("b/c/fileA.d"), NativePath("") }, ]; auto sorted = sort(sfs); SourceFile[] sortedSfs; foreach(sr; sorted) sortedSfs ~= sr; - assert(sortedSfs[0].structurePath == Path("a/file.d"), "1"); - assert(sortedSfs[1].structurePath == Path("b/b/b/fileA.d"), "2"); - assert(sortedSfs[2].structurePath == Path("b/b/fileA.d"), "3"); - assert(sortedSfs[3].structurePath == Path("b/b/fileB.d"), "4"); - assert(sortedSfs[4].structurePath == Path("b/c/fileA.d"), "5"); - assert(sortedSfs[5].structurePath == Path("b/file.d"), "6"); + assert(sortedSfs[0].structurePath == NativePath("a/file.d"), "1"); + assert(sortedSfs[1].structurePath == NativePath("b/b/b/fileA.d"), "2"); + assert(sortedSfs[2].structurePath == NativePath("b/b/fileA.d"), "3"); + assert(sortedSfs[3].structurePath == NativePath("b/b/fileB.d"), "4"); + assert(sortedSfs[4].structurePath == NativePath("b/c/fileA.d"), "5"); + assert(sortedSfs[5].structurePath == NativePath("b/file.d"), "6"); } } -private Path determineStructurePath(Path file_path, in ProjectGenerator.TargetInfo target) +private NativePath determineStructurePath(NativePath file_path, in ProjectGenerator.TargetInfo target) { foreach (p; target.packages) { if (file_path.startsWith(p.path)) - return Path(getPackageFileName(p.name)) ~ file_path.relativeTo(p.path); + return NativePath(getPackageFileName(p.name)) ~ file_path.relativeTo(p.path); } - return Path("misc/") ~ file_path.head; + return NativePath("misc/") ~ file_path.head; } private string getPackageFileName(string pack) diff --git a/source/dub/init.d b/source/dub/init.d index 578074a..a1caaf2 100644 --- a/source/dub/init.d +++ b/source/dub/init.d @@ -38,7 +38,7 @@ package recipe and the file format used to store it prior to writing it to disk. */ -void initPackage(Path root_path, string[string] deps, string type, +void initPackage(NativePath root_path, string[string] deps, string type, PackageFormat format, scope RecipeCallback recipe_callback = null) { import std.conv : to; @@ -92,7 +92,7 @@ alias RecipeCallback = void delegate(ref PackageRecipe, ref PackageFormat); -private void initMinimalPackage(Path root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) +private void initMinimalPackage(NativePath root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) { p.description = "A minimal D application."; pre_write_callback(); @@ -108,7 +108,7 @@ }); } -private void initVibeDPackage(Path root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) +private void initVibeDPackage(NativePath root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) { if ("vibe-d" !in p.buildSettings.dependencies) p.buildSettings.dependencies["vibe-d"] = Dependency("~>0.7.30"); @@ -139,7 +139,7 @@ }); } -private void initDeimosPackage(Path root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) +private void initDeimosPackage(NativePath root_path, ref PackageRecipe p, scope void delegate() pre_write_callback) { import dub.compilers.buildsettings : TargetType; @@ -153,7 +153,7 @@ createDirectory(root_path ~ "deimos"); } -private void writeGitignore(Path root_path, PackageRecipe p) +private void writeGitignore(NativePath root_path, PackageRecipe p) { write((root_path ~ ".gitignore").toNativeString(), q"{.dub diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index 7db4eda..341df84 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -30,14 +30,14 @@ } -private Path[] temporary_files; +private NativePath[] temporary_files; -Path getTempDir() +NativePath getTempDir() { - return Path(std.file.tempDir()); + return NativePath(std.file.tempDir()); } -Path getTempFile(string prefix, string extension = null) +NativePath getTempFile(string prefix, string extension = null) { import std.uuid : randomUUID; @@ -99,13 +99,13 @@ } } -bool isEmptyDir(Path p) { +bool isEmptyDir(NativePath p) { foreach(DirEntry e; dirEntries(p.toNativeString(), SpanMode.shallow)) return false; return true; } -bool isWritableDir(Path p, bool create_if_missing = false) +bool isWritableDir(NativePath p, bool create_if_missing = false) { import std.random; auto fname = p ~ format("__dub_write_test_%08X", uniform(0, uint.max)); @@ -116,7 +116,7 @@ return true; } -Json jsonFromFile(Path file, bool silent_fail = false) { +Json jsonFromFile(NativePath file, bool silent_fail = false) { if( silent_fail && !existsFile(file) ) return Json.emptyObject; auto f = openFile(file.toNativeString(), FileMode.read); scope(exit) f.close(); @@ -124,7 +124,7 @@ return parseJsonString(text, file.toNativeString()); } -Json jsonFromZip(Path zip, string filename) { +Json jsonFromZip(NativePath zip, string filename) { import std.zip : ZipArchive; auto f = openFile(zip, FileMode.read); ubyte[] b = new ubyte[cast(size_t)f.size]; @@ -135,7 +135,7 @@ return parseJsonString(text, zip.toNativeString~"/"~filename); } -void writeJsonFile(Path path, Json json) +void writeJsonFile(NativePath path, Json json) { auto f = openFile(path, FileMode.createTrunc); scope(exit) f.close(); @@ -143,7 +143,7 @@ } /// Performs a write->delete->rename sequence to atomically "overwrite" the destination file -void atomicWriteJsonFile(Path path, Json json) +void atomicWriteJsonFile(NativePath path, Json json) { import std.random : uniform; auto tmppath = path.parentPath ~ format("%s.%s.tmp", path.head, uniform(0, int.max)); @@ -163,7 +163,7 @@ return p[$-1] == '/'; } -bool existsDirectory(Path path) { +bool existsDirectory(NativePath path) { if( !existsFile(path) ) return false; auto fi = getFileInfo(path); return fi.isDirectory; @@ -265,7 +265,7 @@ } else assert(false); } /// ditto -void download(URL url, Path filename) +void download(URL url, NativePath filename) { download(url.toString(), filename.toNativeString()); } @@ -442,7 +442,7 @@ return ret.data; } -string determineModuleName(BuildSettings settings, Path file, Path base_path) +string determineModuleName(BuildSettings settings, NativePath file, NativePath base_path) { import std.algorithm : map; import std.array : array; @@ -452,7 +452,7 @@ if (!file.absolute) file = base_path ~ file; size_t path_skip = 0; - foreach (ipath; settings.importPaths.map!(p => Path(p))) { + foreach (ipath; settings.importPaths.map!(p => NativePath(p))) { if (!ipath.absolute) ipath = base_path ~ ipath; assert(!ipath.empty); if (file.startsWith(ipath) && ipath.bySegment.walkLength > path_skip) diff --git a/source/dub/internal/vibecompat/core/file.d b/source/dub/internal/vibecompat/core/file.d index 404cd87..26321d4 100644 --- a/source/dub/internal/vibecompat/core/file.d +++ b/source/dub/internal/vibecompat/core/file.d @@ -54,7 +54,7 @@ /** Opens a file stream with the specified mode. */ -RangeFile openFile(Path path, FileMode mode = FileMode.read) +RangeFile openFile(NativePath path, FileMode mode = FileMode.read) { string fmode; final switch(mode){ @@ -70,14 +70,14 @@ /// ditto RangeFile openFile(string path, FileMode mode = FileMode.read) { - return openFile(Path(path), mode); + return openFile(NativePath(path), mode); } /** Moves or renames a file. */ -void moveFile(Path from, Path to) +void moveFile(NativePath from, NativePath to) { moveFile(from.toNativeString(), to.toNativeString()); } @@ -93,8 +93,8 @@ Note that attributes and time stamps are currently not retained. Params: - from = Path of the source file - to = Path for the destination file + from = NativePath of the source file + to = NativePath for the destination file overwrite = If true, any file existing at the destination path will be overwritten. If this is false, an excpetion will be thrown should a file already exist at the destination path. @@ -102,7 +102,7 @@ Throws: An Exception if the copy operation fails for some reason. */ -void copyFile(Path from, Path to, bool overwrite = false) +void copyFile(NativePath from, NativePath to, bool overwrite = false) { enforce(existsFile(from), "Source file does not exist."); @@ -138,13 +138,13 @@ /// ditto void copyFile(string from, string to) { - copyFile(Path(from), Path(to)); + copyFile(NativePath(from), NativePath(to)); } version (Windows) extern(Windows) int CreateHardLinkW(in wchar* to, in wchar* from, void* attr=null); // guess whether 2 files are identical, ignores filename and content -private bool sameFile(Path a, Path b) +private bool sameFile(NativePath a, NativePath b) { version (Posix) { auto st_a = std.file.DirEntry(a.toNativeString).statBuf; @@ -159,7 +159,7 @@ /** Creates a hardlink. */ -void hardLinkFile(Path from, Path to, bool overwrite = false) +void hardLinkFile(NativePath from, NativePath to, bool overwrite = false) { if (existsFile(to)) { enforce(overwrite, "Destination file already exists."); @@ -189,7 +189,7 @@ /** Removes a file */ -void removeFile(Path path) +void removeFile(NativePath path) { removeFile(path.toNativeString()); } @@ -201,7 +201,7 @@ /** Checks if a file exists */ -bool existsFile(Path path) { +bool existsFile(NativePath path) { return existsFile(path.toNativeString()); } /// ditto @@ -214,7 +214,7 @@ Returns false if the file does not exist. */ -FileInfo getFileInfo(Path path) +FileInfo getFileInfo(NativePath path) { auto ent = std.file.DirEntry(path.toNativeString()); return makeFileInfo(ent); @@ -222,26 +222,26 @@ /// ditto FileInfo getFileInfo(string path) { - return getFileInfo(Path(path)); + return getFileInfo(NativePath(path)); } /** Creates a new directory. */ -void createDirectory(Path path) +void createDirectory(NativePath path) { mkdir(path.toNativeString()); } /// ditto void createDirectory(string path) { - createDirectory(Path(path)); + createDirectory(NativePath(path)); } /** Enumerates all files in the specified directory. */ -void listDirectory(Path path, scope bool delegate(FileInfo info) del) +void listDirectory(NativePath path, scope bool delegate(FileInfo info) del) { foreach( DirEntry ent; dirEntries(path.toNativeString(), SpanMode.shallow) ) if( !del(makeFileInfo(ent)) ) @@ -250,10 +250,10 @@ /// ditto void listDirectory(string path, scope bool delegate(FileInfo info) del) { - listDirectory(Path(path), del); + listDirectory(NativePath(path), del); } /// ditto -int delegate(scope int delegate(ref FileInfo)) iterateDirectory(Path path) +int delegate(scope int delegate(ref FileInfo)) iterateDirectory(NativePath path) { int iterator(scope int delegate(ref FileInfo) del){ int ret = 0; @@ -268,16 +268,16 @@ /// ditto int delegate(scope int delegate(ref FileInfo)) iterateDirectory(string path) { - return iterateDirectory(Path(path)); + return iterateDirectory(NativePath(path)); } /** Returns the current working directory. */ -Path getWorkingDirectory() +NativePath getWorkingDirectory() { - return Path(std.file.getcwd()); + return NativePath(std.file.getcwd()); } diff --git a/source/dub/internal/vibecompat/inet/path.d b/source/dub/internal/vibecompat/inet/path.d index 0292d3c..047ac5d 100644 --- a/source/dub/internal/vibecompat/inet/path.d +++ b/source/dub/internal/vibecompat/inet/path.d @@ -18,6 +18,9 @@ import std.string; +deprecated("Use NativePath instead.") +alias Path = NativePath; + /** Represents an absolute or relative file system path. @@ -25,7 +28,7 @@ are done to disallow invalid operations such as concatenating two absolute paths. It also validates path strings and allows for easy checking of malicious relative paths. */ -struct Path { +struct NativePath { private { immutable(PathEntry)[] m_nodes; bool m_absolute = false; @@ -36,7 +39,7 @@ alias bySegment = nodes; - /// Constructs a Path object by parsing a path string. + /// Constructs a NativePath object by parsing a path string. this(string pathstr) { m_nodes = splitPath(pathstr); @@ -113,7 +116,7 @@ return ret.data; } - /// Converts the Path object to a native path string (backslash as path separator on Windows). + /// Converts the NativePath object to a native path string (backslash as path separator on Windows). string toNativeString() const { if (m_nodes.empty) { @@ -144,7 +147,7 @@ } /// Tests if `rhs` is an anchestor or the same as this path. - bool startsWith(const Path rhs) const { + bool startsWith(const NativePath rhs) const { if( rhs.m_nodes.length > m_nodes.length ) return false; foreach( i; 0 .. rhs.m_nodes.length ) if( m_nodes[i] != rhs.m_nodes[i] ) @@ -153,7 +156,7 @@ } /// Computes the relative path from `parentPath` to this path. - Path relativeTo(const Path parentPath) const { + NativePath relativeTo(const NativePath parentPath) const { assert(this.absolute && parentPath.absolute, "Determining relative path between non-absolute paths."); version(Windows){ // a path such as ..\C:\windows is not valid, so force the path to stay absolute in this case @@ -169,11 +172,11 @@ nup++; } assert(m_nodes.length >= parentPath.length - nup); - Path ret = Path(null, false); + NativePath ret = NativePath(null, false); assert(m_nodes.length >= parentPath.length - nup); ret.m_endsWithSlash = true; foreach( i; 0 .. nup ) ret ~= ".."; - ret ~= Path(m_nodes[parentPath.length-nup .. $], false); + ret ~= NativePath(m_nodes[parentPath.length-nup .. $], false); ret.m_endsWithSlash = this.m_endsWithSlash; return ret; } @@ -182,7 +185,7 @@ @property ref immutable(PathEntry) head() const { enforce(m_nodes.length > 0, "Getting head of empty path."); return m_nodes[$-1]; } /// The parent path - @property Path parentPath() const { return this[0 .. length-1]; } + @property NativePath parentPath() const { return this[0 .. length-1]; } /// The ist of path entries of which this path is composed @property immutable(PathEntry)[] nodes() const { return m_nodes; } @@ -202,16 +205,16 @@ @property bool external() const { return !m_absolute && m_nodes.length > 0 && m_nodes[0].m_name == ".."; } ref immutable(PathEntry) opIndex(size_t idx) const { return m_nodes[idx]; } - Path opSlice(size_t start, size_t end) const { - auto ret = Path(m_nodes[start .. end], start == 0 ? absolute : false); + NativePath opSlice(size_t start, size_t end) const { + auto ret = NativePath(m_nodes[start .. end], start == 0 ? absolute : false); if( end == m_nodes.length ) ret.m_endsWithSlash = m_endsWithSlash; return ret; } size_t opDollar(int dim)() const if(dim == 0) { return m_nodes.length; } - Path opBinary(string OP)(const Path rhs) const if( OP == "~" ) { - Path ret; + NativePath opBinary(string OP)(const NativePath rhs) const if( OP == "~" ) { + NativePath ret; ret.m_nodes = m_nodes; ret.m_absolute = m_absolute; ret.m_endsWithSlash = rhs.m_endsWithSlash; @@ -234,14 +237,14 @@ return ret; } - Path opBinary(string OP)(string rhs) const if( OP == "~" ) { assert(rhs.length > 0, "Cannot append empty path string."); return opBinary!"~"(Path(rhs)); } - Path opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { assert(rhs.toString().length > 0, "Cannot append empty path string."); return opBinary!"~"(Path(rhs)); } - void opOpAssign(string OP)(string rhs) if( OP == "~" ) { assert(rhs.length > 0, "Cannot append empty path string."); opOpAssign!"~"(Path(rhs)); } - void opOpAssign(string OP)(PathEntry rhs) if( OP == "~" ) { assert(rhs.toString().length > 0, "Cannot append empty path string."); opOpAssign!"~"(Path(rhs)); } - void opOpAssign(string OP)(Path rhs) if( OP == "~" ) { auto p = this ~ rhs; m_nodes = p.m_nodes; m_endsWithSlash = rhs.m_endsWithSlash; } + NativePath opBinary(string OP)(string rhs) const if( OP == "~" ) { assert(rhs.length > 0, "Cannot append empty path string."); return opBinary!"~"(NativePath(rhs)); } + NativePath opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { assert(rhs.toString().length > 0, "Cannot append empty path string."); return opBinary!"~"(NativePath(rhs)); } + void opOpAssign(string OP)(string rhs) if( OP == "~" ) { assert(rhs.length > 0, "Cannot append empty path string."); opOpAssign!"~"(NativePath(rhs)); } + void opOpAssign(string OP)(PathEntry rhs) if( OP == "~" ) { assert(rhs.toString().length > 0, "Cannot append empty path string."); opOpAssign!"~"(NativePath(rhs)); } + void opOpAssign(string OP)(NativePath rhs) if( OP == "~" ) { auto p = this ~ rhs; m_nodes = p.m_nodes; m_endsWithSlash = rhs.m_endsWithSlash; } /// Tests two paths for equality using '=='. - bool opEquals(ref const Path rhs) const { + bool opEquals(ref const NativePath rhs) const { if( m_absolute != rhs.m_absolute ) return false; if( m_endsWithSlash != rhs.m_endsWithSlash ) return false; if( m_nodes.length != rhs.length ) return false; @@ -251,9 +254,9 @@ return true; } /// ditto - bool opEquals(const Path other) const { return opEquals(other); } + bool opEquals(const NativePath other) const { return opEquals(other); } - int opCmp(ref const Path rhs) const { + int opCmp(ref const NativePath rhs) const { if( m_absolute != rhs.m_absolute ) return cast(int)m_absolute - cast(int)rhs.m_absolute; foreach( i; 0 .. min(m_nodes.length, rhs.m_nodes.length) ) if( m_nodes[i] != rhs.m_nodes[i] ) @@ -290,7 +293,7 @@ @property string name() const { return m_name; } - Path opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { return Path([this, rhs], false); } + NativePath opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { return NativePath([this, rhs], false); } bool opEquals(ref const PathEntry rhs) const { return m_name == rhs.m_name; } bool opEquals(PathEntry rhs) const { return m_name == rhs.m_name; } @@ -309,8 +312,8 @@ /// Joins two path strings. subpath must be relative. string joinPath(string basepath, string subpath) { - Path p1 = Path(basepath); - Path p2 = Path(subpath); + NativePath p1 = NativePath(basepath); + NativePath p2 = NativePath(subpath); return (p1 ~ p2).toString(); } @@ -353,13 +356,13 @@ unittest { - Path p; + NativePath p; assert(p.toNativeString() == "."); p.endsWithSlash = true; version(Windows) assert(p.toNativeString() == ".\\"); else assert(p.toNativeString() == "./"); - p = Path("test/"); + p = NativePath("test/"); version(Windows) assert(p.toNativeString() == "test\\"); else assert(p.toNativeString() == "test/"); p.endsWithSlash = false; @@ -370,7 +373,7 @@ { { auto unc = "\\\\server\\share\\path"; - auto uncp = Path(unc); + auto uncp = NativePath(unc); uncp.normalize(); version(Windows) assert(uncp.toNativeString() == unc); assert(uncp.absolute); @@ -379,7 +382,7 @@ { auto abspath = "/test/path/"; - auto abspathp = Path(abspath); + auto abspathp = NativePath(abspath); assert(abspathp.toString() == abspath); version(Windows) {} else assert(abspathp.toNativeString() == abspath); assert(abspathp.absolute); @@ -391,7 +394,7 @@ { auto relpath = "test/path/"; - auto relpathp = Path(relpath); + auto relpathp = NativePath(relpath); assert(relpathp.toString() == relpath); version(Windows) assert(relpathp.toNativeString() == "test\\path\\"); else assert(relpathp.toNativeString() == relpath); @@ -404,7 +407,7 @@ { auto winpath = "C:\\windows\\test"; - auto winpathp = Path(winpath); + auto winpathp = NativePath(winpath); version(Windows) { assert(winpathp.toString() == "C:/windows/test", winpathp.toString()); assert(winpathp.toNativeString() == winpath); @@ -422,7 +425,7 @@ { auto dotpath = "/test/../test2/././x/y"; - auto dotpathp = Path(dotpath); + auto dotpathp = NativePath(dotpath); assert(dotpathp.toString() == "/test/../test2/././x/y"); dotpathp.normalize(); assert(dotpathp.toString() == "/test2/x/y"); @@ -430,7 +433,7 @@ { auto dotpath = "/test/..////test2//./x/y"; - auto dotpathp = Path(dotpath); + auto dotpathp = NativePath(dotpath); assert(dotpathp.toString() == "/test/..////test2//./x/y"); dotpathp.normalize(); assert(dotpathp.toString() == "/test2/x/y"); @@ -438,46 +441,46 @@ { auto parentpath = "/path/to/parent"; - auto parentpathp = Path(parentpath); + auto parentpathp = NativePath(parentpath); auto subpath = "/path/to/parent/sub/"; - auto subpathp = Path(subpath); + auto subpathp = NativePath(subpath); auto subpath_rel = "sub/"; assert(subpathp.relativeTo(parentpathp).toString() == subpath_rel); auto subfile = "/path/to/parent/child"; - auto subfilep = Path(subfile); + auto subfilep = NativePath(subfile); auto subfile_rel = "child"; assert(subfilep.relativeTo(parentpathp).toString() == subfile_rel); } { // relative paths across Windows devices are not allowed version (Windows) { - auto p1 = Path("\\\\server\\share"); assert(p1.absolute); - auto p2 = Path("\\\\server\\othershare"); assert(p2.absolute); - auto p3 = Path("\\\\otherserver\\share"); assert(p3.absolute); - auto p4 = Path("C:\\somepath"); assert(p4.absolute); - auto p5 = Path("C:\\someotherpath"); assert(p5.absolute); - auto p6 = Path("D:\\somepath"); assert(p6.absolute); - assert(p4.relativeTo(p5) == Path("../somepath")); - assert(p4.relativeTo(p6) == Path("C:\\somepath")); - assert(p4.relativeTo(p1) == Path("C:\\somepath")); - assert(p1.relativeTo(p2) == Path("../share")); - assert(p1.relativeTo(p3) == Path("\\\\server\\share")); - assert(p1.relativeTo(p4) == Path("\\\\server\\share")); + auto p1 = NativePath("\\\\server\\share"); assert(p1.absolute); + auto p2 = NativePath("\\\\server\\othershare"); assert(p2.absolute); + auto p3 = NativePath("\\\\otherserver\\share"); assert(p3.absolute); + auto p4 = NativePath("C:\\somepath"); assert(p4.absolute); + auto p5 = NativePath("C:\\someotherpath"); assert(p5.absolute); + auto p6 = NativePath("D:\\somepath"); assert(p6.absolute); + assert(p4.relativeTo(p5) == NativePath("../somepath")); + assert(p4.relativeTo(p6) == NativePath("C:\\somepath")); + assert(p4.relativeTo(p1) == NativePath("C:\\somepath")); + assert(p1.relativeTo(p2) == NativePath("../share")); + assert(p1.relativeTo(p3) == NativePath("\\\\server\\share")); + assert(p1.relativeTo(p4) == NativePath("\\\\server\\share")); } } } unittest { - assert(Path("/foo/bar/baz").relativeTo(Path("/foo")).toString == "bar/baz"); - assert(Path("/foo/bar/baz/").relativeTo(Path("/foo")).toString == "bar/baz/"); - assert(Path("/foo/bar").relativeTo(Path("/foo")).toString == "bar"); - assert(Path("/foo/bar/").relativeTo(Path("/foo")).toString == "bar/"); - assert(Path("/foo").relativeTo(Path("/foo/bar")).toString() == ".."); - assert(Path("/foo/").relativeTo(Path("/foo/bar")).toString() == "../"); - assert(Path("/foo/baz").relativeTo(Path("/foo/bar/baz")).toString() == "../../baz"); - assert(Path("/foo/baz/").relativeTo(Path("/foo/bar/baz")).toString() == "../../baz/"); - assert(Path("/foo/").relativeTo(Path("/foo/bar/baz")).toString() == "../../"); - assert(Path("/foo/").relativeTo(Path("/foo/bar/baz/mumpitz")).toString() == "../../../"); - assert(Path("/foo").relativeTo(Path("/foo")).toString() == ""); - assert(Path("/foo/").relativeTo(Path("/foo")).toString() == ""); + assert(NativePath("/foo/bar/baz").relativeTo(NativePath("/foo")).toString == "bar/baz"); + assert(NativePath("/foo/bar/baz/").relativeTo(NativePath("/foo")).toString == "bar/baz/"); + assert(NativePath("/foo/bar").relativeTo(NativePath("/foo")).toString == "bar"); + assert(NativePath("/foo/bar/").relativeTo(NativePath("/foo")).toString == "bar/"); + assert(NativePath("/foo").relativeTo(NativePath("/foo/bar")).toString() == ".."); + assert(NativePath("/foo/").relativeTo(NativePath("/foo/bar")).toString() == "../"); + assert(NativePath("/foo/baz").relativeTo(NativePath("/foo/bar/baz")).toString() == "../../baz"); + assert(NativePath("/foo/baz/").relativeTo(NativePath("/foo/bar/baz")).toString() == "../../baz/"); + assert(NativePath("/foo/").relativeTo(NativePath("/foo/bar/baz")).toString() == "../../"); + assert(NativePath("/foo/").relativeTo(NativePath("/foo/bar/baz/mumpitz")).toString() == "../../../"); + assert(NativePath("/foo").relativeTo(NativePath("/foo")).toString() == ""); + assert(NativePath("/foo/").relativeTo(NativePath("/foo")).toString() == ""); } diff --git a/source/dub/internal/vibecompat/inet/url.d b/source/dub/internal/vibecompat/inet/url.d index 9115c9c..6016af5 100644 --- a/source/dub/internal/vibecompat/inet/url.d +++ b/source/dub/internal/vibecompat/inet/url.d @@ -27,7 +27,7 @@ private { string m_schema; string m_pathString; - Path m_path; + NativePath m_path; string m_host; ushort m_port; string m_username; @@ -37,7 +37,7 @@ } /// Constructs a new URL object from its components. - this(string schema, string host, ushort port, Path path) + this(string schema, string host, ushort port, NativePath path) { m_schema = schema; m_host = host; @@ -46,7 +46,7 @@ m_pathString = path.toString(); } /// ditto - this(string schema, Path path) + this(string schema, NativePath path) { this(schema, null, 0, path); } @@ -124,9 +124,9 @@ @property string pathString() const { return m_pathString; } /// The path part of the URL - @property Path path() const { return m_path; } + @property NativePath path() const { return m_path; } /// ditto - @property void path(Path p) + @property void path(NativePath p) { m_path = p; auto pstr = p.toString(); @@ -193,7 +193,7 @@ } m_pathString = str; - m_path = Path(decode(str)); + m_path = NativePath(decode(str)); } /// The URL to the parent path with query string and anchor stripped. @@ -239,9 +239,9 @@ return path.startsWith(rhs.m_path); } - URL opBinary(string OP)(Path rhs) const if( OP == "~" ) { return URL(m_schema, m_host, m_port, m_path ~ rhs); } + URL opBinary(string OP)(NativePath rhs) const if( OP == "~" ) { return URL(m_schema, m_host, m_port, m_path ~ rhs); } URL opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { return URL(m_schema, m_host, m_port, m_path ~ rhs); } - void opOpAssign(string OP)(Path rhs) if( OP == "~" ) { m_path ~= rhs; } + void opOpAssign(string OP)(NativePath rhs) if( OP == "~" ) { m_path ~= rhs; } void opOpAssign(string OP)(PathEntry rhs) if( OP == "~" ) { m_path ~= rhs; } /// Tests two URLs for equality using '=='. @@ -266,7 +266,7 @@ auto url = URL.parse("https://www.example.net/index.html"); assert(url.schema == "https", url.schema); assert(url.host == "www.example.net", url.host); - assert(url.path == Path("/index.html"), url.path.toString()); + assert(url.path == NativePath("/index.html"), url.path.toString()); url = URL.parse("http://jo.doe:password@sub.www.example.net:4711/sub2/index.html?query#anchor"); assert(url.schema == "http", url.schema); @@ -278,9 +278,9 @@ assert(url.queryString == "query", url.queryString); assert(url.anchor == "anchor", url.anchor); - url = URL("http://localhost")~Path("packages"); + url = URL("http://localhost")~NativePath("packages"); assert(url.toString() == "http://localhost/packages", url.toString()); - url = URL("http://localhost/")~Path("packages"); + url = URL("http://localhost/")~NativePath("packages"); assert(url.toString() == "http://localhost/packages", url.toString()); } diff --git a/source/dub/package_.d b/source/dub/package_.d index 5197a45..8a2e6f6 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -60,8 +60,8 @@ */ class Package { private { - Path m_path; - Path m_infoFile; + NativePath m_path; + NativePath m_infoFile; PackageRecipe m_info; PackageRecipe m_rawRecipe; Package m_parentPackage; @@ -79,7 +79,7 @@ instead of the one declared in the package recipe, or the one determined by invoking the VCS (GIT currently). */ - this(Json json_recipe, Path root = Path(), Package parent = null, string version_override = "") + this(Json json_recipe, NativePath root = NativePath(), Package parent = null, string version_override = "") { import dub.recipe.json; @@ -88,7 +88,7 @@ this(recipe, root, parent, version_override); } /// ditto - this(PackageRecipe recipe, Path root = Path(), Package parent = null, string version_override = "") + this(PackageRecipe recipe, NativePath root = NativePath(), Package parent = null, string version_override = "") { // save the original recipe m_rawRecipe = recipe.clone; @@ -128,13 +128,13 @@ Returns the full path to the package file, if any was found. Otherwise returns an empty path. */ - static Path findPackageFile(Path directory) + static NativePath findPackageFile(NativePath directory) { foreach (file; packageInfoFiles) { auto filename = directory ~ file.filename; if (existsFile(filename)) return filename; } - return Path.init; + return NativePath.init; } /** Constructs a `Package` using a package that is physically present on the local file system. @@ -149,7 +149,7 @@ instead of the one declared in the package recipe, or the one determined by invoking the VCS (GIT currently). */ - static Package load(Path root, Path recipe_file = Path.init, Package parent = null, string version_override = "") + static Package load(NativePath root, NativePath recipe_file = NativePath.init, Package parent = null, string version_override = "") { import dub.recipe.io; @@ -183,7 +183,7 @@ Note that this can be empty for packages that are not stored in the local file system. */ - @property Path path() const { return m_path; } + @property NativePath path() const { return m_path; } /** Accesses the version associated with this package. @@ -218,7 +218,7 @@ Note that this can be empty for packages that are not stored in the local file system. */ - @property Path recipePath() const { return m_infoFile; } + @property NativePath recipePath() const { return m_infoFile; } /** Returns the base package of this package. @@ -265,7 +265,7 @@ m_infoFile = m_path ~ defaultPackageFilename; } /// ditto - void storeInfo(Path path) + void storeInfo(NativePath path) const { enforce(!version_.isUnknown, "Trying to store a package with an 'unknown' version, this is not supported."); auto filename = path ~ defaultPackageFilename; @@ -650,7 +650,7 @@ if( !existsFile(p) ) continue; foreach(fil; ["app.d", "main.d", pkg_name ~ "/main.d", pkg_name ~ "/" ~ "app.d"]){ if( existsFile(p ~ fil) ) { - app_main_file = (Path(sf) ~ fil).toNativeString(); + app_main_file = (NativePath(sf) ~ fil).toNativeString(); break; } } @@ -702,7 +702,7 @@ } } -private string determineVersionFromSCM(Path path) +private string determineVersionFromSCM(NativePath path) { // On Windows, which is slow at running external processes, // cache the version numbers that are determined using @@ -750,7 +750,7 @@ // determines the version of a package that is stored in a GIT working copy // by invoking the "git" executable -private string determineVersionWithGIT(Path path) +private string determineVersionWithGIT(NativePath path) { import std.process; import dub.semver; diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 042e3e3..c210b2b 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -31,13 +31,13 @@ class PackageManager { private { Repository[LocalPackageType] m_repositories; - Path[] m_searchPath; + NativePath[] m_searchPath; Package[] m_packages; Package[] m_temporaryPackages; bool m_disableDefaultSearchPaths = false; } - this(Path user_path, Path system_path, bool refresh_packages = true) + this(NativePath user_path, NativePath system_path, bool refresh_packages = true) { m_repositories[LocalPackageType.user] = Repository(user_path); m_repositories[LocalPackageType.system] = Repository(system_path); @@ -46,14 +46,14 @@ /** Gets/sets the list of paths to search for local packages. */ - @property void searchPath(Path[] paths) + @property void searchPath(NativePath[] paths) { if (paths == m_searchPath) return; m_searchPath = paths.dup; refresh(false); } /// ditto - @property const(Path)[] searchPath() const { return m_searchPath; } + @property const(NativePath)[] searchPath() const { return m_searchPath; } /** Disables searching DUB's predefined search paths. */ @@ -66,15 +66,15 @@ /** Returns the effective list of search paths, including default ones. */ - @property const(Path)[] completeSearchPath() + @property const(NativePath)[] completeSearchPath() const { - auto ret = appender!(Path[])(); - ret.put(cast(Path[])m_searchPath); // work around Phobos 17251 + auto ret = appender!(NativePath[])(); + ret.put(cast(NativePath[])m_searchPath); // work around Phobos 17251 if (!m_disableDefaultSearchPaths) { - ret.put(cast(Path[])m_repositories[LocalPackageType.user].searchPath); - ret.put(cast(Path)m_repositories[LocalPackageType.user].packagePath); - ret.put(cast(Path[])m_repositories[LocalPackageType.system].searchPath); - ret.put(cast(Path)m_repositories[LocalPackageType.system].packagePath); + ret.put(cast(NativePath[])m_repositories[LocalPackageType.user].searchPath); + ret.put(cast(NativePath)m_repositories[LocalPackageType.user].packagePath); + ret.put(cast(NativePath[])m_repositories[LocalPackageType.system].searchPath); + ret.put(cast(NativePath)m_repositories[LocalPackageType.system].packagePath); } return ret.data; } @@ -127,7 +127,7 @@ } /// ditto - Package getPackage(string name, Version ver, Path path) + Package getPackage(string name, Version ver, NativePath path) { auto ret = getPackage(name, path); if (!ret || ret.version_ != ver) return null; @@ -135,13 +135,13 @@ } /// ditto - Package getPackage(string name, string ver, Path path) + Package getPackage(string name, string ver, NativePath path) { return getPackage(name, Version(ver), path); } /// ditto - Package getPackage(string name, Path path) + Package getPackage(string name, NativePath path) { foreach( p; getPackageIterator(name) ) if (p.path.startsWith(path)) @@ -165,14 +165,14 @@ the package gets loaded and cached for the next call to this function. Params: - path = Path to the root directory of the package + path = NativePath to the root directory of the package recipe_path = Optional path to the recipe file of the package allow_sub_packages = Also return a sub package if it resides in the given folder Returns: The packages loaded from the given path Throws: Throws an exception if no package can be loaded */ - Package getOrLoadPackage(Path path, Path recipe_path = Path.init, bool allow_sub_packages = false) + Package getOrLoadPackage(NativePath path, NativePath recipe_path = NativePath.init, bool allow_sub_packages = false) { path.endsWithSlash = true; foreach (p; getPackageIterator()) @@ -244,10 +244,10 @@ By default, managed folders are "~/.dub/packages" and "/var/lib/dub/packages". */ - bool isManagedPath(Path path) + bool isManagedPath(NativePath path) const { foreach (rep; m_repositories) { - Path rpath = rep.packagePath; + NativePath rpath = rep.packagePath; if (path.startsWith(rpath)) return true; } @@ -313,7 +313,7 @@ writeLocalPackageOverridesFile(scope_); } /// ditto - void addOverride(LocalPackageType scope_, string package_, Dependency version_spec, Path target) + void addOverride(LocalPackageType scope_, string package_, Dependency version_spec, NativePath target) { m_repositories[scope_].overrides ~= PackageOverride(package_, version_spec, target); writeLocalPackageOverridesFile(scope_); @@ -336,7 +336,7 @@ /// Extracts the package supplied as a path to it's zip file to the /// destination and sets a version field in the package description. - Package storeFetchedPackage(Path zip_file_path, Json package_info, Path destination) + Package storeFetchedPackage(NativePath zip_file_path, Json package_info, NativePath destination) { import std.range : walkLength; @@ -363,10 +363,10 @@ logDebug("Extracting from zip."); // In a github zip, the actual contents are in a subfolder - alias PSegment = typeof(Path.init.head); + alias PSegment = typeof(NativePath.init.head); PSegment[] zip_prefix; outer: foreach(ArchiveMember am; archive.directory) { - auto path = Path(am.name).bySegment.array; + auto path = NativePath(am.name).bySegment.array; foreach (fil; packageInfoFiles) if (path.length == 2 && path[$-1].toString == fil.filename) { zip_prefix = path[0 .. $-1]; @@ -376,11 +376,11 @@ logDebug("zip root folder: %s", zip_prefix); - Path getCleanedPath(string fileName) { - auto path = Path(fileName); - if (zip_prefix.length && !path.bySegment.startsWith(zip_prefix)) return Path.init; + NativePath getCleanedPath(string fileName) { + auto path = NativePath(fileName); + if (zip_prefix.length && !path.bySegment.startsWith(zip_prefix)) return NativePath.init; static if (is(typeof(path[0 .. 1]))) return path[zip_prefix.length .. $]; - else return Path(path.bySegment.array[zip_prefix.length .. $]); + else return NativePath(path.bySegment.array[zip_prefix.length .. $]); } static void setAttributes(string path, ArchiveMember am) @@ -421,7 +421,7 @@ logDebug("%s file(s) copied.", to!string(countFiles)); // overwrite dub.json (this one includes a version field) - auto pack = Package.load(destination, Path.init, null, package_info["version"].get!string); + auto pack = Package.load(destination, NativePath.init, null, package_info["version"].get!string); if (pack.recipePath.head != defaultPackageFilename) // Storeinfo saved a default file, this could be different to the file from the zip. @@ -468,7 +468,7 @@ remove(pack); } - Package addLocalPackage(Path path, string verName, LocalPackageType type) + Package addLocalPackage(NativePath path, string verName, LocalPackageType type) { path.endsWithSlash = true; auto pack = Package.load(path); @@ -494,7 +494,7 @@ return pack; } - void removeLocalPackage(Path path, LocalPackageType type) + void removeLocalPackage(NativePath path, LocalPackageType type) { path.endsWithSlash = true; @@ -518,14 +518,14 @@ } /// For the given type add another path where packages will be looked up. - void addSearchPath(Path path, LocalPackageType type) + void addSearchPath(NativePath path, LocalPackageType type) { m_repositories[type].searchPath ~= path; writeLocalPackageList(type); } /// Removes a search path from the given type. - void removeSearchPath(Path path, LocalPackageType type) + void removeSearchPath(NativePath path, LocalPackageType type) { m_repositories[type].searchPath = m_repositories[type].searchPath.filter!(p => p != path)().array(); writeLocalPackageList(type); @@ -538,9 +538,9 @@ // load locally defined packages void scanLocalPackages(LocalPackageType type) { - Path list_path = m_repositories[type].packagePath; + NativePath list_path = m_repositories[type].packagePath; Package[] packs; - Path[] paths; + NativePath[] paths; if (!m_disableDefaultSearchPaths) try { auto local_package_file = list_path ~ LocalPackagesFilename; logDiagnostic("Looking for local package map at %s", local_package_file.toNativeString()); @@ -551,7 +551,7 @@ foreach( pentry; packlist ){ try { auto name = pentry["name"].get!string; - auto path = Path(pentry["path"].get!string); + auto path = NativePath(pentry["path"].get!string); if (name == "*") { paths ~= path; } else { @@ -600,7 +600,7 @@ auto old_packages = m_packages; // rescan the system and user package folder - void scanPackageFolder(Path path) + void scanPackageFolder(NativePath path) { if( path.existsDirectory() ){ logDebug("iterating dir %s", path.toNativeString()); @@ -657,7 +657,7 @@ ovr.package_ = entry["name"].get!string; ovr.version_ = Dependency(entry["version"].get!string); if (auto pv = "targetVersion" in entry) ovr.targetVersion = Version(pv.get!string); - if (auto pv = "targetPath" in entry) ovr.targetPath = Path(pv.get!string); + if (auto pv = "targetPath" in entry) ovr.targetPath = NativePath(pv.get!string); m_repositories[type].overrides ~= ovr; } } @@ -677,18 +677,18 @@ string[] ignored_files = []; SHA1 sha1; foreach(file; dirEntries(pack.path.toNativeString(), SpanMode.depth)) { - if(file.isDir && ignored_directories.canFind(Path(file.name).head.toString())) + if(file.isDir && ignored_directories.canFind(NativePath(file.name).head.toString())) continue; - else if(ignored_files.canFind(Path(file.name).head.toString())) + else if(ignored_files.canFind(NativePath(file.name).head.toString())) continue; - sha1.put(cast(ubyte[])Path(file.name).head.toString()); + sha1.put(cast(ubyte[])NativePath(file.name).head.toString()); if(file.isDir) { - logDebug("Hashed directory name %s", Path(file.name).head); + logDebug("Hashed directory name %s", NativePath(file.name).head); } else { - sha1.put(openFile(Path(file.name)).readAll()); - logDebug("Hashed file contents from %s", Path(file.name).head); + sha1.put(openFile(NativePath(file.name)).readAll()); + logDebug("Hashed file contents from %s", NativePath(file.name).head); } } auto hash = sha1.finish(); @@ -715,7 +715,7 @@ newlist ~= entry; } - Path path = m_repositories[type].packagePath; + NativePath path = m_repositories[type].packagePath; if( !existsDirectory(path) ) mkdirRecurse(path.toNativeString()); writeJsonFile(path ~ LocalPackagesFilename, Json(newlist)); } @@ -749,7 +749,7 @@ Package sp; if (spr.path.length) { - auto p = Path(spr.path); + auto p = NativePath(spr.path); p.normalize(); enforce(!p.absolute, "Sub package paths must be sub paths of the parent package."); auto path = pack.path ~ p; @@ -757,7 +757,7 @@ logError("Package %s declared a sub-package, definition file is missing: %s", pack.name, path.toNativeString()); continue; } - sp = Package.load(path, Path.init, pack); + sp = Package.load(path, NativePath.init, pack); } else sp = new Package(spr.recipe, pack.path, pack); // Add the subpackage. @@ -776,7 +776,7 @@ string package_; Dependency version_; Version targetVersion; - Path targetPath; + NativePath targetPath; this(string package_, Dependency version_, Version target_version) { @@ -785,7 +785,7 @@ this.targetVersion = target_version; } - this(string package_, Dependency version_, Path target_path) + this(string package_, Dependency version_, NativePath target_path) { this.package_ = package_; this.version_ = version_; @@ -803,13 +803,13 @@ private struct Repository { - Path path; - Path packagePath; - Path[] searchPath; + NativePath path; + NativePath packagePath; + NativePath[] searchPath; Package[] localPackages; PackageOverride[] overrides; - this(Path path) + this(NativePath path) { this.path = path; this.packagePath = path ~"packages/"; diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index 8336b92..44ddbcf 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -59,7 +59,7 @@ pre_release: If true, matches the latest pre-release version. Otherwise prefers stable versions. */ - void fetchPackage(Path path, string package_id, Dependency dep, bool pre_release); + void fetchPackage(NativePath path, string package_id, Dependency dep, bool pre_release); /** Retrieves only the recipe of a particular package. @@ -88,10 +88,10 @@ */ class FileSystemPackageSupplier : PackageSupplier { private { - Path m_path; + NativePath m_path; } - this(Path root) { m_path = root; } + this(NativePath root) { m_path = root; } override @property string description() { return "file repository at "~m_path.toNativeString(); } @@ -99,7 +99,7 @@ { Version[] ret; foreach (DirEntry d; dirEntries(m_path.toNativeString(), package_id~"*", SpanMode.shallow)) { - Path p = Path(d.name); + NativePath p = NativePath(d.name); logDebug("Entry: %s", p); enforce(to!string(p.head)[$-4..$] == ".zip"); auto vers = p.head.toString()[package_id.length+1..$-4]; @@ -110,7 +110,7 @@ return ret; } - void fetchPackage(Path path, string packageId, Dependency dep, bool pre_release) + void fetchPackage(NativePath path, string packageId, Dependency dep, bool pre_release) { enforce(path.absolute); logInfo("Storing package '"~packageId~"', version requirements: %s", dep); @@ -131,9 +131,9 @@ return null; } - private Path bestPackageFile(string packageId, Dependency dep, bool pre_release) + private NativePath bestPackageFile(string packageId, Dependency dep, bool pre_release) { - Path toPath(Version ver) { + NativePath toPath(Version ver) { return m_path ~ (packageId ~ "-" ~ ver.toString() ~ ".zip"); } auto versions = getVersions(packageId).filter!(v => dep.matches(v)).array; @@ -183,14 +183,14 @@ return ret; } - void fetchPackage(Path path, string packageId, Dependency dep, bool pre_release) + void fetchPackage(NativePath path, string packageId, Dependency dep, bool pre_release) { import std.array : replace; Json best = getBestPackage(packageId, dep, pre_release); if (best.type == Json.Type.null_) return; auto vers = best["version"].get!string; - auto url = m_registryUrl ~ Path(PackagesPath~"/"~packageId~"/"~vers~".zip"); + auto url = m_registryUrl ~ NativePath(PackagesPath~"/"~packageId~"/"~vers~".zip"); logDiagnostic("Downloading from '%s'", url); foreach(i; 0..3) { try{ @@ -222,7 +222,7 @@ m_metadataCache.remove(packageId); } - auto url = m_registryUrl ~ Path(PackagesPath ~ "/" ~ packageId ~ ".json"); + auto url = m_registryUrl ~ NativePath(PackagesPath ~ "/" ~ packageId ~ ".json"); logDebug("Downloading metadata for %s", packageId); logDebug("Getting from %s", url); @@ -309,7 +309,7 @@ // Workaround https://issues.dlang.org/show_bug.cgi?id=2525 abstract override Version[] getVersions(string package_id); - abstract override void fetchPackage(Path path, string package_id, Dependency dep, bool pre_release); + abstract override void fetchPackage(NativePath path, string package_id, Dependency dep, bool pre_release); abstract override Json fetchPackageRecipe(string package_id, Dependency dep, bool pre_release); abstract override SearchResult[] searchPackages(string query); } diff --git a/source/dub/project.d b/source/dub/project.d index c4f054b..8e23c84 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -56,7 +56,7 @@ project_path = Path of the root package to load pack = An existing `Package` instance to use as the root package */ - this(PackageManager package_manager, Path project_path) + this(PackageManager package_manager, NativePath project_path) { Package pack; auto packageFile = Package.findPackageFile(project_path); @@ -356,7 +356,7 @@ else { auto path = vspec.path; if (!path.absolute) path = m_rootPackage.path ~ path; - p = m_packageManager.getOrLoadPackage(path, Path.init, true); + p = m_packageManager.getOrLoadPackage(path, NativePath.init, true); if (subname.length) p = m_packageManager.getSubPackage(p, subname, true); } } else if (m_dependencies.canFind!(d => getBasePackageName(d.name) == basename)) { @@ -371,10 +371,10 @@ } if (!p && !vspec.path.empty) { - Path path = vspec.path; + NativePath path = vspec.path; if (!path.absolute) path = pack.path ~ path; logDiagnostic("%sAdding local %s in %s", indent, dep.name, path); - p = m_packageManager.getOrLoadPackage(path, Path.init, true); + p = m_packageManager.getOrLoadPackage(path, NativePath.init, true); if (p.parentPackage !is null) { logWarn("%sSub package %s must be referenced using the path to it's parent package.", indent, dep.name); p = p.parentPackage; @@ -1236,7 +1236,7 @@ var = vres.data; } if (is_path) { - auto p = Path(var); + auto p = NativePath(var); if (!p.absolute) { return (pack.path ~ p).toNativeString(); } else return p.toNativeString(); @@ -1299,7 +1299,7 @@ /** Constructs a new version selections from an existing JSON file. */ - this(Path path) + this(NativePath path) { auto json = jsonFromFile(path); deserialize(json); @@ -1342,7 +1342,7 @@ } /// Selects a certain path for a specific package. - void selectVersion(string package_id, Path path) + void selectVersion(string package_id, NativePath path) { if (auto ps = package_id in m_selections) { if (ps.dep == Dependency(path)) @@ -1384,7 +1384,7 @@ should be used as the file name and the directory should be the root directory of the project's root package. */ - void save(Path path) + void save(NativePath path) { Json json = serialize(); auto file = openFile(path, FileMode.createTrunc); @@ -1423,7 +1423,7 @@ if (j.type == Json.Type.string) return Dependency(Version(j.get!string)); else if (j.type == Json.Type.object) - return Dependency(Path(j["path"].get!string)); + return Dependency(NativePath(j["path"].get!string)); else throw new Exception(format("Unexpected type for dependency: %s", j.type)); } diff --git a/source/dub/recipe/io.d b/source/dub/recipe/io.d index 52dbefe..c66072e 100644 --- a/source/dub/recipe/io.d +++ b/source/dub/recipe/io.d @@ -16,7 +16,7 @@ The file format (JSON/SDLang) will be determined from the file extension. Params: - filename = Path of the package recipe file + filename = NativePath of the package recipe file parent_name = Optional name of the parent package (if this is a sub package) Returns: Returns the package recipe contents @@ -24,10 +24,10 @@ */ PackageRecipe readPackageRecipe(string filename, string parent_name = null) { - return readPackageRecipe(Path(filename), parent_name); + return readPackageRecipe(NativePath(filename), parent_name); } /// ditto -PackageRecipe readPackageRecipe(Path filename, string parent_name = null) +PackageRecipe readPackageRecipe(NativePath filename, string parent_name = null) { import dub.internal.utils : stripUTF8Bom; import dub.internal.vibecompat.core.file : openFile, FileMode; @@ -137,7 +137,7 @@ } /// ditto -void writePackageRecipe(Path filename, in ref PackageRecipe recipe) +void writePackageRecipe(NativePath filename, in ref PackageRecipe recipe) { writePackageRecipe(filename.toNativeString, recipe); } diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index e76d487..016b5dd 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -162,7 +162,7 @@ /// Constructs a BuildSettings object from this template. - void getPlatformSettings(ref BuildSettings dst, in BuildPlatform platform, Path base_path) + void getPlatformSettings(ref BuildSettings dst, in BuildPlatform platform, NativePath base_path) const { dst.targetType = this.targetType; if (!this.targetPath.empty) dst.targetPath = this.targetPath; @@ -183,7 +183,7 @@ foreach (spath; paths) { enforce(!spath.empty, "Paths must not be empty strings."); - auto path = Path(spath); + auto path = NativePath(spath); if (!path.absolute) path = base_path ~ path; if (!existsFile(path) || !isDir(path.toNativeString())) { logWarn("Invalid source/import path: %s", path.toNativeString()); @@ -193,7 +193,7 @@ foreach (d; dirEntries(path.toNativeString(), pattern, SpanMode.depth)) { import std.path : baseName; if (baseName(d.name)[0] == '.' || d.isDir) continue; - auto src = Path(d.name).relativeTo(base_path); + auto src = NativePath(d.name).relativeTo(base_path); files ~= src.toNativeString(); } } diff --git a/source/dub/recipe/sdl.d b/source/dub/recipe/sdl.d index 65a3972..33dc59d 100644 --- a/source/dub/recipe/sdl.d +++ b/source/dub/recipe/sdl.d @@ -177,7 +177,7 @@ if ("version" in attrs) logDiagnostic("Ignoring version specification (%s) for path based dependency %s", attrs["version"][0].value.get!string, attrs["path"][0].value.get!string); dep.versionSpec = "*"; - dep.path = Path(attrs["path"][0].value.get!string); + dep.path = NativePath(attrs["path"][0].value.get!string); } else { enforceSDL("version" in attrs, "Missing version specification.", t); dep.versionSpec = attrs["version"][0].value.get!string; @@ -439,7 +439,7 @@ assert(rec.ddoxTool == "ddoxtool"); assert(rec.buildSettings.dependencies.length == 2); assert(rec.buildSettings.dependencies["projectname:subpackage1"].optional == false); - assert(rec.buildSettings.dependencies["projectname:subpackage1"].path == Path(".")); + assert(rec.buildSettings.dependencies["projectname:subpackage1"].path == NativePath(".")); assert(rec.buildSettings.dependencies["somedep"].versionSpec == "1.0.0"); assert(rec.buildSettings.dependencies["somedep"].optional == true); assert(rec.buildSettings.dependencies["somedep"].path.empty);