Skip to content

[5.7] suppress warnings from remote dependencies #5608

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
Jun 18, 2022
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
23 changes: 23 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/app/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// swift-tools-version: 5.7
import PackageDescription

let package = Package(
name: "app",
products: [
.executable(name: "app", targets: ["app"])
],
dependencies: [
.package(url: "../dep1", from: "1.0.0"),
.package(url: "../dep2", from: "1.0.0"),
],
targets: [
.executableTarget(
name: "app",
dependencies: [
.product(name: "dep1", package: "dep1"),
.product(name: "dep2", package: "dep2")
],
path: "./"
)
]
)
15 changes: 15 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/app/app.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dep1
import dep2

@main
struct App {
var deprecated: DeprecatedApp

public static func main() {
print("hello, world!")
}
}

@available(*, deprecated)
struct DeprecatedApp {
}
12 changes: 12 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/dep1/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version: 5.7
import PackageDescription

let package = Package(
name: "dep1",
products: [
.library(name: "dep1", targets: ["dep1"])
],
targets: [
.target(name: "dep1", path: "./")
]
)
7 changes: 7 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/dep1/code.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct Dep1 {
var deprecated: Deprecated1
}

@available(*, deprecated)
struct Deprecated1 {
}
12 changes: 12 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/dep2/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version: 5.7
import PackageDescription

let package = Package(
name: "dep2",
products: [
.library(name: "dep2", targets: ["dep2"])
],
targets: [
.target(name: "dep2", path: "./")
]
)
7 changes: 7 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings/dep2/code.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct Dep2 {
var deprecated: Deprecated2
}

@available(*, deprecated)
struct Deprecated2 {
}
33 changes: 31 additions & 2 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public final class ClangTargetBuildDescription {

/// Target description for a Swift target.
public final class SwiftTargetBuildDescription {
/// The package this target belongs to.
public let package: ResolvedPackage

/// The target described by this target.
public let target: ResolvedTarget
Expand Down Expand Up @@ -661,6 +663,7 @@ public final class SwiftTargetBuildDescription {

/// Create a new target description with target and build parameters.
init(
package: ResolvedPackage,
target: ResolvedTarget,
toolsVersion: ToolsVersion,
additionalFileRules: [FileRuleDescription] = [],
Expand All @@ -675,6 +678,7 @@ public final class SwiftTargetBuildDescription {
guard target.underlyingTarget is SwiftTarget else {
throw InternalError("underlying target type mismatch \(target)")
}
self.package = package
self.target = target
self.toolsVersion = toolsVersion
self.buildParameters = buildParameters
Expand Down Expand Up @@ -869,6 +873,11 @@ public final class SwiftTargetBuildDescription {
args += ["-emit-module-interface-path", parseableModuleInterfaceOutputPath.pathString]
}

// suppress warnings if the package is remote
if self.package.isRemote {
args += ["-suppress-warnings"]
}

args += buildParameters.toolchain.extraSwiftCFlags
// User arguments (from -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.swiftCompilerFlags
Expand Down Expand Up @@ -1608,13 +1617,17 @@ public class BuildPlan {
var generateRedundant = generate
var result: [(ResolvedProduct, SwiftTargetBuildDescription)] = []
for testProduct in graph.allProducts where testProduct.type == .test {
guard let package = graph.package(for: testProduct) else {
throw InternalError("package not found for \(testProduct)")
}
generateRedundant = generateRedundant && nil == testProduct.testManifestTarget
// if test manifest exists, prefer that over test detection,
// this is designed as an escape hatch when test discovery is not appropriate
// and for backwards compatibility for projects that have existing test manifests (LinuxMain.swift)
let toolsVersion = graph.package(for: testProduct)?.manifest.toolsVersion ?? .v5_5
if let testManifestTarget = testProduct.testManifestTarget, !generate {
let desc = try SwiftTargetBuildDescription(
package: package,
target: testManifestTarget,
toolsVersion: toolsVersion,
buildParameters: buildParameters,
Expand Down Expand Up @@ -1651,6 +1664,7 @@ public class BuildPlan {
)

let target = try SwiftTargetBuildDescription(
package: package,
target: testManifestTarget,
toolsVersion: toolsVersion,
buildParameters: buildParameters,
Expand Down Expand Up @@ -1716,7 +1730,11 @@ public class BuildPlan {

switch target.underlyingTarget {
case is SwiftTarget:
guard let package = graph.package(for: target) else {
throw InternalError("package not found for \(target)")
}
targetMap[target] = try .swift(SwiftTargetBuildDescription(
package: package,
target: target,
toolsVersion: toolsVersion,
additionalFileRules: additionalFileRules,
Expand Down Expand Up @@ -2303,8 +2321,19 @@ private func generateResourceInfoPlist(
return true
}

fileprivate extension TSCUtility.Triple {
var isSupportingStaticStdlib: Bool {
extension TSCUtility.Triple {
fileprivate var isSupportingStaticStdlib: Bool {
isLinux() || arch == .wasm32
}
}

extension ResolvedPackage {
fileprivate var isRemote: Bool {
switch self.underlyingPackage.manifest.packageKind {
case .registry, .remoteSourceControl, .localSourceControl:
return true
case .root, .fileSystem:
return false
}
}
}
17 changes: 17 additions & 0 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,21 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertNoMatch(stderr2, .contains("command_arguments"))
}
}

func testNoWarningFromRemoteDependencies() throws {
try fixture(name: "Miscellaneous/DependenciesWarnings") { path in
// prepare the deps as git sources
let dependency1Path = path.appending(component: "dep1")
initGitRepo(dependency1Path, tag: "1.0.0")
let dependency2Path = path.appending(component: "dep2")
initGitRepo(dependency2Path, tag: "1.0.0")

let appPath = path.appending(component: "app")
let (stdout, stderr) = try SwiftPMProduct.SwiftBuild.execute([], packagePath: appPath)
XCTAssertDirectoryExists(appPath.appending(component: ".build"))
XCTAssertMatch(stdout + stderr, .contains("'DeprecatedApp' is deprecated"))
XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated1' is deprecated"))
XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated2' is deprecated"))
}
}
}