Skip to content

Fix output folder for absolute path inputs#296

Open
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:paths
Open

Fix output folder for absolute path inputs#296
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:paths

Conversation

@davispuh

Copy link
Copy Markdown

Currently if you use absolute path for input files then output folder is not respected.

That is, this fails:

$ dstep -o /tmp /usr/include/stdio.h /usr/include/stdlib.h 
dstep: an unknown error occurred: std.file.FileException@std/file.d(840): /usr/include/stdio.d: Permission denied
----------------
/usr/include/dlang/dmd/std/file.d:283 @trusted bool std.file.cenforce!(bool).cenforce(bool, scope const(char)[], scope const(char)*, immutable(char)[], ulong) [0x562fb05e0003]
??:? @trusted void std.file.writeImpl(scope const(char)[], scope const(char)*, scope const(void)[], bool) [0x562fb06dae0b]
/usr/include/dlang/dmd/std/file.d:745 @safe void std.file.write!(immutable(char)[]).write(immutable(char)[], const(void[])) [0x562fb0639917]
dstep/translator/Translator.d:75 void dstep.translator.Translator.Translator.translate() [0x562fb06b35e0]
dstep/driver/Application.d:66 void dstep.driver.Application.Application.run() [0x562fb065a15c]
dstep/driver/CommandLine.d:181 int dstep.driver.CommandLine.run(immutable(char)[][]) [0x562fb066aa61]
dstep/main.d:18 _Dmain [0x562fb066d977]
std.file.FileException@std/file.d(840): /usr/include/stdio.d: Permission denied
----------------
/usr/include/dlang/dmd/std/file.d:283 @trusted bool std.file.cenforce!(bool).cenforce(bool, scope const(char)[], scope const(char)*, immutable(char)[], ulong) [0x562fb05e0003]
??:? @trusted void std.file.writeImpl(scope const(char)[], scope const(char)*, scope const(void)[], bool) [0x562fb06dae0b]
/usr/include/dlang/dmd/std/file.d:745 @safe void std.file.write!(immutable(char)[]).write(immutable(char)[], const(void[])) [0x562fb0639917]
dstep/translator/Translator.d:75 void dstep.translator.Translator.Translator.translate() [0x562fb06b35e0]
dstep/driver/Application.d:66 void dstep.driver.Application.Application.run() [0x562fb065a15c]
dstep/driver/CommandLine.d:181 int dstep.driver.CommandLine.run(immutable(char)[][]) [0x562fb066aa61]
dstep/main.d:18 _Dmain [0x562fb066d977]

It tries to create .d files in same directory as input file without respecting output folder.
This PR fixes that so that it will correctly use output folder for such case.

Copilot AI review requested due to automatic review settings March 18, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes output path generation so that using -o <dir> with absolute input header paths places generated .d files under the requested output directory instead of attempting to write next to the input headers (often unwritable system locations).

Changes:

  • Add findBasePath helper to compute a common base directory for absolute inputs.
  • Update multi-input output mapping to build outputs under config.output using relativePath(file, basePath).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dstep/driver/Util.d Adds findBasePath to derive a base directory from absolute input paths.
dstep/driver/Application.d Uses findBasePath + relativePath when building output paths for multiple inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread dstep/driver/Application.d Outdated
Comment thread dstep/driver/Util.d Outdated
Comment thread dstep/driver/Util.d Outdated

@jacob-carlborg jacob-carlborg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no new tests added that shows the change is working.

Currently this fails:
```
$ dstep -o /tmp /usr/include/stdio.h /usr/include/stdlib.h
dstep: an unknown error occurred: std.file.FileException@std/file.d(840): /usr/include/stdio.d: Permission denied
```

This is because it tries to create .d files in same directory as input file without respecting output folder.
This commit fixes this issue so that it will correctly use output folder for such case.
@davispuh

Copy link
Copy Markdown
Author

I rewrote this PR and added tests. Implement support for Windows aswell and tested that it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants