From 8ebada86b1fc58465751864acba8aafd387ccb4b Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Thu, 10 Nov 2016 01:40:14 -0500 Subject: 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. --- stage2/BasicBuild.scala | 5 +++-- stage2/Lib.scala | 14 ++++++++++++++ stage2/Stage2.scala | 14 ++------------ 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'stage2') 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 = -- cgit v1.2.3 From 9f89d16aa3ca5f96d73a8394d5159dc78dd5d7cf Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Sun, 13 Nov 2016 13:28:36 -0500 Subject: multi-project build example using a single build file --- examples/multi-combined-example/Readme.md | 1 + examples/multi-combined-example/build/build.scala | 44 ++++++++++++++++++++++ .../shared/SomeSharedClass.scala | 6 +++ .../sub1/SomeConcreteClass.scala | 2 + .../sub2/SomeOtherConcreteClass.scala | 2 + examples/multi-standalone-example/Readme.md | 3 ++ stage2/Lib.scala | 2 +- test/test.scala | 1 + 8 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 examples/multi-combined-example/Readme.md create mode 100644 examples/multi-combined-example/build/build.scala create mode 100644 examples/multi-combined-example/shared/SomeSharedClass.scala create mode 100644 examples/multi-combined-example/sub1/SomeConcreteClass.scala create mode 100644 examples/multi-combined-example/sub2/SomeOtherConcreteClass.scala create mode 100644 examples/multi-standalone-example/Readme.md (limited to 'stage2') diff --git a/examples/multi-combined-example/Readme.md b/examples/multi-combined-example/Readme.md new file mode 100644 index 0000000..01302d4 --- /dev/null +++ b/examples/multi-combined-example/Readme.md @@ -0,0 +1 @@ +This is an example how to do a multi-project build with a single build file. diff --git a/examples/multi-combined-example/build/build.scala b/examples/multi-combined-example/build/build.scala new file mode 100644 index 0000000..41c03d6 --- /dev/null +++ b/examples/multi-combined-example/build/build.scala @@ -0,0 +1,44 @@ +import cbt._ +import cbt._ +trait SharedCbtBuild extends BaseBuild{ + override def defaultScalaVersion = "2.10.6" +} + + +class Shared(val context: Context) extends SharedCbtBuild + +class Sub(val context:Context) extends SharedCbtBuild{ + override def dependencies = Seq(new Shared( + context.copy( + projectDirectory = projectDirectory ++ "/../shared" + ) + )) +} + +class Build(val context: Context) extends BaseBuild{ + /* + Currently each sub build nested into the main build needs to be an instance + of a top-level class taking a Context as the sole parameter, similar to the + Build class itself. This restriction may be lifted for more flexibility at + some point, see https://github.com/cvogt/cbt/issues/306 + */ + def sub1 = new Sub( + context.copy( + projectDirectory = projectDirectory ++ "/sub1" + ) + ) + def sub2 = new Sub( + context.copy( + projectDirectory = projectDirectory ++ "/sub2" + ) + ) + + def sub3 = // DON'T DO THIS, anonymous classes are currently not supported here. + new SharedCbtBuild{ + def context = Build.this.context.copy( + projectDirectory = Build.this.projectDirectory ++ "/sub3" + ) + } + + override def dependencies = Seq( sub1, sub2 ) // assembles all projects +} diff --git a/examples/multi-combined-example/shared/SomeSharedClass.scala b/examples/multi-combined-example/shared/SomeSharedClass.scala new file mode 100644 index 0000000..d7d99e4 --- /dev/null +++ b/examples/multi-combined-example/shared/SomeSharedClass.scala @@ -0,0 +1,6 @@ +package cbt.examples.multi_combined +class SomeSharedClass{ + def main(args: Array[String]): Unit = { + println(this.getClass.getSimpleName) + } +} diff --git a/examples/multi-combined-example/sub1/SomeConcreteClass.scala b/examples/multi-combined-example/sub1/SomeConcreteClass.scala new file mode 100644 index 0000000..e55cb12 --- /dev/null +++ b/examples/multi-combined-example/sub1/SomeConcreteClass.scala @@ -0,0 +1,2 @@ +package cbt.examples.multi_combined +object SomeConcreteClass extends SomeSharedClass diff --git a/examples/multi-combined-example/sub2/SomeOtherConcreteClass.scala b/examples/multi-combined-example/sub2/SomeOtherConcreteClass.scala new file mode 100644 index 0000000..399aee6 --- /dev/null +++ b/examples/multi-combined-example/sub2/SomeOtherConcreteClass.scala @@ -0,0 +1,2 @@ +package cbt.examples.multi_combined +object SomeOtherConcreteClass extends SomeSharedClass diff --git a/examples/multi-standalone-example/Readme.md b/examples/multi-standalone-example/Readme.md new file mode 100644 index 0000000..be89598 --- /dev/null +++ b/examples/multi-standalone-example/Readme.md @@ -0,0 +1,3 @@ +This is an example how to build a multi-project build using CBT while keeping each project self-contained with it's own build files. + +Check the multi-combined-example for how to do it with a single build file for all builds together instead. diff --git a/stage2/Lib.scala b/stage2/Lib.scala index dfb7ef3..fcf2642 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -181,7 +181,7 @@ 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) => + case 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 ) diff --git a/test/test.scala b/test/test.scala index 22b7c87..ca9d87b 100644 --- a/test/test.scala +++ b/test/test.scala @@ -205,6 +205,7 @@ object Main{ compile("../examples/scalajs-react-example/js") compile("../examples/scalajs-react-example/jvm") compile("../examples/multi-standalone-example") + compile("../examples/multi-combined-example") if(sys.props("java.version").startsWith("1.7")){ System.err.println("\nskipping dotty tests on Java 7") } else { -- cgit v1.2.3