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 -file attributes #4166

Closed
wants to merge 5 commits into from
Closed

Conversation

oneness
Copy link
Contributor

@oneness oneness commented Jan 9, 2025

Hi @lpil,
Please have a look. It seems the entire pipeline (load, compile and gen) does uses absolute path, which IMHO is a great thing for reproducibility and tooling. This PR propagates the project root so it is stripped off from the generated module file directive. I might be completely off and feel free to comment as you see fit.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!

I see build has failed in a strange way, I expect this is due to a new Rust version being released or such.

Could you update the tests such that they demonstrate the fix working please 🙏

@@ -20,7 +20,7 @@ pub fn main() {

-export([main/0]).

-file("/root/project/test/my/mod.gleam", 1).
-file("my/mod/project/test/my/mod.gleam", 1).
Copy link
Member

@lpil lpil Jan 21, 2025

Choose a reason for hiding this comment

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

Why do these start with my/mod/project/etc now? Shouldn't they be project/etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lpil We use module name as the prefix after we strip off the root, which is /root. The existing test has my/mod as the module name and it is used for module name normalization tests so I choose not to change to minimize the noise of this fix. If you prefer to change it, let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I'm confused. Why do we use the module name as a prefix? That results in an invalid path to a file that doesn't exist?

Copy link
Contributor Author

@oneness oneness Jan 21, 2025

Choose a reason for hiding this comment

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

@lpil No worries. Here is how I understood this issue:
If you look at the #4141, here is actual -file directory being generated before the fix:
-file("/Users/USERNAME/SOME/PATH/some_lib_or_app/src/some_lib_or_app.gleam", 26).
And the expectation is:
-file("some_lib_or_app/src/some_lib_or_app.gleam", 26), which the fix is about.
In our pipeline, I understood that the project root getting parsed as /Users/USERNAME/SOME/PATH, the module name as some_lib_or_app. Thus the fix. Let me know if you think there is better way to fix this issue.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand, so I'll give an example of what the behaviour should be.

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

The tests don't seem to match this from what I can see, why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, if that is what the expected behaviour, then the fix would be much simpler and I could update the code changes and tests to reflect that. So to confirm:
Currently (main branch) generates fqn for the generated erlang -file directive like this:
/root/project/src/wibble.gleam given the cwd of /root/project, which is the bug.
The correct behaviour is:
the file directive should be src/wibble.gleam.

Please confirm and will take care of this soon.

@lpil
Copy link
Member

lpil commented Jan 21, 2025

Closes #4141

@lpil lpil changed the title Fixes https://github.com/gleam-lang/gleam/issues/4141 Use relative paths in -file attributes Jan 21, 2025
@oneness
Copy link
Contributor Author

oneness commented Jan 22, 2025

Closing this PR in favor of #4193.

@oneness oneness closed this Jan 22, 2025
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