@@ -3,11 +3,19 @@ import PackagePlugin
3
3
4
4
/// Plans the build for packaging.
5
5
struct PackagingPlanner {
6
+ /// The options of the plugin
6
7
let options : PackageToJS . Options
8
+ /// The context of the plugin
7
9
let context : PluginContext
10
+ /// The package that contains this plugin
8
11
let selfPackage : Package
12
+ /// The path of this file itself, used to capture changes of planner code
9
13
let selfPath : String
14
+ /// The directory for the final output
10
15
let outputDir : URL
16
+ /// The directory for intermediate files
17
+ let intermediatesDir : URL
18
+ /// The filename of the .wasm file
11
19
let wasmFilename = " main.wasm "
12
20
13
21
init (
@@ -18,6 +26,7 @@ struct PackagingPlanner {
18
26
self . context = context
19
27
self . selfPackage = selfPackage
20
28
self . outputDir = outputDir
29
+ self . intermediatesDir = context. pluginWorkDirectoryURL. appending ( path: outputDir. lastPathComponent + " .tmp " )
21
30
self . selfPath = String ( #filePath)
22
31
}
23
32
@@ -98,19 +107,18 @@ struct PackagingPlanner {
98
107
99
108
if let wasmOptPath = wasmOptPath, shouldOptimize {
100
109
// Optimize the wasm in release mode
101
- let tmpDir = outputDir. deletingLastPathComponent ( ) . appending ( path: " \( outputDir. lastPathComponent) .tmp " )
102
- let tmpDirTask = make. addTask (
103
- inputFiles: [ selfPath] , output: tmpDir. path, attributes: [ . silent]
110
+ let intermediatesDirTask = make. addTask (
111
+ inputFiles: [ selfPath] , output: intermediatesDir. path, attributes: [ . silent]
104
112
) {
105
113
try Self . createDirectory ( atPath: $0. output)
106
114
}
107
115
// If splitDebug is true, we need to place the DWARF-stripped wasm file (but "name" section remains)
108
116
// in the output directory.
109
- let stripWasmPath = ( splitDebug ? outputDir : tmpDir ) . appending ( path: wasmFilename + " .debug " ) . path
117
+ let stripWasmPath = ( splitDebug ? outputDir : intermediatesDir ) . appending ( path: wasmFilename + " .debug " ) . path
110
118
111
119
// First, strip DWARF sections as their existence enables DWARF preserving mode in wasm-opt
112
120
let stripWasm = make. addTask (
113
- inputFiles: [ selfPath, wasmProductArtifact. path] , inputTasks: [ outputDirTask, tmpDirTask ] ,
121
+ inputFiles: [ selfPath, wasmProductArtifact. path] , inputTasks: [ outputDirTask, intermediatesDirTask ] ,
114
122
output: stripWasmPath
115
123
) {
116
124
print ( " Stripping DWARF debug info... " )
0 commit comments