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

Use relative paths in generated erlang -file attributes #4193

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oneness
Copy link
Contributor

@oneness oneness commented Jan 22, 2025

Original issues #4141 and per @lpil, the expected behaviour should be:

Current working directory: /root/project
Source file location: /root/project/src/wibble.gleam
-file value: src/wibble.gleam

@oneness oneness changed the title Use relative paths in generated erlang -file attributes: Fixes #4141 Use relative paths in generated erlang -file attributes Jan 22, 2025
.unwrap_or_else(|| {
EcoString::from(
src_path_full
.strip_prefix(&(root_str + "/"))
Copy link
Member

Choose a reason for hiding this comment

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

Is this going to work on Windows?

Might be more reliable to use the path methods to make a relative path rather than do it via string manipulation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My first commit here:
d5b096a
failed on windows test. It used platform independent path.
After the test failure, I realized that all of the erlang target snapshot tests are assuming unix path and we need to keep two version of each (correct me if I am wrong) snaps file.

I agree with using path abstraction to handle this is much better than string manipulation but I am afraid this branch might sprawl into a long running with more code/test changes considering we have few places where we directly use "/" in our code (manifest.rs memory.rs and few places in test codes).

So I made a note of myself to do a bug report to fix this to work in Windows. What do you think?

Copy link
Member

@lpil lpil Jan 23, 2025

Choose a reason for hiding this comment

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

we need to keep two version of each (correct me if I am wrong) snaps file.

We edit file paths to be unix style for snapshots any time there would be difference between platforms.

I don't think there would need to be any here though, no? The snapshots all use unix style path roots already.

So I made a note of myself to do a bug report to fix this to work in Windows. What do you think?

We don't accept contributions that don't work on all our supported platforms I'm afraid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @lpil.
Yes, we do normalize windows path to be unix style for snapshots during snap file generation. Since all snapshots use unix style path roots, turning the directive absolute path (which happen to be os dependent during run time) into relative is run time dependent as well. if you are ok with following:

For Unix (note the ./ before the src dir) :
Current working directory: /root/project
Source file location: /root/project/src/wibble.gleam
-file value: ./src/wibble.gleam

For Windows (Note .\ before src dir):
Current working directory: \root\project
Source file location: \root\project\src\wibble.gleam
-file value: .\src\wibble.gleam

Then we can drop the hard coded "/", instead just prepend ".", which I believe works cross platform. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

That behaviour looks correct to me, aye!

src_path_full
.strip_prefix(&root_str)
.map(|remaining| format!(".{}", remaining))
.unwrap_or_else(|| src_path_full.to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

Do this using path manipulation please, not string manipulation.

@lpil lpil marked this pull request as draft January 25, 2025 20:02
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.

2 participants