Skip to content

Commit ea8e19c

Browse files
committed
[PackageLoading] Recognize some Xcode filetypes
<rdar://problem/59725095> Most of these can be now used when passing --build-system xcode
1 parent 85f6dda commit ea8e19c

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public struct TargetSourcesBuilder {
6666
self.defaultLocalization = defaultLocalization
6767
self.diags = diags
6868
self.targetPath = path
69-
self.rules = FileRuleDescription.builtinRules + additionalFileRules
69+
self.rules = FileRuleDescription.builtinRules
7070
self.toolsVersion = toolsVersion
7171
self.fs = fs
7272
let excludedPaths = target.exclude.map{ path.appending(RelativePath($0)) }
@@ -515,13 +515,47 @@ public struct FileRuleDescription {
515515
)
516516
}()
517517

518+
/// File types related to the interface builder and storyboards.
519+
public static var xib: FileRuleDescription = {
520+
.init(
521+
rule: .processResource,
522+
toolsVersion: .vNext,
523+
fileTypes: ["nib", "xib", "storyboard"]
524+
)
525+
}()
526+
527+
/// File types related to the asset catalog.
528+
public static var assetCatalog: FileRuleDescription = {
529+
.init(
530+
rule: .processResource,
531+
toolsVersion: .vNext,
532+
fileTypes: ["xcassets"]
533+
)
534+
}()
535+
536+
/// File types related to the CoreData.
537+
public static var coredata: FileRuleDescription = {
538+
.init(
539+
rule: .processResource,
540+
toolsVersion: .vNext,
541+
fileTypes: ["xcdatamodeld", "xcdatamodel", "xcmappingmodel"]
542+
)
543+
}()
544+
518545
/// List of all the builtin rules.
519546
public static let builtinRules: [FileRuleDescription] = [
520547
swift,
521548
clang,
522549
asm,
523550
modulemap,
524551
header,
552+
] + xcbuildFileTypes
553+
554+
/// List of file types that requires the Xcode build system.
555+
public static let xcbuildFileTypes: [FileRuleDescription] = [
556+
xib,
557+
assetCatalog,
558+
coredata,
525559
]
526560
}
527561

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,34 @@ class PackageBuilderTests: XCTestCase {
18951895
diagnostics.check(diagnostic: "manifest property 'defaultLocalization' not set; it is required in the presence of localized resources", behavior: .error)
18961896
}
18971897
}
1898+
1899+
func testXcodeResources() throws {
1900+
let fs = InMemoryFileSystem(emptyFiles:
1901+
"/Foo/Sources/Foo/foo.swift",
1902+
"/Foo/Sources/Foo/Foo.xcassets",
1903+
"/Foo/Sources/Foo/Foo.xib",
1904+
"/Foo/Sources/Foo/Foo.xcdatamodel"
1905+
)
1906+
1907+
let manifest = Manifest.createManifest(
1908+
name: "Foo",
1909+
v: .vNext,
1910+
targets: [
1911+
TargetDescription(name: "Foo"),
1912+
]
1913+
)
1914+
1915+
PackageBuilderTester(manifest, path: AbsolutePath("/Foo"), in: fs) { result, diagnostics in
1916+
result.checkModule("Foo") { result in
1917+
result.checkSources(sources: ["foo.swift"])
1918+
result.checkResources(resources: [
1919+
"/Foo/Sources/Foo/Foo.xib",
1920+
"/Foo/Sources/Foo/Foo.xcdatamodel",
1921+
"/Foo/Sources/Foo/Foo.xcassets",
1922+
])
1923+
}
1924+
}
1925+
}
18981926
}
18991927

19001928
extension PackageModel.Product: ObjectIdentifierProtocol {}
@@ -2047,6 +2075,10 @@ final class PackageBuilderTester {
20472075
checkSources(root: root, sources: paths, file: file, line: line)
20482076
}
20492077

2078+
func checkResources(resources: [String], file: StaticString = #file, line: UInt = #line) {
2079+
XCTAssertEqual(Set(resources), Set(self.target.resources.map{ $0.path.pathString }), "unexpected resource files in \(target.name)", file: file, line: line)
2080+
}
2081+
20502082
func check(targetDependencies depsToCheck: [String], file: StaticString = #file, line: UInt = #line) {
20512083
XCTAssertEqual(Set(depsToCheck), Set(target.dependencies.compactMap { $0.target?.name }), "unexpected dependencies in \(target.name)", file: file, line: line)
20522084
}

0 commit comments

Comments
 (0)