diff options
-rw-r--r-- | project/Build.scala | 18 | ||||
-rw-r--r-- | test/test/CompilerTest.scala | 12 | ||||
-rw-r--r-- | tests/partest.lock | 0 |
3 files changed, 21 insertions, 9 deletions
diff --git a/project/Build.scala b/project/Build.scala index ef9d1375a..61a7e4826 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1,6 +1,7 @@ import sbt.Keys._ import sbt._ - +import java.io.{ RandomAccessFile, File } +import java.nio.channels.{ FileLock, OverlappingFileLockException } object DottyBuild extends Build { val TRAVIS_BUILD = "dotty.travis.build" @@ -10,6 +11,7 @@ object DottyBuild extends Build { // "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so" ) + var partestLock: FileLock = null val defaults = Defaults.defaultSettings ++ Seq( // set sources to src/, tests to test/ and resources to resources/ @@ -48,11 +50,14 @@ object DottyBuild extends Build { // enable verbose exception messages for JUnit testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "--run-listener=test.ContextEscapeDetector"), - // when this file is present, running test generates the files for partest + testOptions in Test += Tests.Cleanup({ () => if (partestLock != null) partestLock.release }), + // when this file is locked, running test generates the files for partest // otherwise it just executes the tests directly - createPartestFile := { new java.io.File("./tests", "runPartest.flag").createNewFile }, + lockPartestFile := { + val partestLockFile = "." + File.separator + "tests" + File.separator + "partest.lock" + partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock + }, runPartestRunner <<= runTask(Test, "dotty.partest.DPConsoleRunner", "") dependsOn (test in Test), - deletePartestFile := { new java.io.File("./tests", "runPartest.flag").delete }, // Adjust classpath for running dotty mainClass in (Compile, run) := Some("dotty.tools.dotc.Main"), @@ -86,7 +91,7 @@ object DottyBuild extends Build { tuning ::: agentOptions ::: travis_build ::: fullpath } - ) ++ addCommandAlias("partest", ";createPartestFile;runPartestRunner;deletePartestFile") + ) ++ addCommandAlias("partest", ";lockPartestFile;runPartestRunner") lazy val dotty = Project(id = "dotty", base = file("."), settings = defaults) @@ -137,8 +142,7 @@ object DottyBuild extends Build { lazy val benchmarks = Project(id = "dotty-bench", settings = benchmarkSettings, base = file("bench")) dependsOn(dotty % "compile->test") - lazy val createPartestFile = TaskKey[Unit]("createPartestFile", "Creates the tests/runPartest.flag file") + lazy val lockPartestFile = TaskKey[Unit]("lockPartestFile", "Creates the file lock on ./tests/partest.lock") lazy val runPartestRunner = TaskKey[Unit]("runPartestRunner", "Runs partests") - lazy val deletePartestFile = TaskKey[Unit]("deletePartestFile", "Deletes the tests/runPartest.flag file") } diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 23bdfd829..1dd65b6e0 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -6,7 +6,8 @@ import dotty.tools.dotc.reporting.Reporter import scala.collection.mutable.ListBuffer import scala.reflect.io.{ Path, Directory, File => SFile } import scala.tools.partest.nest.FileManager -import java.io.{ File => JFile } +import java.io.{ RandomAccessFile, File => JFile } + import org.junit.Test @@ -39,7 +40,14 @@ abstract class CompilerTest extends DottyTest { def partestableDir(prefix: String, dirName: String, args: List[String], xerrors: Int) = true def partestableList(testName: String, files: List[String], args: List[String], xerrors: Int) = true - val generatePartestFiles = new JFile("tests", "runPartest.flag").exists + val generatePartestFiles = { + val partestLockFile = "." + JFile.separator + "tests" + JFile.separator + "partest.lock" + val partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock + if (partestLock != null) { // file not locked by sbt -> don't generate partest + partestLock.release + false + } else true + } // Delete generated files from previous run if (generatePartestFiles) diff --git a/tests/partest.lock b/tests/partest.lock new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/partest.lock |