aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-10 01:40:14 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-02-13 10:10:02 -0500
commit8ebada86b1fc58465751864acba8aafd387ccb4b (patch)
tree3c0cf15a408350511652dd0f0872a8eba6de7a9e
parent0a295c21d3379117e661fdbf586ecb6222c3602b (diff)
downloadcbt-8ebada86b1fc58465751864acba8aafd387ccb4b.tar.gz
cbt-8ebada86b1fc58465751864acba8aafd387ccb4b.tar.bz2
cbt-8ebada86b1fc58465751864acba8aafd387ccb4b.zip
Add support for nested builds and use it to replace cross compilation
command which was previously hard-coded This will allow multi-project builds, too but we should first fix caching across instances and GitDependencies on sub-builds within other repositories.
-rw-r--r--compatibility/BuildInterface.java4
-rw-r--r--examples/cross-build-example/build/build.scala4
-rw-r--r--examples/cross-build-example/src/Main.scala3
-rw-r--r--plugins/essentials/MultipleScalaVersions.scala9
-rw-r--r--stage1/cbt.scala1
-rw-r--r--stage2/BasicBuild.scala5
-rw-r--r--stage2/Lib.scala14
-rw-r--r--stage2/Stage2.scala14
8 files changed, 38 insertions, 16 deletions
diff --git a/compatibility/BuildInterface.java b/compatibility/BuildInterface.java
index f061832..e2b5f36 100644
--- a/compatibility/BuildInterface.java
+++ b/compatibility/BuildInterface.java
@@ -4,7 +4,9 @@ import java.io.*;
public abstract class BuildInterface implements Dependency{
public abstract BuildInterface copy(Context context); // needed to configure builds
public abstract String scalaVersion(); // needed to propagate scalaVersion to dependent builds
- public abstract String[] crossScalaVersionsArray(); // FIXME: this probably can't use Scala classes
public abstract BuildInterface finalBuild(); // needed to propagage through build builds. Maybe we can get rid of this.
public abstract File[] triggerLoopFilesArray(); // needed for watching files across composed builds
+
+ // deprecated methods, which clients are still allowed to implement, but not required
+ public abstract String[] crossScalaVersionsArray();
}
diff --git a/examples/cross-build-example/build/build.scala b/examples/cross-build-example/build/build.scala
new file mode 100644
index 0000000..e1df645
--- /dev/null
+++ b/examples/cross-build-example/build/build.scala
@@ -0,0 +1,4 @@
+import cbt._
+class Build(val context: Context) extends MultipleScalaVersions{
+ override def scalaVersions = Seq("2.10.5","2.11.7")
+}
diff --git a/examples/cross-build-example/src/Main.scala b/examples/cross-build-example/src/Main.scala
new file mode 100644
index 0000000..88a18d3
--- /dev/null
+++ b/examples/cross-build-example/src/Main.scala
@@ -0,0 +1,3 @@
+object Main extends App {
+ println("Hello World")
+}
diff --git a/plugins/essentials/MultipleScalaVersions.scala b/plugins/essentials/MultipleScalaVersions.scala
new file mode 100644
index 0000000..5d896dd
--- /dev/null
+++ b/plugins/essentials/MultipleScalaVersions.scala
@@ -0,0 +1,9 @@
+package cbt
+
+trait MultipleScalaVersions extends DynamicOverrides{
+ def scalaVersions: Seq[String] = Seq(scalaVersion, "2.10.6")
+ def cross: Seq[MultipleScalaVersions] =
+ scalaVersions.map{ v =>
+ newBuild[MultipleScalaVersions](context.copy(scalaVersion = Some(v)))("")
+ }
+}
diff --git a/stage1/cbt.scala b/stage1/cbt.scala
index 8520be4..dd06d81 100644
--- a/stage1/cbt.scala
+++ b/stage1/cbt.scala
@@ -44,7 +44,6 @@ object `package`{
// then we wouldn't need this and could provide this method from a
// plugin rather than hard-coding trigger files stuff in cbt
def triggerLoopFiles: Seq[File] = triggerLoopFilesArray.to
- def crossScalaVersions: Seq[String] = crossScalaVersionsArray.to
}
implicit class ArtifactInfoExtensions(subject: ArtifactInfo){
import subject._
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index ed03de2..b7b0854 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -41,8 +41,6 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
def defaultScalaVersion: String = constants.scalaVersion
final def scalaVersion = context.scalaVersion getOrElse defaultScalaVersion
final def scalaMajorVersion: String = lib.libMajorVersion(scalaVersion)
- def crossScalaVersions: Seq[String] = Seq(scalaVersion, "2.10.6")
- final def crossScalaVersionsArray: Array[String] = crossScalaVersions.to
def projectName = "default"
// TODO: get rid of this in favor of newBuild.
@@ -285,4 +283,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
// a method that can be called only to trigger any side-effects
final def `void` = ()
+
+ @deprecated("use the MultipleScalaVersions plugin instead","")
+ final def crossScalaVersionsArray = Array(scalaVersion)
}
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index 47e1635..dfb7ef3 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -181,6 +181,20 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger) with Scaffold{
case code if code.getClass.getSimpleName == "ExitCode" =>
// FIXME: ExitCode needs to be part of the compatibility interfaces
ExitCode(Stage0Lib.get(code,"integer").asInstanceOf[Int])
+ case Seq(b:BaseBuild) =>
+ val context = b.context.copy(args=b.context.args.drop(1))
+ val task = b.context.args.lift(0)
+ new ReflectBuild( b.copy(context=context) ).callNullary( task )
+ case Seq(b: BaseBuild, bs @ _*) if bs.forall(_.isInstanceOf[BaseBuild]) =>
+ (b +: bs)
+ .map( _.asInstanceOf[BaseBuild] )
+ .map{ b =>
+ val task = b.context.args.lift(0)
+ new ReflectBuild(
+ b.copy( context = b.context.copy(args=b.context.args.drop(1)) )
+ ).callNullary( task )
+ }
+ .head
case other =>
println( other.toString ) // no method .toConsole, using to String
ExitCode.Success
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index 0f5b557..25cd0ae 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -12,12 +12,10 @@ object Stage2 extends Stage2Base{
val paths = CbtPaths(args.cbtHome,args.cache)
import paths._
val lib = new Lib(args.logger)
-
logger.stage2(s"Stage2 start")
val loop = args.args.lift(0) == Some("loop")
- val cross = args.args.lift(0) == Some("cross")
- val taskIndex = if (loop || cross) {
+ val taskIndex = if (loop) {
1
} else {
0
@@ -44,15 +42,7 @@ object Stage2 extends Stage2Base{
val build = first.finalBuild
def call(build: BuildInterface): ExitCode = {
- if(cross){
- build.crossScalaVersions.map{
- v => new lib.ReflectBuild(
- build.copy(context.copy(scalaVersion = Some(v)))
- ).callNullary(task)
- }.filter(_ != ExitCode.Success).headOption getOrElse ExitCode.Success
- } else {
- new lib.ReflectBuild(build).callNullary(task)
- }
+ new lib.ReflectBuild(build).callNullary(task)
}
val res =