Skip to content

allow use of warnings-as-errors while dependencies have supressed warnings #5612

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 21, 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/DependenciesWarnings2/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: "./"
)
]
)
9 changes: 9 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings2/app/app.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dep1
import dep2

@main
struct App {
public static func main() {
print("hello, world!")
}
}
12 changes: 12 additions & 0 deletions Fixtures/Miscellaneous/DependenciesWarnings2/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: "./")
]
)
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/DependenciesWarnings2/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: "./")
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct Dep2 {
var deprecated: Deprecated2
}

@available(*, deprecated)
struct Deprecated2 {
}
11 changes: 8 additions & 3 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -873,14 +873,19 @@ public final class SwiftTargetBuildDescription {
args += ["-emit-module-interface-path", parseableModuleInterfaceOutputPath.pathString]
}

args += buildParameters.toolchain.extraSwiftCFlags
// User arguments (from -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.swiftCompilerFlags

// suppress warnings if the package is remote
if self.package.isRemote {
args += ["-suppress-warnings"]
// suppress-warnings and warnings-as-errors are mutually exclusive
if let index = args.firstIndex(of: "-warnings-as-errors") {
args.remove(at: index)
}
}

args += buildParameters.toolchain.extraSwiftCFlags
// User arguments (from -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.swiftCompilerFlags
return args
}

Expand Down
16 changes: 16 additions & 0 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,20 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated2' is deprecated"))
}
}

func testNoWarningFromRemoteDependenciesWithWarningsAsErrors() throws {
try fixture(name: "Miscellaneous/DependenciesWarnings2") { 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(["-Xswiftc", "-warnings-as-errors"], packagePath: appPath)
XCTAssertDirectoryExists(appPath.appending(component: ".build"))
XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated1' is deprecated"))
XCTAssertNoMatch(stdout + stderr, .contains("'Deprecated2' is deprecated"))
}
}
}