diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 1736336..6c4956e 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1711,7 +1711,7 @@ enforceUsage(free_args.length == 1, "Expected destination path."); auto path = Path(free_args[0]); path.normalize(); - enforceUsage(path.length > 0, "Destination path must not be empty."); + enforceUsage(!path.empty, "Destination path must not be empty."); if (!path.absolute) path = Path(getcwd()) ~ path; enforceUsage(!path.startsWith(dub.rootPath), "Destination path must not be a sub directory of the tested package!"); @@ -1739,7 +1739,7 @@ } static void fixPathDependency(string pack, ref Dependency dep) { - if (dep.path.length > 0) { + if (!dep.path.empty) { auto mainpack = getBasePackageName(pack); dep.path = Path("../") ~ mainpack; } diff --git a/source/dub/dub.d b/source/dub/dub.d index 45f862d..6fc954a 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -516,11 +516,11 @@ */ void testProject(GeneratorSettings settings, string config, Path custom_main_file) { - if (custom_main_file.length && !custom_main_file.absolute) custom_main_file = getWorkingDirectory() ~ custom_main_file; + if (!custom_main_file.empty && !custom_main_file.absolute) custom_main_file = getWorkingDirectory() ~ custom_main_file; if (config.length == 0) { // if a custom main file was given, favor the first library configuration, so that it can be applied - if (custom_main_file.length) config = m_project.getDefaultConfiguration(settings.platform, false); + if (!custom_main_file.empty) config = m_project.getDefaultConfiguration(settings.platform, false); // else look for a "unittest" configuration if (!config.length && m_project.rootPackage.configurations.canFind("unittest")) config = "unittest"; // if not found, fall back to the first "library" configuration @@ -565,7 +565,7 @@ if (!mainfil.length) mainfil = m_project.rootPackage.recipe.buildSettings.mainSourceFile; string custommodname; - if (custom_main_file.length) { + if (!custom_main_file.empty) { import std.path; tcinfo.sourceFiles[""] ~= custom_main_file.relativeTo(m_project.rootPackage.path).toNativeString(); tcinfo.importPaths[""] ~= custom_main_file.parentPath.toNativeString(); @@ -1090,13 +1090,13 @@ } auto srcfile = m_project.rootPackage.recipePath; - auto srcext = srcfile[$-1].toString().extension; + auto srcext = srcfile.head.toString().extension; if (srcext == "."~destination_file_ext) { logInfo("Package format is already %s.", destination_file_ext); return; } - writePackageRecipe(srcfile[0 .. $-1] ~ ("dub."~destination_file_ext), m_project.rootPackage.rawRecipe); + writePackageRecipe(srcfile.parentPath ~ ("dub."~destination_file_ext), m_project.rootPackage.rawRecipe); removeFile(srcfile); } @@ -1165,7 +1165,7 @@ private void updatePackageSearchPath() { - if (m_overrideSearchPath.length) { + if (!m_overrideSearchPath.empty) { m_packageManager.disableDefaultSearchPaths = true; m_packageManager.searchPath = [m_overrideSearchPath]; } else { diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index c23ea9d..8947bd8 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -103,7 +103,7 @@ auto buildsettings = targets[m_project.rootPackage.name].buildSettings.dup; if (settings.run && !(buildsettings.options & BuildOption.syntaxOnly)) { Path exe_file_path; - if (!m_targetExecutablePath.length) + if (m_targetExecutablePath.empty) exe_file_path = getTargetPath(buildsettings, settings); else exe_file_path = m_targetExecutablePath ~ settings.compiler.getTargetFileName(buildsettings, settings.platform); diff --git a/source/dub/generators/sublimetext.d b/source/dub/generators/sublimetext.d index c22fcb1..18b6087 100644 --- a/source/dub/generators/sublimetext.d +++ b/source/dub/generators/sublimetext.d @@ -11,6 +11,7 @@ import dub.generators.generator; import dub.internal.vibecompat.core.log; import dub.internal.vibecompat.data.json; +import dub.internal.vibecompat.inet.path; import dub.packagemanager; import dub.project; diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index e47da77..3f94f6e 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -203,10 +203,10 @@ // Create folders and files ret.formattedWrite(" ", getPackageFileName(packname)); - Path lastFolder; + typeof(Path.init.head)[] lastFolder; foreach(source; sortedSources(sourceFiles.values)) { logDebug("source looking at %s", source.structurePath); - auto cur = source.structurePath[0 .. source.structurePath.length-1]; + auto cur = source.structurePath.parentPath.bySegment.array; if(lastFolder != cur) { size_t same = 0; foreach(idx; 0..min(lastFolder.length, cur.length)) @@ -317,8 +317,8 @@ foreach (f; buildsettings.sourceFiles) { auto rpath = Path(f).relativeTo(project_file_dir); size_t nd = 0; - foreach (i; 0 .. rpath.length) - if (rpath[i] == "..") + foreach (s; rpath.bySegment) + if (s == "..") nd++; if (nd > ndummy) ndummy = nd; } @@ -460,13 +460,13 @@ private final static int sortOrder(ref const SourceFile a, ref const SourceFile b) { assert(!a.structurePath.empty); assert(!b.structurePath.empty); - auto as = a.structurePath; - auto bs = b.structurePath; + auto as = a.structurePath.bySegment.array; + auto bs = b.structurePath.bySegment.array; // Check for different folders, compare folders only (omit last one). for(uint idx=0; idx Path(p))) { if (!ipath.absolute) ipath = base_path ~ ipath; assert(!ipath.empty); - if (file.startsWith(ipath) && ipath.length > path_skip) - path_skip = ipath.length; + if (file.startsWith(ipath) && ipath.bySegment.walkLength > path_skip) + path_skip = ipath.bySegment.walkLength; } enforce(path_skip > 0, format("Source file '%s' not found in any import path.", file.toNativeString())); - auto mpath = file[path_skip .. file.length]; + auto mpath = file.bySegment.array[path_skip .. $]; auto ret = appender!string; //search for module keyword in file diff --git a/source/dub/internal/vibecompat/inet/path.d b/source/dub/internal/vibecompat/inet/path.d index 68cd513..0292d3c 100644 --- a/source/dub/internal/vibecompat/inet/path.d +++ b/source/dub/internal/vibecompat/inet/path.d @@ -7,7 +7,8 @@ */ module dub.internal.vibecompat.inet.path; -version (Have_vibe_d_core) public import vibe.inet.path; +version (Have_vibe_core) public import vibe.core.path; +else version (Have_vibe_d_core) public import vibe.inet.path; else: import std.algorithm; @@ -31,6 +32,10 @@ bool m_endsWithSlash = false; } + alias Segment = PathEntry; + + alias bySegment = nodes; + /// Constructs a Path object by parsing a path string. this(string pathstr) { @@ -283,6 +288,8 @@ string toString() const pure { return m_name; } + @property string name() const { return m_name; } + Path opBinary(string OP)(PathEntry rhs) const if( OP == "~" ) { return Path([this, rhs], false); } bool opEquals(ref const PathEntry rhs) const { return m_name == rhs.m_name; } diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index a0f9f61..042e3e3 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -338,6 +338,8 @@ /// destination and sets a version field in the package description. Package storeFetchedPackage(Path zip_file_path, Json package_info, Path destination) { + import std.range : walkLength; + auto package_name = package_info["name"].get!string; auto package_version = package_info["version"].get!string; auto clean_package_version = package_version[package_version.startsWith("~") ? 1 : 0 .. $]; @@ -361,11 +363,12 @@ logDebug("Extracting from zip."); // In a github zip, the actual contents are in a subfolder - Path zip_prefix; + alias PSegment = typeof(Path.init.head); + PSegment[] zip_prefix; outer: foreach(ArchiveMember am; archive.directory) { - auto path = Path(am.name); + auto path = Path(am.name).bySegment.array; foreach (fil; packageInfoFiles) - if (path.length == 2 && path.head.toString == fil.filename) { + if (path.length == 2 && path[$-1].toString == fil.filename) { zip_prefix = path[0 .. $-1]; break outer; } @@ -375,8 +378,9 @@ Path getCleanedPath(string fileName) { auto path = Path(fileName); - if(zip_prefix != Path() && !path.startsWith(zip_prefix)) return Path(); - return path[zip_prefix.length..path.length]; + if (zip_prefix.length && !path.bySegment.startsWith(zip_prefix)) return Path.init; + static if (is(typeof(path[0 .. 1]))) return path[zip_prefix.length .. $]; + else return Path(path.bySegment.array[zip_prefix.length .. $]); } static void setAttributes(string path, ArchiveMember am) @@ -396,7 +400,7 @@ foreach(ArchiveMember a; archive.directory) { auto cleanedPath = getCleanedPath(a.name); if(cleanedPath.empty) continue; - auto dst_path = destination~cleanedPath; + auto dst_path = destination ~ cleanedPath; logDebug("Creating %s", cleanedPath); if( dst_path.endsWithSlash ){ diff --git a/source/dub/recipe/sdl.d b/source/dub/recipe/sdl.d index 0e2bab6..65a3972 100644 --- a/source/dub/recipe/sdl.d +++ b/source/dub/recipe/sdl.d @@ -230,7 +230,7 @@ foreach (pack, d; bs.dependencies) { Attribute[] attribs; - if (d.path.length) attribs ~= new Attribute(null, "path", Value(d.path.toString())); + if (!d.path.empty) attribs ~= new Attribute(null, "path", Value(d.path.toString())); else attribs ~= new Attribute(null, "version", Value(d.versionSpec)); if (d.optional) attribs ~= new Attribute(null, "optional", Value(true)); ret ~= new Tag(null, "dependency", [Value(pack)], attribs);