diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-11 00:50:59 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-11 00:50:59 -0800 |
commit | a40be9487a39ca5d98444d1f7adc053adbc42649 (patch) | |
tree | ae37eaf32db9341486566f468787baac0cbcd436 /scalalib/src | |
parent | 7677210d9fce7ac1fde9615d429e6c79d058b72a (diff) | |
download | mill-a40be9487a39ca5d98444d1f7adc053adbc42649.tar.gz mill-a40be9487a39ca5d98444d1f7adc053adbc42649.tar.bz2 mill-a40be9487a39ca5d98444d1f7adc053adbc42649.zip |
WIP getting Scala.js dependencies working nicely
Diffstat (limited to 'scalalib/src')
-rw-r--r-- | scalalib/src/mill/scalalib/Dep.scala | 35 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/GenIdea.scala | 2 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/Lib.scala | 44 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaModule.scala | 2 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/publish/settings.scala | 37 |
5 files changed, 81 insertions, 39 deletions
diff --git a/scalalib/src/mill/scalalib/Dep.scala b/scalalib/src/mill/scalalib/Dep.scala index aa301fcb..8ecd39ee 100644 --- a/scalalib/src/mill/scalalib/Dep.scala +++ b/scalalib/src/mill/scalalib/Dep.scala @@ -6,36 +6,39 @@ object Dep{ implicit def parse(signature: String) = { signature.split(':') match{ - case Array(a, b, c) => Dep.Java(a, b, c) - case Array(a, "", b, c) => Dep.Scala(a, b, c) - case Array(a, "", "", b, c) => Dep.Point(a, b, c) + case Array(a, b, c) => Dep.Java(a, b, c, cross = false) + case Array(a, b, "", c) => Dep.Java(a, b, c, cross = true) + case Array(a, "", b, c) => Dep.Scala(a, b, c, cross = false) + case Array(a, "", b, "", c) => Dep.Scala(a, b, c, cross = true) + case Array(a, "", "", b, c) => Dep.Point(a, b, c, cross = false) + case Array(a, "", "", b, "", c) => Dep.Point(a, b, c, cross = true) case _ => throw new Exception(s"Unable to parse signature: [$signature]") } } - def apply(org: String, name: String, version: String): Dep = { - this(coursier.Dependency(coursier.Module(org, name), version)) + def apply(org: String, name: String, version: String, cross: Boolean): Dep = { + this(coursier.Dependency(coursier.Module(org, name), version), cross) } - case class Java(dep: coursier.Dependency) extends Dep + case class Java(dep: coursier.Dependency, cross: Boolean) extends Dep object Java{ implicit def rw: RW[Java] = macroRW - def apply(org: String, name: String, version: String): Dep = { - Java(coursier.Dependency(coursier.Module(org, name), version)) + def apply(org: String, name: String, version: String, cross: Boolean): Dep = { + Java(coursier.Dependency(coursier.Module(org, name), version), cross) } } - implicit def default(dep: coursier.Dependency): Dep = new Java(dep) - def apply(dep: coursier.Dependency) = Scala(dep) - case class Scala(dep: coursier.Dependency) extends Dep + implicit def default(dep: coursier.Dependency): Dep = new Java(dep, false) + def apply(dep: coursier.Dependency, cross: Boolean) = Scala(dep, cross) + case class Scala(dep: coursier.Dependency, cross: Boolean) extends Dep object Scala{ implicit def rw: RW[Scala] = macroRW - def apply(org: String, name: String, version: String): Dep = { - Scala(coursier.Dependency(coursier.Module(org, name), version)) + def apply(org: String, name: String, version: String, cross: Boolean): Dep = { + Scala(coursier.Dependency(coursier.Module(org, name), version), cross) } } - case class Point(dep: coursier.Dependency) extends Dep + case class Point(dep: coursier.Dependency, cross: Boolean) extends Dep object Point{ implicit def rw: RW[Point] = macroRW - def apply(org: String, name: String, version: String): Dep = { - Point(coursier.Dependency(coursier.Module(org, name), version)) + def apply(org: String, name: String, version: String, cross: Boolean): Dep = { + Point(coursier.Dependency(coursier.Module(org, name), version), cross) } } implicit def rw = RW.merge[Dep]( diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala index 4b283e7c..420e79b9 100644 --- a/scalalib/src/mill/scalalib/GenIdea.scala +++ b/scalalib/src/mill/scalalib/GenIdea.scala @@ -59,7 +59,7 @@ object GenIdea { Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", for(name <- artifactNames) - yield Dep("com.lihaoyi", s"mill-${name}", sys.props("MILL_VERSION")) + yield ivy"com.lihaoyi::mill-$name:${sys.props("MILL_VERSION")}" ) res.items.toSeq.map(_.path) } diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index ae10bd00..50e19b16 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -37,13 +37,36 @@ object Lib{ def resolveDependencies(repositories: Seq[Repository], scalaVersion: String, deps: TraversableOnce[Dep], + platformSuffix: String = "", sources: Boolean = false): Result[Agg[PathRef]] = { + val flattened = deps.map{ - case Dep.Java(dep) => dep - case Dep.Scala(dep) => - dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion(scalaVersion))) - case Dep.Point(dep) => - dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaVersion)) + case Dep.Java(dep, cross) => + dep.copy( + module = dep.module.copy( + name = + dep.module.name + + (if (!cross) "" else platformSuffix) + ) + ) + case Dep.Scala(dep, cross) => + dep.copy( + module = dep.module.copy( + name = + dep.module.name + + (if (!cross) "" else platformSuffix) + + "_" + scalaBinaryVersion(scalaVersion) + ) + ) + case Dep.Point(dep, cross) => + dep.copy( + module = dep.module.copy( + name = + dep.module.name + + (if (!cross) "" else platformSuffix) + + "_" + scalaVersion + ) + ) }.toSet val start = Resolution(flattened) @@ -77,14 +100,17 @@ object Lib{ } } def scalaCompilerIvyDeps(scalaVersion: String) = Agg[Dep]( - Dep.Java("org.scala-lang", "scala-compiler", scalaVersion), - Dep.Java("org.scala-lang", "scala-reflect", scalaVersion) + ivy"org.scala-lang:scala-compiler:$scalaVersion", + ivy"org.scala-lang:scala-reflect:$scalaVersion" ) def scalaRuntimeIvyDeps(scalaVersion: String) = Agg[Dep]( - Dep.Java("org.scala-lang", "scala-library", scalaVersion) + ivy"org.scala-lang:scala-library:$scalaVersion" ) def compilerBridgeIvyDep(scalaVersion: String) = - Dep.Point(coursier.Dependency(coursier.Module("com.lihaoyi", "mill-bridge"), "0.1", transitive = false)) + Dep.Point( + coursier.Dependency(coursier.Module("com.lihaoyi", "mill-bridge"), "0.1", transitive = false), + cross = false + ) val DefaultShellScript: Seq[String] = Seq( "#!/usr/bin/env sh", diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 6548aad4..3c5d9479 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -62,10 +62,12 @@ trait ScalaModule extends mill.Module with TaskModule { outer => repositories, scalaVersion(), deps(), + platformSuffix(), sources ) } + def platformSuffix = T{ "" } def externalCompileDepClasspath: T[Agg[PathRef]] = T{ Agg.from(Task.traverse(moduleDeps)(_.externalCompileDepClasspath)().flatten) ++ resolveDeps( diff --git a/scalalib/src/mill/scalalib/publish/settings.scala b/scalalib/src/mill/scalalib/publish/settings.scala index eb0a44b6..621e5718 100644 --- a/scalalib/src/mill/scalalib/publish/settings.scala +++ b/scalalib/src/mill/scalalib/publish/settings.scala @@ -8,22 +8,33 @@ case class Artifact(group: String, id: String, version: String) { object Artifact { - def fromDep(dep: Dep, scalaFull: String, scalaBin: String): Dependency = { + def fromDep(dep: Dep, + scalaFull: String, + scalaBin: String): Dependency = { dep match { - case Dep.Java(dep) => + case Dep.Java(dep, cross) => Dependency( Artifact(dep.module.organization, dep.module.name, dep.version), - Scope.Compile) - case Dep.Scala(dep) => - Dependency(Artifact(dep.module.organization, - s"${dep.module.name}_${scalaBin}", - dep.version), - Scope.Compile) - case Dep.Point(dep) => - Dependency(Artifact(dep.module.organization, - s"${dep.module.name}_${scalaFull}", - dep.version), - Scope.Compile) + Scope.Compile + ) + case Dep.Scala(dep, cross) => + Dependency( + Artifact( + dep.module.organization, + s"${dep.module.name}_${scalaBin}", + dep.version + ), + Scope.Compile + ) + case Dep.Point(dep, cross) => + Dependency( + Artifact( + dep.module.organization, + s"${dep.module.name}_${scalaFull}", + dep.version + ), + Scope.Compile + ) } } } |