Skip to content

Commit 01b5d8d

Browse files
committed
BridgeJS: Fix an issue where the skeleton was being treated as a resource
1 parent d8358e6 commit 01b5d8d

3 files changed

Lines changed: 54 additions & 11 deletions

File tree

Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
2020

2121
private func createGenerateCommand(context: PluginContext, target: SwiftSourceModuleTarget) throws -> Command {
2222
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.swift")
23-
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "JavaScript/BridgeJS.json")
2423

2524
let inputSwiftFiles = target.sourceFiles.filter {
2625
!$0.url.path.hasPrefix(context.pluginWorkDirectoryURL.path + "/")
@@ -67,9 +66,14 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
6766
for skeleton in dependencySkeletons(context: context, target: target) {
6867
arguments.append(contentsOf: [
6968
"--dependency-skeleton",
70-
"\(skeleton.moduleName)=\(skeleton.url.path)",
69+
"\(skeleton.moduleName)=\(skeleton.skeletonURL.path)",
7170
])
72-
inputFiles.append(skeleton.url)
71+
// We have to use the Swift file, not the skeleton, as the input file,
72+
// since we can’t make the skeleton file an output file without it being
73+
// treated as a resource by the build system (and thus included in the
74+
// resource bundle). We need to use something as the inputFile to maintain
75+
// correct ordering.
76+
inputFiles.append(skeleton.bridgeJSSwiftURL)
7377
}
7478

7579
let allSwiftFiles = inputSwiftFiles + pluginGeneratedSwiftFiles
@@ -80,13 +84,14 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
8084
executable: try context.tool(named: "BridgeJSTool").url,
8185
arguments: arguments,
8286
inputFiles: inputFiles,
83-
outputFiles: [outputSwiftPath, outputSkeletonPath]
87+
outputFiles: [outputSwiftPath]
8488
)
8589
}
8690

8791
private struct DependencySkeleton {
8892
let moduleName: String
89-
let url: URL
93+
let skeletonURL: URL
94+
let bridgeJSSwiftURL: URL
9095
}
9196

9297
/// We only read skeletons from dependencies with a `bridge-js.config.json` file.
@@ -118,7 +123,18 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
118123
packageID: context.package.id,
119124
buildPluginWorkDirectoryURL: context.pluginWorkDirectoryURL
120125
)
121-
skeletons.append(DependencySkeleton(moduleName: swiftTarget.name, url: skeletonURL))
126+
let bridgeJSSwiftURL = BridgeJSPluginPaths.bridgeJSSwiftURL(
127+
targetName: swiftTarget.name,
128+
packageID: context.package.id,
129+
buildPluginWorkDirectoryURL: context.pluginWorkDirectoryURL
130+
)
131+
skeletons.append(
132+
DependencySkeleton(
133+
moduleName: swiftTarget.name,
134+
skeletonURL: skeletonURL,
135+
bridgeJSSwiftURL: bridgeJSSwiftURL
136+
)
137+
)
122138
}
123139
return skeletons
124140
}

Plugins/BridgeJS/Sources/BridgeJSPluginUtilities/PluginPaths.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ enum BridgeJSPluginPaths {
1313
.deletingLastPathComponent()
1414
.deletingLastPathComponent()
1515
.deletingLastPathComponent()
16-
return skeletonURL(
16+
return bridgeJSDirectoryURL(
1717
targetName: targetName,
1818
packageID: packageID,
1919
pluginsOutputsRootURL: pluginsOutputsRootURL
2020
)
21+
.appending(path: "JavaScript/BridgeJS.json")
2122
}
2223

2324
static func skeletonURL(
@@ -32,22 +33,42 @@ enum BridgeJSPluginPaths {
3233
.deletingLastPathComponent()
3334
.deletingLastPathComponent()
3435
.appending(path: "outputs")
35-
return skeletonURL(
36+
return bridgeJSDirectoryURL(
3637
targetName: targetName,
3738
packageID: packageID,
3839
pluginsOutputsRootURL: pluginsOutputsRootURL
3940
)
41+
.appending(path: "JavaScript/BridgeJS.json")
4042
}
4143

42-
private static func skeletonURL(
44+
static func bridgeJSSwiftURL(
45+
targetName: String,
46+
packageID: String,
47+
buildPluginWorkDirectoryURL workDirectoryURL: URL
48+
) -> URL {
49+
let pluginsOutputsRootURL =
50+
workDirectoryURL
51+
.deletingLastPathComponent()
52+
.deletingLastPathComponent()
53+
.deletingLastPathComponent()
54+
.deletingLastPathComponent()
55+
return bridgeJSDirectoryURL(
56+
targetName: targetName,
57+
packageID: packageID,
58+
pluginsOutputsRootURL: pluginsOutputsRootURL
59+
)
60+
.appending(path: "BridgeJS.swift")
61+
}
62+
63+
private static func bridgeJSDirectoryURL(
4364
targetName: String,
4465
packageID: String,
4566
pluginsOutputsRootURL: URL
4667
) -> URL {
4768
pluginsOutputsRootURL
4869
.appending(path: packageID)
4970
.appending(path: targetName)
50-
.appending(path: "destination/BridgeJS/JavaScript/BridgeJS.json")
71+
.appending(path: "destination/BridgeJS")
5172
}
5273
}
5374
#endif

Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,13 @@ import BridgeJSUtilities
250250
}
251251
}
252252

253-
// Write unified skeleton
253+
// Write unified skeleton.
254+
// Note that for the build system to sequence the BridgeJSBuildPlugin correctly,
255+
// the skeleton and the Swift output must form a bijection, i.e. if one changes the
256+
// other must also change. This is because we can’t use the BridgeJS.json file
257+
// as an outputFile, since it would then be treated as a resource and thus included
258+
// in the generated bundle. The invariant currently holds, but if this ever changes the
259+
// BridgeJS.swift file could include a hash of the skeleton to maintain it.
254260
let outputSkeletonURL = outputDirectory.appending(path: "JavaScript/BridgeJS.json")
255261
try withSpan("Writing output skeleton") {
256262
try FileManager.default.createDirectory(

0 commit comments

Comments
 (0)