Skip to content

Support String Catalog symbol generation by adding String Catalogs as both Sources and Resources #8815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SwiftBuildSupport/PackagePIFProjectBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ struct PackagePIFProjectBuilder {
self.log(.debug, indent: 2, "Added asset catalog as source file '\(resourcePath)'")
}

// String Catalogs can also generate symbols.
if SwiftBuild.SwiftBuildFileType.xcstrings.fileTypes.contains(resourcePath.pathExtension) {
self.project[keyPath: sourceModuleTargetKeyPath].addSourceFile { id in
BuildFile(id: id, fileRef: ref)
}
self.log(.debug, indent: 2, "Added string catalog as source file '\(resourcePath)'")
}

self.log(.debug, indent: 2, "Added resource file '\(resourcePath)'")
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/XCBuildSupport/PIF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,11 @@ public struct XCBuildFileType: CaseIterable {
fileTypeIdentifier: "folder.abstractassetcatalog"
)

public static let xcstrings: XCBuildFileType = XCBuildFileType(
fileType: "xcstrings",
fileTypeIdentifier: "text.json.xcstrings"
)

public static let xcdatamodeld: XCBuildFileType = XCBuildFileType(
fileType: "xcdatamodeld",
fileTypeIdentifier: "wrapper.xcdatamodeld"
Expand All @@ -1140,6 +1145,8 @@ public struct XCBuildFileType: CaseIterable {
)

public static let allCases: [XCBuildFileType] = [
.xcassets,
.xcstrings,
.xcdatamodeld,
.xcdatamodel,
.xcmappingmodel,
Expand Down
5 changes: 5 additions & 0 deletions Sources/XCBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
pifTarget.addSourceFile(resourceFile)
}

// String Catalogs can also generate symbols.
if XCBuildFileType.xcstrings.fileTypes.contains(resource.path.extension ?? "") {
pifTarget.addSourceFile(resourceFile)
}

resourcesTarget.addResourceFile(resourceFile)
}

Expand Down
25 changes: 22 additions & 3 deletions Tests/XCBuildSupportTests/PIFBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2201,12 +2201,18 @@ final class PIFBuilderTests: XCTestCase {
"/Foo/Sources/foo/main.swift",
"/Foo/Sources/foo/Resources/Data.plist",
"/Foo/Sources/foo/Resources/Database.xcdatamodel",
"/Foo/Sources/foo/Resources/Assets.xcassets",
"/Foo/Sources/foo/Resources/Localizable.xcstrings",
"/Foo/Sources/FooLib/lib.swift",
"/Foo/Sources/FooLib/Resources/Data.plist",
"/Foo/Sources/FooLib/Resources/Database.xcdatamodel",
"/Foo/Sources/FooLib/Resources/Assets.xcassets",
"/Foo/Sources/FooLib/Resources/Localizable.xcstrings",
"/Foo/Sources/FooTests/FooTests.swift",
"/Foo/Sources/FooTests/Resources/Data.plist",
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel"
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel",
"/Foo/Sources/FooTests/Resources/Assets.xcassets",
"/Foo/Sources/FooTests/Resources/Localizable.xcstrings",
)

let observability = ObservabilitySystem.makeForTesting()
Expand All @@ -2216,15 +2222,15 @@ final class PIFBuilderTests: XCTestCase {
Manifest.createRootManifest(
displayName: "Foo",
path: "/Foo",
toolsVersion: .v5_3,
toolsVersion: .v5_9,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped to the first tools version that supports xcstrings at all.

products: [
.init(name: "FooLib", type: .library(.automatic), targets: ["FooLib"]),
],
targets: [
.init(name: "foo", resources: [
// This is intentionally specific to test that we pick up `.xcdatamodel` implicitly.
.init(rule: .process(localization: .none), path: "Resources/Data.plist"),
]),
], type: .executable),
.init(name: "FooLib", resources: [
.init(rule: .process(localization: .none), path: "Resources"),
]),
Expand Down Expand Up @@ -2253,7 +2259,10 @@ final class PIFBuilderTests: XCTestCase {
try workspace.checkProject("PACKAGE:/Foo") { project in
project.checkTarget("PACKAGE-PRODUCT:foo") { target in
XCTAssertEqual(target.dependencies, ["PACKAGE-RESOURCE:foo"])
// All of these file types can generate code.
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Database.xcdatamodel"))
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Assets.xcassets"))
XCTAssert(target.sources.contains("/Foo/Sources/foo/Resources/Localizable.xcstrings"))

target.checkBuildConfiguration("Debug") { configuration in
configuration.checkBuildSettings { settings in
Expand Down Expand Up @@ -2290,6 +2299,8 @@ final class PIFBuilderTests: XCTestCase {
XCTAssertEqual(target.resources, [
"/Foo/Sources/foo/Resources/Data.plist",
"/Foo/Sources/foo/Resources/Database.xcdatamodel",
"/Foo/Sources/foo/Resources/Assets.xcassets",
"/Foo/Sources/foo/Resources/Localizable.xcstrings",
])

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

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

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

target.checkBuildConfiguration("Debug") { configuration in
configuration.checkBuildSettings { settings in
Expand Down Expand Up @@ -2408,6 +2425,8 @@ final class PIFBuilderTests: XCTestCase {
XCTAssertEqual(target.resources, [
"/Foo/Sources/FooTests/Resources/Data.plist",
"/Foo/Sources/FooTests/Resources/Database.xcdatamodel",
"/Foo/Sources/FooTests/Resources/Assets.xcassets",
"/Foo/Sources/FooTests/Resources/Localizable.xcstrings",
])

target.checkBuildConfiguration("Debug") { configuration in
Expand Down