Skip to content

[5.5] Ignore .docc files rather than emitting warnings, since it's useful to have them in packages without warnings #3616

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

Merged
merged 1 commit into from
Jul 19, 2021
Merged
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
2 changes: 1 addition & 1 deletion Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public class SwiftTool {
config: try getSwiftPMConfig(),
repositoryProvider: provider,
netrcFilePath: try resolvedNetrcFilePath(),
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : [],
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
isResolverPrefetchingEnabled: options.shouldEnableResolverPrefetching,
skipUpdate: options.skipDependencyUpdate,
enableResolverTrace: options.enableResolverTrace,
Expand Down
30 changes: 22 additions & 8 deletions Sources/PackageLoading/TargetSourcesBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -66,12 +66,9 @@ public struct TargetSourcesBuilder {
self.defaultLocalization = defaultLocalization
self.diags = diags
self.targetPath = path
if toolsVersion <= ToolsVersion.v5_4 {
// In version 5.4 and earlier, we did not support `additionalFileRules` and always implicitly included XCBuild file types.
self.rules = FileRuleDescription.builtinRules + FileRuleDescription.xcbuildFileTypes
} else {
self.rules = FileRuleDescription.builtinRules + additionalFileRules
}
// In version 5.4 and earlier, SwiftPM did not support `additionalFileRules` and always implicitly included XCBuild file types.
let actualAdditionalRules = (toolsVersion <= ToolsVersion.v5_4 ? FileRuleDescription.xcbuildFileTypes : additionalFileRules)
self.rules = FileRuleDescription.builtinRules + actualAdditionalRules
self.toolsVersion = toolsVersion
self.fs = fs
let excludedPaths = target.exclude.map{ path.appending(RelativePath($0)) }
Expand Down Expand Up @@ -253,7 +250,7 @@ public struct TargetSourcesBuilder {
/// Returns the `Resource` file associated with a file and a particular rule, if there is one.
private func resource(for path: AbsolutePath, with rule: Rule) -> Resource? {
switch rule.rule {
case .compile, .header, .none, .modulemap:
case .compile, .header, .none, .modulemap, .ignored:
return nil
case .processResource:
let implicitLocalization: String? = {
Expand Down Expand Up @@ -490,6 +487,9 @@ public struct FileRuleDescription {

/// A header file.
case header

/// Indicates that the file should be treated as ignored, without causing an unhandled-file warning.
case ignored

/// Sentinal to indicate that no rule was chosen for a given file.
case none
Expand Down Expand Up @@ -605,6 +605,15 @@ public struct FileRuleDescription {
)
}()

/// File rule to ignore .docc (in the SwiftPM build system).
public static let docc: FileRuleDescription = {
.init(
rule: .ignored,
toolsVersion: .v5_5,
fileTypes: ["docc"]
)
}()

/// List of all the builtin rules.
public static let builtinRules: [FileRuleDescription] = [
swift,
Expand All @@ -621,6 +630,11 @@ public struct FileRuleDescription {
coredata,
metal,
]

/// List of file types that apply just to the SwiftPM build system.
public static let swiftpmFileTypes: [FileRuleDescription] = [
docc,
]
}

extension TargetDescription.Resource.Rule {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public func loadPackageGraph(
return try PackageGraph.load(
root: graphRoot,
identityResolver: identityResolver,
additionalFileRules: useXCBuildFileRules ? FileRuleDescription.xcbuildFileTypes : [],
additionalFileRules: useXCBuildFileRules ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
externalManifests: externalManifests,
binaryArtifacts: binaryArtifacts,
diagnostics: diagnostics,
Expand Down
35 changes: 35 additions & 0 deletions Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,39 @@ class TargetSourcesBuilderTests: XCTestCase {

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"])
}

func testDocCFilesDoNotCauseWarningOutsideXCBuild() throws {
let target = try TargetDescription(
name: "Foo",
path: nil,
exclude: [],
sources: ["File.swift"],
resources: [],
publicHeadersPath: nil,
type: .regular
)

let fs = InMemoryFileSystem()
fs.createEmptyFiles(at: .root, files: [
"/File.swift",
"/Foo.docc"
])

let diags = DiagnosticsEngine()

let builder = TargetSourcesBuilder(
packageName: "",
packagePath: .root,
target: target,
path: .root,
defaultLocalization: nil,
additionalFileRules: FileRuleDescription.swiftpmFileTypes,
toolsVersion: .v5_5,
fs: fs,
diags: diags
)
_ = try builder.run()

XCTAssertTrue(diags.diagnostics.isEmpty)
}
}