diff options
author | Matt Farmer <matt@frmr.me> | 2016-03-12 11:33:37 -0500 |
---|---|---|
committer | Matt Farmer <matt@frmr.me> | 2016-03-12 11:33:37 -0500 |
commit | 6d20a6b183a105ab0faa803c3d6497a7025350d7 (patch) | |
tree | e6515d76ebaf999bbbe8d2a2bf10377280f15238 /stage1/Stage1Lib.scala | |
parent | b143c01a2e180b647eb27338cb7302aa38ef10c6 (diff) | |
download | cbt-6d20a6b183a105ab0faa803c3d6497a7025350d7.tar.gz cbt-6d20a6b183a105ab0faa803c3d6497a7025350d7.tar.bz2 cbt-6d20a6b183a105ab0faa803c3d6497a7025350d7.zip |
Bubble zinc error codes to calling script.
We were previously eating zinc error codes because we invoked
trapExitCode twice in the same call stack.
Diffstat (limited to 'stage1/Stage1Lib.scala')
-rw-r--r-- | stage1/Stage1Lib.scala | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 67ae049..f9f1fdd 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -85,7 +85,7 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{ Files.move(incomplete, Paths.get(target.string), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); } } - + def listFilesRecursive(f: File): Seq[File] = { f +: ( if( f.isDirectory ) f.listFiles.flatMap(listFilesRecursive).toVector else Seq[File]() @@ -154,30 +154,30 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{ val scalaCompiler = MavenDependency("org.scala-lang","scala-compiler",scalaVersion)(logger).jar val code = redirectOutToErr{ - trapExitCode{ - 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 - ) ++ extraArgs.map("-S"++_) ++ files.map(_.toString), - zinc.classLoader - ) - } + 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 + ) ++ extraArgs.map("-S"++_) ++ files.map(_.toString), + zinc.classLoader + ) } + if(code != ExitCode.Success){ - // FIXME: zinc currently always returns exit code 0 // hack that triggers recompilation next time. Nicer solution? val now = System.currentTimeMillis() files.foreach{_.setLastModified(now)} + + // Tell the caller that things went wrong. + System.exit(code.code) } } - } def redirectOutToErr[T](code: => T): T = { val oldOut = System.out @@ -189,42 +189,35 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{ } } - def trapExitCode( code: => Unit ): ExitCode = { - /* - Doesn't seem to work reliably. Seems like the Security manager is not always - reset properly. Maybe some non-thread-safety issue or some Nailgun interaction. - + private val trapSecurityManager = new SecurityManager { + override def checkPermission( permission: Permission ) = { + /* + NOTE: is it actually ok, to just make these empty? + Calling .super leads to ClassNotFound exteption for a lambda. + Calling to the previous SecurityManager leads to a stack overflow + */ + } + override def checkPermission( permission: Permission, context: Any ) = { + /* Does this methods need to be overidden? */ + } + override def checkExit( status: Int ) = { + super.checkExit(status) + logger.lib(s"checkExit($status)") + throw new TrappedExitCode(status) + } + } + def trapExitCode( code: => Unit ): ExitCode = { val old: Option[SecurityManager] = Option(System.getSecurityManager()) try{ - val securityManager = new SecurityManager{ - override def checkPermission( permission: Permission ) = { - /* - NOTE: is it actually ok, to just make these empty? - Calling .super leads to ClassNotFound exteption for a lambda. - Calling to the previous SecurityManager leads to a stack overflow - */ - } - override def checkPermission( permission: Permission, context: Any ) = { - /* Does this methods need to be overidden? */ - } - override def checkExit( status: Int ) = { - super.checkExit(status) - logger.lib(s"checkExit($status)") - throw new TrappedExitCode(status) - } - } - System.setSecurityManager( securityManager ) + System.setSecurityManager( trapSecurityManager ) code ExitCode.Success } catch { - case TrappedExitCode(exitCode) => exitCode + case TrappedExitCode(exitCode) => + exitCode } finally { System.setSecurityManager(old.getOrElse(null)) } - */ - code - ExitCode.Success } } - |