summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-06 22:14:17 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-06 22:15:33 -0800
commitb97acb6f671502f57134932d0e7908e333b7cbbe (patch)
tree8024a5fcc48a7478f130ff11f15169f607c6a2a2
parent6408623e593b932829296945c75e1569930775eb (diff)
downloadmill-b97acb6f671502f57134932d0e7908e333b7cbbe.tar.gz
mill-b97acb6f671502f57134932d0e7908e333b7cbbe.tar.bz2
mill-b97acb6f671502f57134932d0e7908e333b7cbbe.zip
all T.commands to take targets as CLI arguments, and use that to get rid of our custom releaseCI/releaseManual commands
-rw-r--r--.travis.yml18
-rwxr-xr-xbuild.sc36
-rwxr-xr-xci/release.py22
-rwxr-xr-xci/release.sh11
-rwxr-xr-xci/test-mill-release.sh10
-rw-r--r--core/src/mill/define/BaseModule.scala50
-rw-r--r--core/src/mill/main/MainRunner.scala1
-rw-r--r--core/src/mill/main/Resolve.scala13
-rw-r--r--core/src/mill/main/Scopt.scala19
-rw-r--r--scalalib/src/mill/scalalib/PublishModule.scala39
10 files changed, 120 insertions, 99 deletions
diff --git a/.travis.yml b/.travis.yml
index da939589..5621661f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,16 +10,16 @@ jdk:
matrix:
include:
- - stage: build
- env: CI_SCRIPT=ci/test-sbt.sh
- - stage: build
- env: CI_SCRIPT=ci/test-sbt-built.sh
- - stage: build
- env: CI_SCRIPT=ci/test-mill-built.sh
- - stage: build
- env: CI_SCRIPT=ci/test-mill-release.sh
+# - stage: build
+# env: CI_SCRIPT=ci/test-sbt.sh
+# - stage: build
+# env: CI_SCRIPT=ci/test-sbt-built.sh
+# - stage: build
+# env: CI_SCRIPT=ci/test-mill-built.sh
+# - stage: build
+# env: CI_SCRIPT=ci/test-mill-release.sh
- stage: release
- env: CI_SCRIPT=ci/release.sh
+ env: CI_SCRIPT=ci/release.py
script:
- "$CI_SCRIPT"
diff --git a/build.sc b/build.sc
index ad21c20c..d31b66d8 100755
--- a/build.sc
+++ b/build.sc
@@ -243,39 +243,3 @@ def uploadToGithub(assembly: Path, authKey: String, release: String, label: Stri
upload.apply(assembly, release, label, authKey)
}
-
-def releaseCI(githubAuthKey: String,
- sonatypeCreds: String,
- gpgPassphrase: String,
- gpgPrivateKey: String) =
- if (!isMasterCommit) T.command()
- else {
- write(home / "gpg.key", java.util.Base64.getDecoder.decode(gpgPrivateKey))
- %('gpg, "--import", home / "gpg.key")(pwd)
- T.command{
- releaseManual(githubAuthKey, sonatypeCreds, gpgPassphrase)()
- }
- }
-
-
-def releaseManual(githubAuthKey: String,
- sonatypeCreds: String,
- gpgPassphrase: String) = T.command{
- mill.scalalib.PublishModule.publishAll(
- sonatypeCreds = sonatypeCreds,
- gpgPassphrase = gpgPassphrase,
- modules = Seq(
- moduledefs,
- core,
- scalalib,
- scalajslib,
- scalaworker,
- scalajslib.jsbridges("0.6"),
- scalajslib.jsbridges("1.0")
- )
- )()
-
- val (release, label) = publishVersion()
- uploadToGithub(releaseAssembly().path, githubAuthKey, release, label)
- ()
-}
diff --git a/ci/release.py b/ci/release.py
new file mode 100755
index 00000000..c59c6811
--- /dev/null
+++ b/ci/release.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from subprocess import check_call
+import os, base64
+check_call(["sbt", "bin/test:assembly"])
+is_master_commit = (
+ os.environ["TRAVIS_PULL_REQUEST"] == "false" &&
+ (os.environ["TRAVIS_BRANCH"] == "master" || os.environ["TRAVIS_TAG"] != "")
+)
+
+with open("~/gpg.key", "w") as f:
+ f.write(base64.b64decode(os.environ["GPG_PRIVATE_KEY_B64"]))
+
+check_call(["gpg", "--import", "~/gpg.key"])
+
+check_call([
+ "target/bin/mill",
+ "mill.scalalib.PublishModule/publishAll",
+ "lihaoyi:" + os.environ["SONATYPE_PASSWORD"],
+ os.environ["GPG_PASSWORD"],
+ "_.publishArtifacts"
+])
diff --git a/ci/release.sh b/ci/release.sh
deleted file mode 100755
index e9ff8302..00000000
--- a/ci/release.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-
-set -eux
-
-sbt bin/test:assembly
-
-target/bin/mill releaseCI \
- $GITHUB_ACCESS_TOKEN \
- lihaoyi:$SONATYPE_PASSWORD \
- $GPG_PASSWORD \
- $GPG_PRIVATE_KEY_B64
diff --git a/ci/test-mill-release.sh b/ci/test-mill-release.sh
index 52fc053d..5e19bcdc 100755
--- a/ci/test-mill-release.sh
+++ b/ci/test-mill-release.sh
@@ -9,15 +9,7 @@ git clean -xdf
sbt bin/test:assembly
# Build Mill using SBT
-target/bin/mill --all \
- moduledefs.publishLocal \
- core.publishLocal \
- scalalib.publishLocal \
- scalaworker.publishLocal \
- scalajslib.publishLocal \
- scalajslib.jsbridges[0.6].publishLocal \
- scalajslib.jsbridges[1.0].publishLocal \
- releaseAssembly
+target/bin/mill --all _.publishLocal releaseAssembly
mv out/releaseAssembly/dest/out.jar ~/mill-release
diff --git a/core/src/mill/define/BaseModule.scala b/core/src/mill/define/BaseModule.scala
index 9cefeeae..a449a6a0 100644
--- a/core/src/mill/define/BaseModule.scala
+++ b/core/src/mill/define/BaseModule.scala
@@ -2,14 +2,16 @@ package mill.define
import ammonite.main.Router.Overrides
import ammonite.ops.Path
+import mill.main.ParseArgs
object BaseModule{
case class Implicit(value: BaseModule)
}
-class BaseModule(millSourcePath0: Path, external0: Boolean = false)
- (implicit millModuleEnclosing0: sourcecode.Enclosing,
- millModuleLine0: sourcecode.Line,
- millName0: sourcecode.Name)
+
+abstract class BaseModule(millSourcePath0: Path, external0: Boolean = false)
+ (implicit millModuleEnclosing0: sourcecode.Enclosing,
+ millModuleLine0: sourcecode.Line,
+ millName0: sourcecode.Name)
extends Module()(
mill.define.Ctx.make(
implicitly,
@@ -28,6 +30,13 @@ class BaseModule(millSourcePath0: Path, external0: Boolean = false)
override def millSourcePath = millOuterCtx.millSourcePath
override implicit def millModuleBasePath: BasePath = BasePath(millSourcePath)
implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this)
+ def millDiscover: Discover[this.type]
+// implicit def millScoptModuleReads[T <: mill.Module] = new mill.main.ModuleScopt[T, this.type](
+// this, millDiscover
+// )
+ implicit def millScoptTargetReads[T] = new TargetScopt[T, this.type](
+ this, millDiscover
+ )
}
@@ -35,7 +44,7 @@ abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosin
millModuleLine0: sourcecode.Line,
millName0: sourcecode.Name)
extends BaseModule(ammonite.ops.pwd, external0 = true){
- def millDiscover: Discover[_]
+
implicit def millDiscoverImplicit: Discover[_] = millDiscover
assert(
!" #".exists(millModuleEnclosing0.value.contains(_)),
@@ -44,4 +53,33 @@ abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosin
override implicit def millModuleSegments = {
Segments(millModuleEnclosing0.value.split('.').map(Segment.Label):_*)
}
-} \ No newline at end of file
+}
+
+class TargetScopt[T, M <: BaseModule](rootModule: M, d: => Discover[M])
+ extends scopt.Read[Seq[mill.define.Target[T]]]{
+ def arity = 1
+ def reads = s => {
+ val (expanded, Nil) = ParseArgs(Seq(s)).fold(e => throw new Exception(e), identity)
+ val resolved = expanded.map{
+ case (Some(scoping), segments) =>
+ val moduleCls = rootModule.getClass.getClassLoader.loadClass(scoping.render + "$")
+ val externalRootModule = moduleCls.getField("MODULE$").get(moduleCls).asInstanceOf[ExternalModule]
+ val crossSelectors = segments.value.map {
+ case mill.define.Segment.Cross(x) => x.toList.map(_.toString)
+ case _ => Nil
+ }
+ mill.main.Resolve.resolve(segments.value.toList, externalRootModule, d, Nil, crossSelectors.toList, Nil)
+ case (None, segments) =>
+ rootModule.millInternal.segmentsToModules(segments).asInstanceOf[T]
+ val crossSelectors = segments.value.map {
+ case mill.define.Segment.Cross(x) => x.toList.map(_.toString)
+ case _ => Nil
+ }
+ mill.main.Resolve.resolve(segments.value.toList, rootModule, d, Nil, crossSelectors.toList, Nil)
+ }
+ mill.util.EitherOps.sequence(resolved) match{
+ case Left(s) => throw new Exception(s)
+ case Right(ts) => ts.flatten.collect{case t: mill.define.Target[T] => t}
+ }
+ }
+}
diff --git a/core/src/mill/main/MainRunner.scala b/core/src/mill/main/MainRunner.scala
index e3820e3d..e312aa7a 100644
--- a/core/src/mill/main/MainRunner.scala
+++ b/core/src/mill/main/MainRunner.scala
@@ -99,6 +99,7 @@ class MainRunner(config: ammonite.main.Cli.Config,
| // even if it does nothing...
| def $$main() = Iterator[String]()
|
+ | implicit def millScoptReads = new mill.main.ModuleScopt(this, millDiscover)
| implicit def millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type]
| // Need to wrap the returned Module in Some(...) to make sure it
| // doesn't get picked up during reflective child-module discovery
diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala
index f4eeb8fe..a83e3552 100644
--- a/core/src/mill/main/Resolve.scala
+++ b/core/src/mill/main/Resolve.scala
@@ -69,19 +69,10 @@ object Resolve {
val newRevSelectorsSoFar = head :: revSelectorsSoFar
head match{
case Segment.Label(singleLabel) =>
- if (singleLabel == "__"){
- val matching =
- obj.millInternal
- .modules
- .map(resolve(tail, _, discover, rest, remainingCrossSelectors, newRevSelectorsSoFar))
- .collect{case Right(vs) => vs}.flatten
+ if (singleLabel == "_") {
- if (matching.nonEmpty) Right(matching.toSeq)
- else Left("Cannot resolve module " + Segments(newRevSelectorsSoFar.reverse:_*).render)
- }else if (singleLabel == "_") {
val matching =
- obj.millInternal
- .reflectNestedObjects[mill.Module]
+ obj.millInternal.modules
.map(resolve(tail, _, discover, rest, remainingCrossSelectors, newRevSelectorsSoFar))
.collect{case Right(vs) => vs}.flatten
diff --git a/core/src/mill/main/Scopt.scala b/core/src/mill/main/Scopt.scala
new file mode 100644
index 00000000..57d6529d
--- /dev/null
+++ b/core/src/mill/main/Scopt.scala
@@ -0,0 +1,19 @@
+//package mill.main
+//
+//import mill.define.{BaseModule, Discover, ExternalModule}
+//
+////class ModuleScopt[T <: mill.Module, M <: BaseModule](rootModule: M, d: => Discover[M])
+//// extends scopt.Read[Seq[T]]{
+//// def arity = 1
+//// def reads = s => {
+//// val (expanded, Nil) = ParseArgs(Seq(s)).fold(e => throw new Exception(e), identity)
+//// expanded.map{
+//// case (Some(scoping), segments) =>
+//// val moduleCls = rootModule.getClass.getClassLoader.loadClass(scoping.render + "$")
+//// val externalRootModule = moduleCls.getField("MODULE$").get(moduleCls).asInstanceOf[ExternalModule]
+//// externalRootModule.millInternal.segmentsToModules(segments).asInstanceOf[T]
+//// case (None, segments) =>
+//// rootModule.millInternal.segmentsToModules(segments).asInstanceOf[T]
+//// }
+//// }
+////}
diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala
index 5c8b35e6..aef8b456 100644
--- a/scalalib/src/mill/scalalib/PublishModule.scala
+++ b/scalalib/src/mill/scalalib/PublishModule.scala
@@ -4,7 +4,7 @@ package scalalib
import ammonite.ops._
import mill.define.{ExternalModule, Task}
import mill.eval.{PathRef, Result}
-import mill.scalalib.publish.SonatypePublisher
+import mill.scalalib.publish.{Artifact, SonatypePublisher}
import mill.util.Loose.Agg
/**
* Configuration necessary for publishing a Scala module to Maven Central or similar
@@ -29,20 +29,20 @@ trait PublishModule extends ScalaModule { outer =>
ivyPomDeps ++ modulePomDeps.map(Dependency(_, Scope.Compile))
}
def pom = T {
- val pom = Pom(artifact(), publishXmlDeps(), artifactId(), pomSettings())
+ val pom = Pom(artifactMetadata(), publishXmlDeps(), artifactId(), pomSettings())
val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom"
write.over(pomPath, pom)
PathRef(pomPath)
}
def ivy = T {
- val ivy = Ivy(artifact(), publishXmlDeps())
+ val ivy = Ivy(artifactMetadata(), publishXmlDeps())
val ivyPath = T.ctx().dest / "ivy.xml"
write.over(ivyPath, ivy)
PathRef(ivyPath)
}
- def artifact: T[Artifact] = T {
+ def artifactMetadata: T[Artifact] = T {
Artifact(pomSettings().organization, artifactId(), publishVersion())
}
@@ -53,7 +53,7 @@ trait PublishModule extends ScalaModule { outer =>
docsJar = docsJar().path,
pom = pom().path,
ivy = ivy().path,
- artifact = artifact()
+ artifact = artifactMetadata()
)
}
@@ -63,30 +63,37 @@ trait PublishModule extends ScalaModule { outer =>
def publishArtifacts = T{
val baseName = s"${artifactId()}-${publishVersion()}"
- Seq(
- jar().path -> s"$baseName.jar",
- sourcesJar().path -> s"$baseName-sources.jar",
- docsJar().path -> s"$baseName-javadoc.jar",
- pom().path -> s"$baseName.pom"
+ (
+ artifactMetadata(),
+ Seq(
+ jar() -> s"$baseName.jar",
+ sourcesJar() -> s"$baseName-sources.jar",
+ docsJar() -> s"$baseName-javadoc.jar",
+ pom() -> s"$baseName.pom"
+ )
)
}
def publish(sonatypeCreds: String, gpgPassphrase: String): define.Command[Unit] = T.command {
+ val (artifactInfo, artifacts) = publishArtifacts()
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
sonatypeCreds,
gpgPassphrase,
T.ctx().log
- ).publish(publishArtifacts(), artifact())
+ ).publish(artifacts.map{case (a, b) => (a.path, b)}, artifactInfo)
}
}
object PublishModule extends ExternalModule{
def publishAll(sonatypeCreds: String,
gpgPassphrase: String,
- modules: Seq[PublishModule],
sonatypeUri: String = "https://oss.sonatype.org/service/local",
- sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots") = T.task{
+ sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots",
+ publishInfo: Seq[mill.T[(mill.scalalib.publish.Artifact, Seq[(PathRef, String)])]] = Nil) = T.command{
+ val x: Seq[(Seq[(Path, String)], Artifact)] = Task.sequence(publishInfo)().map{
+ case (a, s) => (s.map{case (p, f) => (p.path, f)}, a)
+ }
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
@@ -94,10 +101,8 @@ object PublishModule extends ExternalModule{
gpgPassphrase,
T.ctx().log
).publishAll(
- Task.traverse(modules)(
- m => T.task{(m.publishArtifacts(), m.artifact())}
- )():_*
+ x:_*
)
}
- def millDiscover = mill.define.Discover[this.type]
+ def millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type]
} \ No newline at end of file