@@ -28,8 +28,10 @@ import com.google.common.jimfs.Jimfs
28
28
29
29
import scala .tools .partest .scalajs .ScalaJSPartestOptions ._
30
30
31
+ import java .io .IOException
31
32
import java .net .URL
32
33
import java .nio .file ._
34
+ import java .nio .file .attribute .BasicFileAttributes
33
35
34
36
import scala .io .Source
35
37
import scala .concurrent .Await
@@ -112,51 +114,56 @@ class MainGenericRunner {
112
114
/* The Wasm output needs to read other files in the same directory,
113
115
* with predictable names. Therefore, we need to use real files.
114
116
*/
115
- val tempDir = Files .createTempDirectory(" tmp-scalajs-partest" )
116
- tempDir.toFile().deleteOnExit()
117
- tempDir
117
+ Files .createTempDirectory(" tmp-scalajs-partest" )
118
118
}
119
+ try {
120
+ val sjsCode = {
121
+ val cache = StandardImpl .irFileCache().newCache
122
+ val result = PathIRContainer
123
+ .fromClasspath(command.settings.classpathURLs.map(urlToPath _))
124
+ .map(_._1)
125
+ .flatMap(cache.cached _)
126
+ .flatMap(linker.link(_, moduleInitializers, PathOutputDirectory (dir), logger))
119
127
120
- val sjsCode = {
121
- val cache = StandardImpl .irFileCache().newCache
122
- val result = PathIRContainer
123
- .fromClasspath(command.settings.classpathURLs.map(urlToPath _))
124
- .map(_._1)
125
- .flatMap(cache.cached _)
126
- .flatMap(linker.link(_, moduleInitializers, PathOutputDirectory (dir), logger))
127
-
128
- val report = Await .result(result, Duration .Inf )
128
+ val report = Await .result(result, Duration .Inf )
129
129
130
- if (report.publicModules.size != 1 )
131
- throw new AssertionError (s " got other than 1 module: $report" )
130
+ if (report.publicModules.size != 1 )
131
+ throw new AssertionError (s " got other than 1 module: $report" )
132
132
133
- dir.resolve(report.publicModules.head.jsFileName)
134
- }
133
+ dir.resolve(report.publicModules.head.jsFileName)
134
+ }
135
135
136
- val jsEnvConfig : NodeJSEnv .Config = if (! useWasm) {
137
- NodeJSEnv .Config ()
138
- } else {
139
- NodeJSEnv .Config ().withArgs(List (
140
- " --experimental-wasm-exnref" ,
141
- " --experimental-wasm-imported-strings" , // for JS string builtins
142
- /* Force using the Turboshaft infrastructure for the optimizing compiler.
143
- * It appears to be more stable for the Wasm that we throw at it.
144
- * See also the use of this flag in Build.scala.
145
- */
146
- " --turboshaft-wasm"
147
- ))
148
- }
136
+ val jsEnvConfig : NodeJSEnv .Config = if (! useWasm) {
137
+ NodeJSEnv .Config ()
138
+ } else {
139
+ NodeJSEnv .Config ().withArgs(List (
140
+ " --experimental-wasm-exnref" ,
141
+ " --experimental-wasm-imported-strings" , // for JS string builtins
142
+ /* Force using the Turboshaft infrastructure for the optimizing compiler.
143
+ * It appears to be more stable for the Wasm that we throw at it.
144
+ * See also the use of this flag in Build.scala.
145
+ */
146
+ " --turboshaft-wasm"
147
+ ))
148
+ }
149
149
150
- val input =
151
- if (useESModule) Input .ESModule (sjsCode) :: Nil
152
- else Input .Script (sjsCode) :: Nil
153
- val config = RunConfig ().withLogger(logger)
150
+ val input =
151
+ if (useESModule) Input .ESModule (sjsCode) :: Nil
152
+ else Input .Script (sjsCode) :: Nil
153
+ val config = RunConfig ().withLogger(logger)
154
154
155
- val run = new NodeJSEnv (jsEnvConfig).start(input, config)
156
- try {
157
- Await .result(run.future, Duration .Inf )
155
+ val run = new NodeJSEnv (jsEnvConfig).start(input, config)
156
+ try {
157
+ Await .result(run.future, Duration .Inf )
158
+ } finally {
159
+ run.close()
160
+ }
158
161
} finally {
159
- run.close()
162
+ /* If using Wasm, we created actual files that we must delete.
163
+ * For JS, we use an in-memory file system, so there is no point.
164
+ */
165
+ if (useWasm)
166
+ recursivelyDeleteDir(dir)
160
167
}
161
168
162
169
true
@@ -169,6 +176,20 @@ class MainGenericRunner {
169
176
case e : java.net.URISyntaxException => Paths .get(url.getPath())
170
177
}
171
178
}
179
+
180
+ private def recursivelyDeleteDir (directory : Path ): Unit = {
181
+ Files .walkFileTree(directory, new SimpleFileVisitor [Path ] {
182
+ override def visitFile (file : Path , attrs : BasicFileAttributes ): FileVisitResult = {
183
+ Files .delete(file)
184
+ FileVisitResult .CONTINUE
185
+ }
186
+
187
+ override def postVisitDirectory (dir : Path , exc : IOException ): FileVisitResult = {
188
+ Files .delete(dir)
189
+ FileVisitResult .CONTINUE
190
+ }
191
+ })
192
+ }
172
193
}
173
194
174
195
object MainGenericRunner extends MainGenericRunner {
0 commit comments