Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update path module to [email protected] #2821

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
fail-fast: false
matrix:
# Latest stable version, update at will
os: [ macOS-13, ubuntu-20.04, windows-2019 ]
os: [ windows-2019 ]
dc:
# Always test latest as that is what we use to compile on release
- dmd-latest
Expand All @@ -72,8 +72,6 @@ jobs:
- { dc: ldc-latest, do_test: true }
- { dc: dmd-master, do_test: true }
- { dc: ldc-master, do_test: true }
# Test on ARM64
- { os: macOS-14, dc: ldc-latest, do_test: true }
exclude:
# Error with those versions:
# ld: multiple errors: symbol count from symbol table and dynamic symbol table differ in [.../dub.o]; address=0x0 points to section(2) with no content in '[...]/osx/lib/libphobos2.a[3177](config_a68_4c3.o)'
Expand Down
1 change: 1 addition & 0 deletions build-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ source/dub/internal/vibecompat/data/json.d
source/dub/internal/vibecompat/data/serialization.d
source/dub/internal/vibecompat/data/utils.d
source/dub/internal/vibecompat/inet/path.d
source/dub/internal/vibecompat/inet/path2.d
source/dub/internal/vibecompat/inet/url.d
source/dub/internal/colorize/colors.d
source/dub/internal/colorize/cwrite.d
Expand Down
2 changes: 2 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ configuration "library" {
}

configuration "library-nonet" {
dependency "vibe-core" version="~>2" optional=true
dependency "vibe-d:http" version=">=0.9.0 <0.11.0" optional=true
targetType "library"
excludedSourceFiles "source/app.d"
}

configuration "dynamic-library-nonet" {
dependency "vibe-core" version="~>2" optional=true
dependency "vibe-d:http" version=">=0.9.0 <0.11.0" optional=true
targetType "dynamicLibrary"
excludedSourceFiles "source/app.d"
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dub test --compiler=${DC} -c library-nonet

export DMD="$(command -v $DMD)"

./build.d -preview=dip1000 -preview=in -w -g -debug
./build.d -preview=in -w -g -debug

if [ "$COVERAGE" = true ]; then
# library-nonet fails to build with coverage (Issue 13742)
Expand Down
3 changes: 3 additions & 0 deletions source/dub/internal/io/filesystem.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public interface Filesystem
/// Returns: The `path` of this FSEntry
public abstract NativePath getcwd () const scope;

/// Change current directory to `path`. Equivalent to `cd` in shell.
public abstract void chdir (in NativePath path) scope;

/**
* Implements `mkdir -p`: Create a directory and every intermediary
*
Expand Down
80 changes: 74 additions & 6 deletions source/dub/internal/io/mockfs.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,44 @@ public final class MockFS : Filesystem {
///
private FSEntry root;

///
public this () scope
{
this.root = this.cwd = new FSEntry();
/***************************************************************************

Instantiate a `MockFS` with a given root

A parameter-less overload exists for POSIX, while on Windows a parameter
needs to be provided, as Windows' root has a drive letter.

Params:
root = The name of the root, e.g. "C:\"

***************************************************************************/

version (Windows) {
public this (char dir = 'C') scope
{
this.root = this.cwd = new FSEntry();
this.root.name = [ dir, ':' ];
}
} else {
public this () scope
{
this.root = this.cwd = new FSEntry();
}
}

public override NativePath getcwd () const scope
{
return this.cwd.path();
}

public override void chdir (in NativePath path) scope
{
auto tmp = this.lookup(path, true);
enforce(tmp !is null, "No such directory: " ~ path.toNativeString());
enforce(tmp.isDirectory(), "Cannot chdir into non-directory: " ~ path.toNativeString());
this.cwd = tmp;
}

///
public override bool existsDirectory (in NativePath path) const scope
{
Expand Down Expand Up @@ -275,14 +302,18 @@ public final class MockFS : Filesystem {
}

/// Get an arbitrarily nested children node
protected inout(FSEntry) lookup(NativePath path) inout return scope
protected inout(FSEntry) lookup(NativePath path, bool dbg = false) inout return scope
{
import std.algorithm.iteration : reduce;

const abs = path.absolute();
auto segments = path.bySegment;
// `library-nonet` (using vibe.d) has an empty front for absolute path,
// while our built-in module (in vibecompat) does not.
if (dbg) {
import std.stdio;
writeln("lookup: ", path, ", abs: ", abs, ", bySegment: ", path.bySegment);
}
if (abs && segments.front.name.length == 0) segments.popFront();
// Casting away constness because no good way to do this with `inout`,
// but `FSEntry.lookup` is `inout` too.
Expand Down Expand Up @@ -337,6 +368,8 @@ public class FSEntry
/// Creates a new FSEntry
package(dub) this (FSEntry p, Type t, string n)
{
assert(n.length);

// Avoid 'DOS File Times cannot hold dates prior to 1980.' exception
import std.datetime.date;
SysTime DefaultTime = SysTime(DateTime(2020, 01, 01));
Expand Down Expand Up @@ -431,7 +464,8 @@ public class FSEntry
public NativePath path () const scope
{
if (this.parent is null)
return NativePath("/");
// The first runtime branch is for Windows, the second for POSIX
return this.name ? NativePath(this.name) : NativePath("/");
auto thisPath = this.parent.path ~ this.name;
thisPath.endsWithSlash = (this.attributes.type == Type.Directory);
return thisPath;
Expand Down Expand Up @@ -473,3 +507,37 @@ public class FSEntry
this.attributes.attrs = attributes;
}
}

unittest {
alias P = NativePath;
scope fs = new MockFS();

version (Windows) immutable NativePath root = NativePath(`C:`);
else immutable NativePath root = NativePath(`/`);

assert(fs.getcwd == root, fs.getcwd.toString());
// We shouldn't be able to chdir into a non-existent directory
assertThrown(fs.chdir(P("foo/bar")));
// Even with an absolute path
assertThrown(fs.chdir(root ~ "foo/bar"));
// Now we should be
fs.mkdir(P("foo/bar"));
fs.chdir(P("foo/bar"));
assert(fs.getcwd == root ~ "foo/bar/", fs.getcwd.toNativeString());
// chdir with absolute path
fs.chdir(root ~ "foo");
assert(fs.getcwd == root ~ "foo/", fs.getcwd.toNativeString());
// This still does not exists
assertThrown(fs.chdir(root ~ "bar"));
// Test pseudo entries / meta locations
version (POSIX) {
fs.chdir(P("."));
assert(fs.getcwd == P("/foo/"));
fs.chdir(P(".."));
assert(fs.getcwd == P("/"));
fs.chdir(P("."));
assert(fs.getcwd == P("/"));
fs.chdir(NativePath("/foo/bar/../"));
assert(fs.getcwd == P("/foo/"));
}
}
6 changes: 6 additions & 0 deletions source/dub/internal/io/realfs.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public final class RealFS : Filesystem {
return this.path_;
}

///
public override void chdir (in NativePath path) scope
{
std.file.chdir(path.toNativeString());
}

///
protected override bool existsDirectory (in NativePath path) const scope
{
Expand Down
Loading
Loading