-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Changes from 7 commits
9ff11aa
3c20ced
50a41d7
e46a2bd
6f7147b
8505cde
fec317a
f4bc130
3c6fef4
276bbd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} |
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" | ||
} |
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()) | ||
} |
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 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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") | ||
|
||
object test 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 js extends Cross[JsModule](scalaVersions) | ||
trait JsModule extends SharedJS | ||
} | ||
|
||
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 js extends Cross[JsModule](scalaVersions) | ||
trait JsModule extends SharedJS { | ||
def moduleDeps = Seq(bar.js()) | ||
} | ||
} | ||
|
||
// 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 __.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... | ||
|
||
*/ |
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" | ||
} |
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" | ||
} |
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()) | ||
} |
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 | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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 | ||
} | ||
} |
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(_))) | ||
} | ||
} |
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 | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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 | ||
} | ||
} |
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(_))) | ||
} | ||
} |
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 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the user added additional source folders, maybe pointing outside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems reasonable to mirror them inside 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more consideration is that the current approach of shadowing the We also already delegate a lot of targets from test module to host module, so delegating another one would fit right in |
||
} | ||
} | ||
} | ||
|
||
trait Tests extends JavaModuleTests | ||
|
||
def defaultCommandName(): String = "run" | ||
|
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.
file needs scalafmt