Skip to content

Commit d8bc782

Browse files
Support String Catalog symbol generation by adding String Catalogs as both Sources and Resources (#8815)
- **Explanation**: This change adds support for String Catalog symbol generation by ensuring that String Catalogs get added to the Sources build phase in the same way that Asset Catalogs do. Depends on: swiftlang/swift-build#582 - **Scope**: Packages that include String Catalogs. - **Issue**: rdar://147474472 - **Risk**: Change is already tested and in use within Xcode. - **Testing**: Unit tests added here, plus usage within Xcode.
1 parent f3feee0 commit d8bc782

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

Sources/SwiftBuildSupport/PackagePIFProjectBuilder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ struct PackagePIFProjectBuilder {
334334
self.log(.debug, indent: 2, "Added asset catalog as source file '\(resourcePath)'")
335335
}
336336

337+
// String Catalogs can also generate symbols.
338+
if SwiftBuild.SwiftBuildFileType.xcstrings.fileTypes.contains(resourcePath.pathExtension) {
339+
self.project[keyPath: sourceModuleTargetKeyPath].addSourceFile { id in
340+
BuildFile(id: id, fileRef: ref)
341+
}
342+
self.log(.debug, indent: 2, "Added string catalog as source file '\(resourcePath)'")
343+
}
344+
337345
self.log(.debug, indent: 2, "Added resource file '\(resourcePath)'")
338346
}
339347

Sources/XCBuildSupport/PIF.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,11 @@ public struct XCBuildFileType: CaseIterable {
11241124
fileTypeIdentifier: "folder.abstractassetcatalog"
11251125
)
11261126

1127+
public static let xcstrings: XCBuildFileType = XCBuildFileType(
1128+
fileType: "xcstrings",
1129+
fileTypeIdentifier: "text.json.xcstrings"
1130+
)
1131+
11271132
public static let xcdatamodeld: XCBuildFileType = XCBuildFileType(
11281133
fileType: "xcdatamodeld",
11291134
fileTypeIdentifier: "wrapper.xcdatamodeld"
@@ -1140,6 +1145,8 @@ public struct XCBuildFileType: CaseIterable {
11401145
)
11411146

11421147
public static let allCases: [XCBuildFileType] = [
1148+
.xcassets,
1149+
.xcstrings,
11431150
.xcdatamodeld,
11441151
.xcdatamodel,
11451152
.xcmappingmodel,

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
946946
pifTarget.addSourceFile(resourceFile)
947947
}
948948

949+
// String Catalogs can also generate symbols.
950+
if XCBuildFileType.xcstrings.fileTypes.contains(resource.path.extension ?? "") {
951+
pifTarget.addSourceFile(resourceFile)
952+
}
953+
949954
resourcesTarget.addResourceFile(resourceFile)
950955
}
951956

Tests/XCBuildSupportTests/PIFBuilderTests.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,12 +2201,18 @@ final class PIFBuilderTests: XCTestCase {
22012201
"/Foo/Sources/foo/main.swift",
22022202
"/Foo/Sources/foo/Resources/Data.plist",
22032203
"/Foo/Sources/foo/Resources/Database.xcdatamodel",
2204+
"/Foo/Sources/foo/Resources/Assets.xcassets",
2205+
"/Foo/Sources/foo/Resources/Localizable.xcstrings",
22042206
"/Foo/Sources/FooLib/lib.swift",
22052207
"/Foo/Sources/FooLib/Resources/Data.plist",
22062208
"/Foo/Sources/FooLib/Resources/Database.xcdatamodel",
2209+
"/Foo/Sources/FooLib/Resources/Assets.xcassets",
2210+
"/Foo/Sources/FooLib/Resources/Localizable.xcstrings",
22072211
"/Foo/Sources/FooTests/FooTests.swift",
22082212
"/Foo/Sources/FooTests/Resources/Data.plist",
2209-
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel"
2213+
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel",
2214+
"/Foo/Sources/FooTests/Resources/Assets.xcassets",
2215+
"/Foo/Sources/FooTests/Resources/Localizable.xcstrings",
22102216
)
22112217

22122218
let observability = ObservabilitySystem.makeForTesting()
@@ -2216,15 +2222,15 @@ final class PIFBuilderTests: XCTestCase {
22162222
Manifest.createRootManifest(
22172223
displayName: "Foo",
22182224
path: "/Foo",
2219-
toolsVersion: .v5_3,
2225+
toolsVersion: .v5_9,
22202226
products: [
22212227
.init(name: "FooLib", type: .library(.automatic), targets: ["FooLib"]),
22222228
],
22232229
targets: [
22242230
.init(name: "foo", resources: [
22252231
// This is intentionally specific to test that we pick up `.xcdatamodel` implicitly.
22262232
.init(rule: .process(localization: .none), path: "Resources/Data.plist"),
2227-
]),
2233+
], type: .executable),
22282234
.init(name: "FooLib", resources: [
22292235
.init(rule: .process(localization: .none), path: "Resources"),
22302236
]),
@@ -2253,7 +2259,10 @@ final class PIFBuilderTests: XCTestCase {
22532259
try workspace.checkProject("PACKAGE:/Foo") { project in
22542260
project.checkTarget("PACKAGE-PRODUCT:foo") { target in
22552261
XCTAssertEqual(target.dependencies, ["PACKAGE-RESOURCE:foo"])
2262+
// All of these file types can generate code.
22562263
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Database.xcdatamodel"))
2264+
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Assets.xcassets"))
2265+
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Localizable.xcstrings"))
22572266

22582267
target.checkBuildConfiguration("Debug") { configuration in
22592268
configuration.checkBuildSettings { settings in
@@ -2290,6 +2299,8 @@ final class PIFBuilderTests: XCTestCase {
22902299
XCTAssertEqual(target.resources, [
22912300
"/Foo/Sources/foo/Resources/Data.plist",
22922301
"/Foo/Sources/foo/Resources/Database.xcdatamodel",
2302+
"/Foo/Sources/foo/Resources/Assets.xcassets",
2303+
"/Foo/Sources/foo/Resources/Localizable.xcstrings",
22932304
])
22942305

22952306
target.checkBuildConfiguration("Debug") { configuration in
@@ -2322,6 +2333,8 @@ final class PIFBuilderTests: XCTestCase {
23222333
project.checkTarget("PACKAGE-PRODUCT:FooLib") { target in
23232334
XCTAssert(!target.dependencies.contains("PACKAGE-RESOURCE:FooLib"))
23242335
XCTAssert(!target.sources.contains("/Foo/Sources/FooLib/Resources/Database.xcdatamodel"))
2336+
XCTAssert(!target.sources.contains("/Foo/Sources/FooLib/Resources/Assets.xcassets"))
2337+
XCTAssert(!target.sources.contains("/Foo/Sources/FooLib/Resources/Localizable.xcstrings"))
23252338

23262339
target.checkBuildConfiguration("Debug") { configuration in
23272340
configuration.checkBuildSettings { settings in
@@ -2343,6 +2356,8 @@ final class PIFBuilderTests: XCTestCase {
23432356
project.checkTarget("PACKAGE-TARGET:FooLib") { target in
23442357
XCTAssertEqual(target.dependencies, ["PACKAGE-RESOURCE:FooLib"])
23452358
XCTAssert(target.sources.contains("/Foo/Sources/FooLib/Resources/Database.xcdatamodel"))
2359+
XCTAssert(target.sources.contains("/Foo/Sources/FooLib/Resources/Assets.xcassets"))
2360+
XCTAssert(target.sources.contains("/Foo/Sources/FooLib/Resources/Localizable.xcstrings"))
23462361

23472362
target.checkBuildConfiguration("Debug") { configuration in
23482363
configuration.checkBuildSettings { settings in
@@ -2372,6 +2387,8 @@ final class PIFBuilderTests: XCTestCase {
23722387
project.checkTarget("PACKAGE-PRODUCT:FooTests") { target in
23732388
XCTAssertEqual(target.dependencies, ["PACKAGE-RESOURCE:FooTests"])
23742389
XCTAssert(target.sources.contains("/Foo/Sources/FooTests/Resources/Database.xcdatamodel"))
2390+
XCTAssert(target.sources.contains("/Foo/Sources/FooTests/Resources/Assets.xcassets"))
2391+
XCTAssert(target.sources.contains("/Foo/Sources/FooTests/Resources/Localizable.xcstrings"))
23752392

23762393
target.checkBuildConfiguration("Debug") { configuration in
23772394
configuration.checkBuildSettings { settings in
@@ -2408,6 +2425,8 @@ final class PIFBuilderTests: XCTestCase {
24082425
XCTAssertEqual(target.resources, [
24092426
"/Foo/Sources/FooTests/Resources/Data.plist",
24102427
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel",
2428+
"/Foo/Sources/FooTests/Resources/Assets.xcassets",
2429+
"/Foo/Sources/FooTests/Resources/Localizable.xcstrings",
24112430
])
24122431

24132432
target.checkBuildConfiguration("Debug") { configuration in

0 commit comments

Comments
 (0)