1
1
import sbt .Keys ._
2
2
import sbt ._
3
-
3
+ import java .io .{ RandomAccessFile , File }
4
+ import java .nio .channels .{ FileLock , OverlappingFileLockException }
4
5
object DottyBuild extends Build {
5
6
6
7
val TRAVIS_BUILD = " dotty.travis.build"
@@ -10,6 +11,7 @@ object DottyBuild extends Build {
10
11
// "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so"
11
12
)
12
13
14
+ var partestLock : FileLock = null
13
15
14
16
val defaults = Defaults .defaultSettings ++ Seq (
15
17
// set sources to src/, tests to test/ and resources to resources/
@@ -48,11 +50,14 @@ object DottyBuild extends Build {
48
50
49
51
// enable verbose exception messages for JUnit
50
52
testOptions in Test += Tests .Argument (TestFrameworks .JUnit , " -a" , " -v" , " --run-listener=test.ContextEscapeDetector" ),
51
- // when this file is present, running test generates the files for partest
53
+ testOptions in Test += Tests .Cleanup ({ () => if (partestLock != null ) partestLock.release }),
54
+ // when this file is locked, running test generates the files for partest
52
55
// otherwise it just executes the tests directly
53
- createPartestFile := { new java.io.File (" ./tests" , " runPartest.flag" ).createNewFile },
56
+ lockPartestFile := {
57
+ val partestLockFile = " ." + File .separator + " tests" + File .separator + " partest.lock"
58
+ partestLock = new RandomAccessFile (partestLockFile, " rw" ).getChannel.tryLock
59
+ },
54
60
runPartestRunner <<= runTask(Test , " dotty.partest.DPConsoleRunner" , " " ) dependsOn (test in Test ),
55
- deletePartestFile := { new java.io.File (" ./tests" , " runPartest.flag" ).delete },
56
61
57
62
// Adjust classpath for running dotty
58
63
mainClass in (Compile , run) := Some (" dotty.tools.dotc.Main" ),
@@ -86,7 +91,7 @@ object DottyBuild extends Build {
86
91
87
92
tuning ::: agentOptions ::: travis_build ::: fullpath
88
93
}
89
- ) ++ addCommandAlias(" partest" , " ;createPartestFile ;runPartestRunner;deletePartestFile " )
94
+ ) ++ addCommandAlias(" partest" , " ;lockPartestFile ;runPartestRunner" )
90
95
91
96
lazy val dotty = Project (id = " dotty" , base = file(" ." ), settings = defaults)
92
97
@@ -137,8 +142,7 @@ object DottyBuild extends Build {
137
142
lazy val benchmarks = Project (id = " dotty-bench" , settings = benchmarkSettings,
138
143
base = file(" bench" )) dependsOn(dotty % " compile->test" )
139
144
140
- lazy val createPartestFile = TaskKey [Unit ](" createPartestFile " , " Creates the tests/runPartest.flag file " )
145
+ lazy val lockPartestFile = TaskKey [Unit ](" lockPartestFile " , " Creates the file lock on ./ tests/partest.lock " )
141
146
lazy val runPartestRunner = TaskKey [Unit ](" runPartestRunner" , " Runs partests" )
142
- lazy val deletePartestFile = TaskKey [Unit ](" deletePartestFile" , " Deletes the tests/runPartest.flag file" )
143
147
144
148
}
0 commit comments