-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize handling of source folders in cross-platform/version scena…
…rios (#2531) 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
- Loading branch information
Showing
24 changed files
with
225 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
example/web/7-cross-platform-version-publishing/bar/src-2/BarVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package bar | ||
object BarVersionSpecific { | ||
def text(): String = "Specific code for Scala 2.x" | ||
} |
4 changes: 4 additions & 0 deletions
4
example/web/7-cross-platform-version-publishing/bar/src-3/BarVersionSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package bar | ||
object BarVersionSpecific { | ||
def text(): String = "Specific code for Scala 3.x" | ||
} |
5 changes: 5 additions & 0 deletions
5
example/web/7-cross-platform-version-publishing/bar/src/Bar.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bar | ||
import scalatags.Text.all._ | ||
object Bar { | ||
val value = p("world", " ", BarVersionSpecific.text()) | ||
} |
12 changes: 12 additions & 0 deletions
12
example/web/7-cross-platform-version-publishing/bar/test/src/BarTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package bar | ||
import utest._ | ||
object BarTests extends TestSuite { | ||
def tests = Tests { | ||
test("test") { | ||
val result = Bar.value.toString | ||
val matcher = "<p>world Specific code for Scala [23].x</p>".r | ||
assert(matcher.matches(result)) | ||
result | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
example/web/7-cross-platform-version-publishing/build.sc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import mill._, scalalib._, scalajslib._, publish._ | ||
|
||
trait Shared extends CrossScalaModule with PlatformScalaModule with PublishModule { | ||
def publishVersion = "0.0.1" | ||
|
||
def pomSettings = PomSettings( | ||
description = "Hello", | ||
organization = "com.lihaoyi", | ||
url = "https://github.com/lihaoyi/example", | ||
licenses = Seq(License.MIT), | ||
versionControl = VersionControl.github("lihaoyi", "example"), | ||
developers = Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")) | ||
) | ||
|
||
def ivyDeps = Agg(ivy"com.lihaoyi::scalatags::0.12.0") | ||
|
||
trait SharedTestModule extends Tests { | ||
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.7.11") | ||
def testFramework = "utest.runner.Framework" | ||
} | ||
} | ||
|
||
trait SharedJS extends Shared with ScalaJSModule { | ||
def scalaJSVersion = "1.13.0" | ||
} | ||
|
||
val scalaVersions = Seq("2.13.8", "3.2.2") | ||
|
||
object bar extends Module { | ||
object jvm extends Cross[JvmModule](scalaVersions) | ||
trait JvmModule extends Shared{ | ||
object test extends Tests with SharedTestModule | ||
} | ||
|
||
object js extends Cross[JsModule](scalaVersions) | ||
trait JsModule extends SharedJS{ | ||
object test extends Tests with SharedTestModule | ||
} | ||
} | ||
|
||
object qux extends Module{ | ||
object jvm extends Cross[JvmModule](scalaVersions) | ||
trait JvmModule extends Shared{ | ||
def moduleDeps = Seq(bar.jvm()) | ||
def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.lihaoyi::upickle::3.0.0") | ||
|
||
object test extends Tests with SharedTestModule | ||
} | ||
|
||
object js extends Cross[JsModule](scalaVersions) | ||
trait JsModule extends SharedJS { | ||
def moduleDeps = Seq(bar.js()) | ||
|
||
object test extends Tests with SharedTestModule | ||
} | ||
} | ||
|
||
// This example demonstrates an alternative way of defining your cross-platform | ||
// cross-version modules: rather than wrapping them all in a `foo` | ||
// cross-module to provide the different versions, we instead give each module | ||
// `bar.jvm`, `bar.js`, `qux.jvm`, `qux.js` its own `Cross` module. This | ||
// approach can be useful if the different cross modules need to support | ||
// different sets of Scala versions, as it allows you to specify the | ||
// `scalaVersions` passed to each individual cross module separately. | ||
|
||
/** Usage | ||
> ./mill show qux.js[3.2.2].sources | ||
[ | ||
".../qux/src", | ||
".../qux/src-js", | ||
".../qux/src-3.2.2", | ||
".../qux/src-3.2.2-js", | ||
".../qux/src-3.2", | ||
".../qux/src-3.2-js", | ||
".../qux/src-3", | ||
".../qux/src-3-js" | ||
] | ||
> ./mill show qux.js[3.2.2].test.sources | ||
[ | ||
".../qux/test/src", | ||
".../qux/test/src-js", | ||
".../qux/test/src-3.2.2", | ||
".../qux/test/src-3.2.2-js", | ||
".../qux/test/src-3.2", | ||
".../qux/test/src-3.2-js", | ||
".../qux/test/src-3", | ||
".../qux/test/src-3-js" | ||
] | ||
> ./mill qux.jvm[2.13.8].run | ||
Bar.value: <p>world Specific code for Scala 2.x</p> | ||
Parsing JSON with ujson.read | ||
Qux.main: Set(<p>i</p>, <p>cow</p>, <p>me</p>) | ||
> ./mill __.js[3.2.2].test | ||
+ bar.BarTests.test ... <p>world Specific code for Scala 3.x</p> | ||
+ qux.QuxTests.parseJsonGetKeys ... Set(i, cow, me) | ||
> ./mill __.publishLocal | ||
... | ||
Publishing Artifact(com.lihaoyi,bar_sjs1_2.13,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,bar_2.13,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,qux_sjs1_2.13,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,qux_2.13,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,bar_sjs1_3,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,bar_3,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,qux_sjs1_3,0.0.1) to ivy repo... | ||
Publishing Artifact(com.lihaoyi,qux_3,0.0.1) to ivy repo... | ||
*/ |
8 changes: 8 additions & 0 deletions
8
example/web/7-cross-platform-version-publishing/qux/src-js/QuxPlatformSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package qux | ||
import scala.scalajs.js | ||
object QuxPlatformSpecific { | ||
def parseJsonGetKeys(s: String): Set[String] = { | ||
println("Parsing JSON with js.JSON.parse") | ||
js.JSON.parse(s).asInstanceOf[js.Dictionary[_]].keys.toSet | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
example/web/7-cross-platform-version-publishing/qux/src-jvm/QuxPlatformSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package qux | ||
object QuxPlatformSpecific { | ||
def parseJsonGetKeys(s: String): Set[String] = { | ||
println("Parsing JSON with ujson.read") | ||
ujson.read(s).obj.keys.toSet | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
example/web/7-cross-platform-version-publishing/qux/src/Qux.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package qux | ||
import scalatags.Text.all._ | ||
object Qux { | ||
def main(args: Array[String]): Unit = { | ||
println("Bar.value: " + bar.Bar.value) | ||
val string = """{"i": "am", "cow": "hear", "me": "moo"}""" | ||
println("Qux.main: " + QuxPlatformSpecific.parseJsonGetKeys(string).map(p(_))) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
example/web/7-cross-platform-version-publishing/qux/test/src/QuxTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package qux | ||
import utest._ | ||
object QuxTests extends TestSuite { | ||
def tests = Tests { | ||
test("parseJsonGetKeys") { | ||
val string = """{"i": "am", "cow": "hear", "me": "moo"}""" | ||
val keys = QuxPlatformSpecific.parseJsonGetKeys(string) | ||
assert(keys == Set("i", "cow", "me")) | ||
keys | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters