Skip to content

Commit f39a8be

Browse files
committed
Refine the change to ignore .docc files rather than emit warnings to avoid having multiple definitions for the same file extension
Ignore .docc files rather than emitting warnings, since it's useful to have them in packages without warnings. Unlike other Xcode-specific file types, such as Storyboards and Asset Catalogs, the .docc bundles are not needed for correctness during the build, and should therefore not trigger warnings. This is a refinement of the fix in #3609. rdar://78133445
1 parent 8f9e5d3 commit f39a8be

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public class SwiftTool {
561561
config: try getSwiftPMConfig(),
562562
repositoryProvider: provider,
563563
netrcFilePath: try resolvedNetrcFilePath(),
564-
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : [],
564+
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
565565
isResolverPrefetchingEnabled: options.shouldEnableResolverPrefetching,
566566
skipUpdate: options.skipDependencyUpdate,
567567
enableResolverTrace: options.enableResolverTrace,

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,9 @@ public struct TargetSourcesBuilder {
6666
self.defaultLocalization = defaultLocalization
6767
self.diags = diags
6868
self.targetPath = path
69-
70-
// Configure the file rules that determine how files of various types are processed. We always start with the builtins.
71-
var fileRules = FileRuleDescription.builtinRules
72-
// In version 5.4 and earlier, we did not support `additionalFileRules` and always implicitly included the XCBuild file types.
73-
fileRules += (toolsVersion <= ToolsVersion.v5_4) ? FileRuleDescription.xcbuildFileTypes : additionalFileRules
74-
// At the end we add the ignored types. They might duplicate some of the rules in `additionalFileRules`, but in that case, the rule to ignore the file type will never be reached.
75-
fileRules += FileRuleDescription.ignoredFileTypes
76-
self.rules = fileRules
77-
69+
// In version 5.4 and earlier, SwiftPM did not support `additionalFileRules` and always implicitly included XCBuild file types.
70+
let actualAdditionalRules = (toolsVersion <= ToolsVersion.v5_4 ? FileRuleDescription.xcbuildFileTypes : additionalFileRules)
71+
self.rules = FileRuleDescription.builtinRules + actualAdditionalRules
7872
self.toolsVersion = toolsVersion
7973
self.fs = fs
8074
let excludedPaths = target.exclude.map{ path.appending(RelativePath($0)) }
@@ -611,7 +605,7 @@ public struct FileRuleDescription {
611605
)
612606
}()
613607

614-
/// File types related to DocC.
608+
/// File rule to ignore .docc (in the SwiftPM build system).
615609
public static let docc: FileRuleDescription = {
616610
.init(
617611
rule: .ignored,
@@ -637,9 +631,8 @@ public struct FileRuleDescription {
637631
metal,
638632
]
639633

640-
/// List of file types that are ignored in this version of SwiftPM CLI
641-
/// (that don't generate warnings for being unhandled).
642-
public static let ignoredFileTypes: [FileRuleDescription] = [
634+
/// List of file types that apply just to the SwiftPM build system.
635+
public static let swiftpmFileTypes: [FileRuleDescription] = [
643636
docc,
644637
]
645638
}

Sources/SPMTestSupport/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public func loadPackageGraph(
239239
return try PackageGraph.load(
240240
root: graphRoot,
241241
identityResolver: identityResolver,
242-
additionalFileRules: useXCBuildFileRules ? FileRuleDescription.xcbuildFileTypes : [],
242+
additionalFileRules: useXCBuildFileRules ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
243243
externalManifests: externalManifests,
244244
binaryArtifacts: binaryArtifacts,
245245
diagnostics: diagnostics,

Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ class TargetSourcesBuilderTests: XCTestCase {
662662
XCTAssertEqual(diags.diagnostics.map { $0.description }, ["found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target\n /Foo.xcdatamodel\n"])
663663
}
664664

665-
func testIgnoredFileTypesDoNoCauseWarnings() throws {
665+
func testDocCFilesDoNotCauseWarningOutsideXCBuild() throws {
666666
let target = try TargetDescription(
667667
name: "Foo",
668668
path: nil,
@@ -687,6 +687,7 @@ class TargetSourcesBuilderTests: XCTestCase {
687687
target: target,
688688
path: .root,
689689
defaultLocalization: nil,
690+
additionalFileRules: FileRuleDescription.swiftpmFileTypes,
690691
toolsVersion: .v5_5,
691692
fs: fs,
692693
diags: diags

0 commit comments

Comments
 (0)