-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix Location macro to be hermetic #823
Conversation
**Problem** The Locaiton macro currently captures the absolute path of the source file, which is not hermetic, and won't cache correctly on remote cached build tools such as Bazel, Gradle, and (in development) sbt 2.x. **Solution** This captures the relative path from the working directory instead.
val p = Paths.get(cwd).resolve(path) | ||
if (Files.exists(p)) p | ||
else if (max < 1) sys.error(s"$path was not found") | ||
else if (cwd.contains("\\")) findPath(cwd.split("\\").dropRight(1).mkString("\\"), path, max - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some of the tests are failing on Windows, would you be able to take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scalafmt and Scalafix are having an issue, too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's failing because the expected value contains /
and on Windows it's returning \
.
392521b
to
0ef1d84
Compare
if (Files.exists(p)) p | ||
else if (max < 1) sys.error(s"$path was not found") | ||
else if (cwd.contains("\\")) | ||
findPath(cwd.split("\\").dropRight(1).mkString("\\"), path, max - 1) | ||
else findPath(cwd.split("/").dropRight(1).mkString("/"), path, max - 1) | ||
findPath(getParentPath(cwd, "\\"), path, max - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using https://docs.oracle.com/javase/8/docs/api/java/io/File.html#separator instead of looking at the current path ? Or would this only work on the JVM ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, for native and JS it might be simpler to just look for \
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Let me know if you need a release right away. |
It would be great if could get a release this week or next. Thanks! |
Fixes #382
Problem
The
Location
macro currently captures the absolute path of the source file, which is not hermetic, and won't cache correctly on remote cached build tools such as Bazel, Gradle, and (in development) sbt 2.x.Solution
This captures the relative path from the working directory instead.