diff options
| author | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-02-08 13:56:03 +1100 |
|---|---|---|
| committer | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-02-08 14:30:37 +1100 |
| commit | 1f7390f3999e80f775dbc0e62f1dcb071c3bed77 (patch) | |
| tree | 825d01e81a5f51759798ae62339c5639d1ca33ee /src/Compilation.zig | |
| parent | 9ccd8ed0ad4cc9e68c2a2e0c9b1e32d50259357e (diff) | |
| download | zig-1f7390f3999e80f775dbc0e62f1dcb071c3bed77.tar.gz zig-1f7390f3999e80f775dbc0e62f1dcb071c3bed77.zip | |
fix custom test runner package path resolution
Fixes #13970.
This fix makes test runners resolve package paths relative to the
directory the test runner is in. This means it is not possible to import
a file from outside the file tree root at the directory containing the
test runner.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index e09b8f18ab..8f265f9eb6 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1621,8 +1621,11 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const root_pkg = if (options.is_test) root_pkg: { // TODO: we currently have two packages named 'root' here, which is weird. This // should be changed as part of the resolution of #12201 - const test_pkg = if (options.test_runner_path) |test_runner| - try Package.create(gpa, "root", null, test_runner) + const test_pkg = if (options.test_runner_path) |test_runner| test_pkg: { + const test_dir = std.fs.path.dirname(test_runner); + const basename = std.fs.path.basename(test_runner); + break :test_pkg try Package.create(gpa, "root", test_dir, basename); + } else try Package.createWithDir( gpa, |
