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

Generalize handling of source folders in cross-platform/version scenarios #2531

Merged
merged 10 commits into from
May 20, 2023

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented May 20, 2023

Originally bumped into these issues trying to upgrade fansi/os-lib/upickle to 0.11.0-M9

  1. Generalize CrossScalaModuleTests#sources to JavaModuleTests#sources.

    1. Rather than explicitly duplicating the behavior of CrossScalaModule in CrossScalaModuleTests, we instead define that all Tests module within a JavaModule of any kind most follow the parent module's source layout, relativized to the test module's millSourcePath.
    2. This should allow the "test module follows parent module source" approach to generalize for any combination of CrossScalaModule, PlatformScalaModule, etc. without needing it to be aware of every combination of such cross-modules
  2. Generalize PlatformScalaModule#sources to work for cross modules where the cross segment is the last one, i.e. foo.jvm[2.13.10] vs foo[2.13.10].jvm

Tested both changes with an additional example test included in the documentation. This demonstrates an alternative approach to that in example/web/6-cross-version-platform-publishing/, one commonly used in the com-lihaoyi libraries, so I think it's worth making a full example v.s. just testing this via unit tests

@lihaoyi lihaoyi requested review from lolgab and lefou May 20, 2023 06:11
@lihaoyi lihaoyi marked this pull request as ready for review May 20, 2023 06:11
Copy link
Member

Choose a reason for hiding this comment

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

file needs scalafmt

@@ -41,7 +41,13 @@ trait JavaModule
override def zincWorker: ZincWorkerModule = outer.zincWorker
override def skipIdea: Boolean = outer.skipIdea
override def runUseArgsFile: Target[Boolean] = T { outer.runUseArgsFile() }
override def sources = T.sources {
for (src <- outer.sources()) yield {
PathRef(this.millSourcePath / src.path.relativeTo(outer.millSourcePath))
Copy link
Member

Choose a reason for hiding this comment

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

What if the user added additional source folders, maybe pointing outside of outer.millSourcePath?

Copy link
Member Author

@lihaoyi lihaoyi May 20, 2023

Choose a reason for hiding this comment

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

Seems reasonable to mirror them inside test I think? That's what I'm finding as I port builds over, e.g. maybe someone added src-2.13+/ or src-js-jvm/, and it would make perfect sense to mirror them inside the test submodule. Especially v.s. the current status quo, where the source folder layout of test folders is pretty manual and thus ad-hoc, "same as parent module" seems like a big simplification both in UX as well as internal machinery

We could filter these folders somehow if we really want, but IMO it's not necessary. In most common cases the only downside would be the test module gets a few unused-but-reasonable source folders, and worst comes to worst if someone wants to change this mirroring they can always override it, which is what the CrossSbtModule#Tests already do

Copy link
Member Author

Choose a reason for hiding this comment

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

One more consideration is that the current approach of shadowing the Tests trait does not compose. While it works for one use case in CrossScalaModule, you cannot stack a second use case in PlatformScalaModule and have them work together to define the final sources list

We also already delegate a lot of targets from test module to host module, so delegating another one would fit right in

@lihaoyi lihaoyi merged commit 73437ce into com-lihaoyi:main May 20, 2023
@lefou lefou added this to the 0.11.0-M10 milestone May 20, 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