Skip to content

Commit 8f9e5d3

Browse files
authored
Ignore .docc files rather than emitting warnings, since it's useful to have them in packages without warnings. (#3609)
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. rdar://78133445
1 parent 9b04413 commit 8f9e5d3

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -66,12 +66,15 @@ public struct TargetSourcesBuilder {
6666
self.defaultLocalization = defaultLocalization
6767
self.diags = diags
6868
self.targetPath = path
69-
if toolsVersion <= ToolsVersion.v5_4 {
70-
// In version 5.4 and earlier, we did not support `additionalFileRules` and always implicitly included XCBuild file types.
71-
self.rules = FileRuleDescription.builtinRules + FileRuleDescription.xcbuildFileTypes
72-
} else {
73-
self.rules = FileRuleDescription.builtinRules + additionalFileRules
74-
}
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+
7578
self.toolsVersion = toolsVersion
7679
self.fs = fs
7780
let excludedPaths = target.exclude.map{ path.appending(RelativePath($0)) }
@@ -253,7 +256,7 @@ public struct TargetSourcesBuilder {
253256
/// Returns the `Resource` file associated with a file and a particular rule, if there is one.
254257
private func resource(for path: AbsolutePath, with rule: Rule) -> Resource? {
255258
switch rule.rule {
256-
case .compile, .header, .none, .modulemap:
259+
case .compile, .header, .none, .modulemap, .ignored:
257260
return nil
258261
case .processResource:
259262
let implicitLocalization: String? = {
@@ -490,6 +493,9 @@ public struct FileRuleDescription {
490493

491494
/// A header file.
492495
case header
496+
497+
/// Indicates that the file should be treated as ignored, without causing an unhandled-file warning.
498+
case ignored
493499

494500
/// Sentinal to indicate that no rule was chosen for a given file.
495501
case none
@@ -605,6 +611,15 @@ public struct FileRuleDescription {
605611
)
606612
}()
607613

614+
/// File types related to DocC.
615+
public static let docc: FileRuleDescription = {
616+
.init(
617+
rule: .ignored,
618+
toolsVersion: .v5_5,
619+
fileTypes: ["docc"]
620+
)
621+
}()
622+
608623
/// List of all the builtin rules.
609624
public static let builtinRules: [FileRuleDescription] = [
610625
swift,
@@ -621,6 +636,12 @@ public struct FileRuleDescription {
621636
coredata,
622637
metal,
623638
]
639+
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] = [
643+
docc,
644+
]
624645
}
625646

626647
extension TargetDescription.Resource.Rule {

Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,38 @@ class TargetSourcesBuilderTests: XCTestCase {
661661

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
}
664+
665+
func testIgnoredFileTypesDoNoCauseWarnings() throws {
666+
let target = try TargetDescription(
667+
name: "Foo",
668+
path: nil,
669+
exclude: [],
670+
sources: ["File.swift"],
671+
resources: [],
672+
publicHeadersPath: nil,
673+
type: .regular
674+
)
675+
676+
let fs = InMemoryFileSystem()
677+
fs.createEmptyFiles(at: .root, files: [
678+
"/File.swift",
679+
"/Foo.docc"
680+
])
681+
682+
let diags = DiagnosticsEngine()
683+
684+
let builder = TargetSourcesBuilder(
685+
packageName: "",
686+
packagePath: .root,
687+
target: target,
688+
path: .root,
689+
defaultLocalization: nil,
690+
toolsVersion: .v5_5,
691+
fs: fs,
692+
diags: diags
693+
)
694+
_ = try builder.run()
695+
696+
XCTAssertTrue(diags.diagnostics.isEmpty)
697+
}
664698
}

0 commit comments

Comments
 (0)