aboutsummaryrefslogtreecommitdiff
path: root/stage1/Stage1Lib.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-04-02 15:17:36 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-04-02 15:17:36 -0400
commit10c156d83bb24486df6c040b514d072bf6b112d5 (patch)
tree6abfc2ed51fbf96e2444498bb09d45049cf014a3 /stage1/Stage1Lib.scala
parentb9f8ff66c9e61daab016cc8e595f388f449ec780 (diff)
downloadcbt-10c156d83bb24486df6c040b514d072bf6b112d5.tar.gz
cbt-10c156d83bb24486df6c040b514d072bf6b112d5.tar.bz2
cbt-10c156d83bb24486df6c040b514d072bf6b112d5.zip
only compile and only produce jars if there are actually files.
This seem desirable, but also fixes a test failure for which I have no idea why it didn't fail before but now.
Diffstat (limited to 'stage1/Stage1Lib.scala')
-rw-r--r--stage1/Stage1Lib.scala104
1 files changed, 53 insertions, 51 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index e4fe15e..105fe3e 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -127,64 +127,66 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
classLoaderCache: ClassLoaderCache,
zincVersion: String,
scalaVersion: String
- ): File = {
+ ): Option[File] = {
val cp = classpath.string
if(classpath.files.isEmpty)
throw new Exception("Trying to compile with empty classpath. Source files: " ++ files.toString)
- if(files.isEmpty)
- throw new Exception("Trying to compile no files. ClassPath: " ++ cp)
- if( needsRecompile ){
- val zinc = JavaDependency("com.typesafe.zinc","zinc", zincVersion)
- val zincDeps = zinc.transitiveDependencies
-
- val sbtInterface =
- zincDeps
- .collect{ case d @ JavaDependency( "com.typesafe.sbt", "sbt-interface", _, Classifier.none ) => d }
- .headOption
- .getOrElse( throw new Exception(s"cannot find sbt-interface in zinc $zincVersion dependencies: "++zincDeps.toString) )
- .jar
-
- val compilerInterface =
- zincDeps
- .collect{ case d @ JavaDependency( "com.typesafe.sbt", "compiler-interface", _, Classifier.sources ) => d }
- .headOption
- .getOrElse( throw new Exception(s"cannot find compiler-interface in zinc $zincVersion dependencies: "++zincDeps.toString) )
- .jar
-
- val scalaLibrary = JavaDependency("org.scala-lang","scala-library",scalaVersion).jar
- val scalaReflect = JavaDependency("org.scala-lang","scala-reflect",scalaVersion).jar
- val scalaCompiler = JavaDependency("org.scala-lang","scala-compiler",scalaVersion).jar
-
- val start = System.currentTimeMillis
-
- val code = redirectOutToErr{
- lib.runMain(
- "com.typesafe.zinc.Main",
- Seq(
- "-scala-compiler", scalaCompiler.toString,
- "-scala-library", scalaLibrary.toString,
- "-sbt-interface", sbtInterface.toString,
- "-compiler-interface", compilerInterface.toString,
- "-scala-extra", scalaReflect.toString,
- "-cp", cp,
- "-d", compileTarget.toString
- ) ++ scalacOptions.map("-S"++_) ++ files.map(_.toString),
- zinc.classLoader(classLoaderCache)
- )
- }
-
- if(code == ExitCode.Success){
- // write version and when last compilation started so we can trigger
- // recompile if cbt version changed or newer source files are seen
- Files.write(statusFile.toPath, "".getBytes)//cbtVersion.getBytes)
- Files.setLastModifiedTime(statusFile.toPath, FileTime.fromMillis(start) )
- } else {
- System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
+ if( files.isEmpty ){
+ None
+ }else{
+ if( needsRecompile ){
+ val zinc = JavaDependency("com.typesafe.zinc","zinc", zincVersion)
+ val zincDeps = zinc.transitiveDependencies
+
+ val sbtInterface =
+ zincDeps
+ .collect{ case d @ JavaDependency( "com.typesafe.sbt", "sbt-interface", _, Classifier.none ) => d }
+ .headOption
+ .getOrElse( throw new Exception(s"cannot find sbt-interface in zinc $zincVersion dependencies: "++zincDeps.toString) )
+ .jar
+
+ val compilerInterface =
+ zincDeps
+ .collect{ case d @ JavaDependency( "com.typesafe.sbt", "compiler-interface", _, Classifier.sources ) => d }
+ .headOption
+ .getOrElse( throw new Exception(s"cannot find compiler-interface in zinc $zincVersion dependencies: "++zincDeps.toString) )
+ .jar
+
+ val scalaLibrary = JavaDependency("org.scala-lang","scala-library",scalaVersion).jar
+ val scalaReflect = JavaDependency("org.scala-lang","scala-reflect",scalaVersion).jar
+ val scalaCompiler = JavaDependency("org.scala-lang","scala-compiler",scalaVersion).jar
+
+ val start = System.currentTimeMillis
+
+ val code = redirectOutToErr{
+ lib.runMain(
+ "com.typesafe.zinc.Main",
+ Seq(
+ "-scala-compiler", scalaCompiler.toString,
+ "-scala-library", scalaLibrary.toString,
+ "-sbt-interface", sbtInterface.toString,
+ "-compiler-interface", compilerInterface.toString,
+ "-scala-extra", scalaReflect.toString,
+ "-cp", cp,
+ "-d", compileTarget.toString
+ ) ++ scalacOptions.map("-S"++_) ++ files.map(_.toString),
+ zinc.classLoader(classLoaderCache)
+ )
+ }
+
+ if(code == ExitCode.Success){
+ // write version and when last compilation started so we can trigger
+ // recompile if cbt version changed or newer source files are seen
+ Files.write(statusFile.toPath, "".getBytes)//cbtVersion.getBytes)
+ Files.setLastModifiedTime(statusFile.toPath, FileTime.fromMillis(start) )
+ } else {
+ System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
+ }
}
+ Some( compileTarget )
}
- compileTarget
}
def redirectOutToErr[T](code: => T): T = {
val oldOut = System.out