summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Timushev <rtimush@gmail.com>2017-12-29 10:28:51 +0100
committerRoman Timushev <rtimush@gmail.com>2017-12-29 19:05:00 +0100
commit1a0cce2d21e9d90058386890f77a57291a494359 (patch)
tree84776b5439c07292fd01a665b1fae2fd7510f0eb
parent8583a2a95a0bf0b3dcfb74bfb47ea18719be01c1 (diff)
downloadmill-1a0cce2d21e9d90058386890f77a57291a494359.tar.gz
mill-1a0cce2d21e9d90058386890f77a57291a494359.tar.bz2
mill-1a0cce2d21e9d90058386890f77a57291a494359.zip
Cross-publish for ScalaJS
-rwxr-xr-xbuild.sc2
-rw-r--r--scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala28
-rw-r--r--scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala40
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala31
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala4
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala2
6 files changed, 78 insertions, 29 deletions
diff --git a/build.sc b/build.sc
index 5fdfaa2a..a9e63b43 100755
--- a/build.sc
+++ b/build.sc
@@ -12,7 +12,7 @@ trait MillPublishModule extends PublishModule {
def pomSettings = PomSettings(
organization = "com.lihaoyi",
- description = publishName(),
+ description = artifactId(),
developers = Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi/mill")),
licenses = Seq(License("MIT License", "https://spdx.org/licenses/MIT.html#licenseText")),
scm = SCM("https://github.com/lihaoyi/mill", "scm:git:https://github.com/lihaoyi/mill.git"),
diff --git a/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala b/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
index 1c736537..c3e8a89d 100644
--- a/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
+++ b/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
@@ -7,20 +7,31 @@ import ammonite.ops.Path
import mill.eval.Result.Success
import mill.scalajsplugin.Lib._
import mill.scalaplugin.Lib.resolveDependencies
-import mill.scalaplugin.{Dep, ScalaModule, TestScalaModule}
+import mill.scalaplugin.{Dep, PublishModule, ScalaModule, TestScalaModule}
trait ScalaJSModule extends ScalaModule { outer =>
def scalaJSVersion: T[String]
- def scalaJSBinaryVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") }
+ private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r
+ private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r
+
+ def scalaJSBinaryVersion = T{
+ scalaJSVersion() match {
+ case ReleaseVersion(major, minor, _) => s"$major.$minor"
+ case MinorSnapshotVersion(major, minor, _) => s"$major.$minor"
+ case _ => scalaJSVersion()
+ }
+ }
+
+ def scalaJSBridgeVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") }
def scalaJSLinkerClasspath: T[Seq[PathRef]] = T{
- val jsBridgeKey = "MILL_SCALAJS_BRIDGE_" + scalaJSBinaryVersion().replace('.', '_')
+ val jsBridgeKey = "MILL_SCALAJS_BRIDGE_" + scalaJSBridgeVersion().replace('.', '_')
val jsBridgePath = sys.props(jsBridgeKey)
if (jsBridgePath != null) Success(jsBridgePath.split(File.pathSeparator).map(f => PathRef(Path(f), quick = true)).toVector)
else {
- val dep = scalaJSLinkerIvyDep(scalaJSBinaryVersion())
+ val dep = scalaJSLinkerIvyDep(scalaJSBridgeVersion())
resolveDependencies(
repositories,
scalaVersion(),
@@ -44,6 +55,15 @@ trait ScalaJSModule extends ScalaModule { outer =>
override def ivyDeps = T{ Seq(Dep("org.scala-js", "scalajs-library", scalaJSVersion())) }
+ // publish artifact with name "mill_sjs0.6.4_2.12" instead of "mill_sjs0.6_2.12"
+ def crossFullScalaJSVersion: T[Boolean] = false
+ def artifactScalaJSVersion: T[String] = T {
+ if (crossFullScalaJSVersion()) scalaJSVersion()
+ else scalaJSBinaryVersion()
+ }
+
+ override def artifactId: T[String] = T { s"${artifactName()}_sjs${artifactScalaJSVersion()}_${artifactScalaVersion()}" }
+
}
trait TestScalaJSModule extends ScalaJSModule with TestScalaModule \ No newline at end of file
diff --git a/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala b/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
index ae824d86..e199c1da 100644
--- a/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
+++ b/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
@@ -5,15 +5,17 @@ import java.util.jar.JarFile
import javax.script.{ScriptContext, ScriptEngineManager}
import ammonite.ops._
-import ammonite.ops.ImplicitWd._
+import mill._
import mill.define.Cross
import mill.discover.Discovered
+import mill.scalaplugin.PublishModule
+import mill.scalaplugin.publish.{Developer, License, PomSettings, SCM}
import mill.util.TestEvaluator
import utest._
import scala.collection.JavaConverters._
-trait HelloJSWorldModule extends ScalaJSModule {
+trait HelloJSWorldModule extends ScalaJSModule with PublishModule {
def basePath = HelloJSWorldTests.workspacePath
override def mainClass = Some("Main")
}
@@ -26,6 +28,20 @@ object HelloJSWorld {
new HelloJSWorldModule {
def scalaVersion = scala
def scalaJSVersion = scalaJS
+ def pomSettings = PomSettings(
+ organization = "com.lihaoyi",
+ description = "hello js world ready for real world publishing",
+ url = "https://github.com/lihaoyi/hello-world-publish",
+ licenses = Seq(
+ License("Apache License, Version 2.0",
+ "http://www.apache.org/licenses/LICENSE-2.0")),
+ scm = SCM(
+ "https://github.com/lihaoyi/hello-world-publish",
+ "scm:git:https://github.com/lihaoyi/hello-world-publish"
+ ),
+ developers =
+ Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
+ )
}
}
@@ -58,7 +74,7 @@ object HelloJSWorldTests extends TestSuite {
def tests: Tests = Tests {
prepareWorkspace()
'compile - {
- def testFromScratch(scalaVersion: String,
+ def testCompileFromScratch(scalaVersion: String,
scalaJSVersion: String): Unit = {
val Right((result, evalCount)) =
helloWorldEvaluator(HelloJSWorld.build(scalaVersion, scalaJSVersion).compile)
@@ -77,10 +93,10 @@ object HelloJSWorldTests extends TestSuite {
assert(unchangedEvalCount == 0)
}
- 'fromScratch_2124_0621 - testFromScratch("2.12.4", "0.6.21")
- 'fromScratch_2123_0621 - testFromScratch("2.12.3", "0.6.21")
- 'fromScratch_2118_0621 - testFromScratch("2.11.8", "0.6.21")
- 'fromScratch_2124_100M2 - testFromScratch("2.11.8", "1.0.0-M2")
+ 'fromScratch_2124_0621 - testCompileFromScratch("2.12.4", "0.6.21")
+ 'fromScratch_2123_0621 - testCompileFromScratch("2.12.3", "0.6.21")
+ 'fromScratch_2118_0621 - testCompileFromScratch("2.11.8", "0.6.21")
+ 'fromScratch_2124_100M2 - testCompileFromScratch("2.11.8", "1.0.0-M2")
}
def testRun(scalaVersion: String,
@@ -115,6 +131,16 @@ object HelloJSWorldTests extends TestSuite {
assert(entries.contains("Main$.sjsir"))
}
}
+ 'publish - {
+ def testArtifactId(scalaVersion: String,
+ scalaJSVersion: String,
+ artifactId: String): Unit = {
+ val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.build(scalaVersion, scalaJSVersion).artifact)
+ assert(result.id == artifactId)
+ }
+ 'artifactId_0621 - testArtifactId("2.12.4", "0.6.21", "hello-js-world_sjs0.6_2.12")
+ 'artifactId_0621 - testArtifactId("2.12.4", "1.0.0-M2", "hello-js-world_sjs1.0.0-M2_2.12")
+ }
}
def compileClassfiles(parentDir: Path) = Set(
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
index b1102234..13e91c2a 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
@@ -257,29 +257,32 @@ trait ScalaModule extends Module with TaskModule { outer =>
options = Seq("-usejavacp")
)
}
-}
-
-trait PublishModule extends ScalaModule { outer =>
- import mill.scalaplugin.publish._
-
- def publishName: T[String] = basePath.last.toString
- def publishVersion: T[String] = "0.0.1-SNAPSHOT"
- def pomSettings: T[PomSettings]
// publish artifact with name "mill_2.12.4" instead of "mill_2.12"
- def publishWithFullScalaVersion: Boolean = false
+ def crossFullScalaVersion: T[Boolean] = false
+ def artifactName: T[String] = basePath.last.toString
def artifactScalaVersion: T[String] = T {
- if (publishWithFullScalaVersion) scalaVersion()
+ if (crossFullScalaVersion()) scalaVersion()
else scalaBinaryVersion()
}
+ def artifactId: T[String] = T { s"${artifactName()}_${artifactScalaVersion()}" }
+
+}
+
+trait PublishModule extends ScalaModule { outer =>
+ import mill.scalaplugin.publish._
+
+ def pomSettings: T[PomSettings]
+ def publishVersion: T[String] = "0.0.1-SNAPSHOT"
+
def pom = T {
val dependencies =
ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion()))
- val pom = Pom(artifact(), dependencies, publishName(), pomSettings())
+ val pom = Pom(artifact(), dependencies, artifactName(), pomSettings())
- val pomPath = T.ctx().dest / s"${publishName()}_${artifactScalaVersion()}-${publishVersion()}.pom"
+ val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom"
write.over(pomPath, pom)
PathRef(pomPath)
}
@@ -294,7 +297,7 @@ trait PublishModule extends ScalaModule { outer =>
}
def artifact: T[Artifact] = T {
- Artifact(pomSettings().organization, s"${publishName()}_${artifactScalaVersion()}", publishVersion())
+ Artifact(pomSettings().organization, artifactId(), publishVersion())
}
def publishLocal(): define.Command[Unit] = T.command {
@@ -313,7 +316,7 @@ trait PublishModule extends ScalaModule { outer =>
def sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots"
def publish(credentials: String, gpgPassphrase: String): define.Command[Unit] = T.command {
- val baseName = s"${publishName()}_${artifactScalaVersion()}-${publishVersion()}"
+ val baseName = s"${artifactId()}-${publishVersion()}"
val artifacts = Seq(
jar().path -> s"${baseName}.jar",
sourcesJar().path -> s"${baseName}-sources.jar",
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
index 529dda0c..131ee6bb 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
@@ -13,11 +13,11 @@ object AcyclicBuild{
for(crossVersion <- Cross("2.10.6", "2.11.8", "2.12.3", "2.12.4"))
yield new SbtScalaModule with PublishModule {outer =>
def basePath = AcyclicTests.workspacePath
- def publishName = "acyclic"
+ def artifactName = "acyclic"
def publishVersion = "0.1.7"
def pomSettings = PomSettings(
- description = publishName(),
+ description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/acyclic",
licenses = Seq(
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
index a265b953..4272654a 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
@@ -42,7 +42,7 @@ object HelloWorldFatalWarnings extends HelloWorldModule {
}
object HelloWorldWithPublish extends HelloWorldModule with PublishModule {
- def publishName = "hello-world"
+ def artifactName = "hello-world"
def publishVersion = "0.0.1"
def pomSettings = PomSettings(