Skip to content

Commit 6e191c9

Browse files
authored
[5.5] Ignore .docc files rather than emitting warnings, since it's useful to have them in packages without warnings (#3616)
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 (cherry picked from commit 8f9e5d3 and f39a8be)
1 parent 1e567bd commit 6e191c9

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public class SwiftTool {
574574
config: try getSwiftPMConfig(),
575575
repositoryProvider: provider,
576576
netrcFilePath: try resolvedNetrcFilePath(),
577-
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : [],
577+
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
578578
isResolverPrefetchingEnabled: options.shouldEnableResolverPrefetching,
579579
skipUpdate: options.skipDependencyUpdate,
580580
enableResolverTrace: options.enableResolverTrace,

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 22 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,9 @@ 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+
// 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
7572
self.toolsVersion = toolsVersion
7673
self.fs = fs
7774
let excludedPaths = target.exclude.map{ path.appending(RelativePath($0)) }
@@ -253,7 +250,7 @@ public struct TargetSourcesBuilder {
253250
/// Returns the `Resource` file associated with a file and a particular rule, if there is one.
254251
private func resource(for path: AbsolutePath, with rule: Rule) -> Resource? {
255252
switch rule.rule {
256-
case .compile, .header, .none, .modulemap:
253+
case .compile, .header, .none, .modulemap, .ignored:
257254
return nil
258255
case .processResource:
259256
let implicitLocalization: String? = {
@@ -490,6 +487,9 @@ public struct FileRuleDescription {
490487

491488
/// A header file.
492489
case header
490+
491+
/// Indicates that the file should be treated as ignored, without causing an unhandled-file warning.
492+
case ignored
493493

494494
/// Sentinal to indicate that no rule was chosen for a given file.
495495
case none
@@ -605,6 +605,15 @@ public struct FileRuleDescription {
605605
)
606606
}()
607607

608+
/// File rule to ignore .docc (in the SwiftPM build system).
609+
public static let docc: FileRuleDescription = {
610+
.init(
611+
rule: .ignored,
612+
toolsVersion: .v5_5,
613+
fileTypes: ["docc"]
614+
)
615+
}()
616+
608617
/// List of all the builtin rules.
609618
public static let builtinRules: [FileRuleDescription] = [
610619
swift,
@@ -621,6 +630,11 @@ public struct FileRuleDescription {
621630
coredata,
622631
metal,
623632
]
633+
634+
/// List of file types that apply just to the SwiftPM build system.
635+
public static let swiftpmFileTypes: [FileRuleDescription] = [
636+
docc,
637+
]
624638
}
625639

626640
extension TargetDescription.Resource.Rule {

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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,39 @@ 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 testDocCFilesDoNotCauseWarningOutsideXCBuild() 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+
additionalFileRules: FileRuleDescription.swiftpmFileTypes,
691+
toolsVersion: .v5_5,
692+
fs: fs,
693+
diags: diags
694+
)
695+
_ = try builder.run()
696+
697+
XCTAssertTrue(diags.diagnostics.isEmpty)
698+
}
664699
}

0 commit comments

Comments
 (0)