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

Fix crossProjectBaseDirectory #156

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

armanbilge
Copy link
Contributor

Sorry, there were some misses in the initial implementation 😕

  1. The vanilla baseDirectory setting (always?) returns an absolute file so I would expect crossProjectBaseDirectory to do so as well.

  2. Changes to the base directory with CrossProject#in was not being reflected in the crossProjectBaseDirectory setting.

The fixes work, but I wonder if there is a more principled way we should do this.

In sbt, the Project#base is a relative file but thisProject.value.base is absolute. So the change is somehow happening in between but I couldn't quite figure out how.

@@ -18,21 +18,24 @@ lazy val root =
check := {
doCheckPlatform(crossProjectPlatform.value, "jvm")
doCheckType(crossProjectCrossType.value, CrossType.Pure)
doCheckBase(crossProjectBaseDirectory.value, file("root"))
doCheckBase(crossProjectBaseDirectory.value,
file("root").getAbsoluteFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the .getAbsoluteFile inside def doCheckBase?

settings(
CrossPlugin.autoImport.crossProjectBaseDirectory := dir.getAbsoluteFile)
.mapProjectsByPlatform((platform, project) =>
project.in(crossType.platformDir(dir, platform)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The formatting here is downright misleading. Can you convince scalafmt not to destroy readability here? Perhaps import CrossPlugin.autoImport._ at the top of the file, and use unqualified key names.

@sjrd
Copy link
Collaborator

sjrd commented Apr 17, 2023

The fixes work, but I wonder if there is a more principled way we should do this.

In sbt, the Project#base is a relative file but thisProject.value.base is absolute. So the change is somehow happening in between but I couldn't quite figure out how.

Apparently, this is happening at "build loading time" here:
https://github.com/sbt/sbt/blob/973cd63e0b6bfe0d06d364f314f391a08a77d38b/main/src/main/scala/sbt/internal/Load.scala#L619-L626
I think it would be better to use a similar approach. The build base directory can be obtained with (LocalRootProject / baseDirectory).value. We could then IO.resolve the base against that value.

@armanbilge
Copy link
Contributor Author

Thanks, that was very helpful! Is this what you had in mind?

Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Yes, that seems more like it ;)

@sjrd sjrd merged commit c030519 into portable-scala:main Apr 17, 2023
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