Skip to content

Commit 376414f

Browse files
authored
Disable check for unsafe flags. (#8896)
As discussed in the Swift forums below, a number of projects require the use of "unsafe" flags. A common example is the use of absolute header include paths set via an environment variable that project consumers agree to use. As such, the flags can be safely used under those circumstances. This change disables the one line that was doing the check. We will further study the issue and come up with other mechanisms to ensure the challenges some flags have on quality of the package ecosystem are mitigated. https://forums.swift.org/t/pitch-disable-checks-for-unsafe-flags-in-swiftpm/80698
1 parent 2fed024 commit 376414f

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,8 @@ extension Sequence {
20242024

20252025
extension TargetDescription {
20262026
fileprivate var usesUnsafeFlags: Bool {
2027-
settings.filter(\.kind.isUnsafeFlags).isEmpty == false
2027+
// We no longer restrict unsafe flags
2028+
false
20282029
}
20292030

20302031
fileprivate func isMacroTest(in manifest: Manifest) -> Bool {

Tests/PackageGraphTests/ModulesGraphTests.swift

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,26 +2127,8 @@ final class ModulesGraphTests: XCTestCase {
21272127
observabilityScope: observability.topScope
21282128
)
21292129

2130-
XCTAssertEqual(observability.diagnostics.count, 3)
2131-
testDiagnostics(observability.diagnostics) { result in
2132-
var expectedMetadata = ObservabilityMetadata()
2133-
expectedMetadata.moduleName = "Foo2"
2134-
let diagnostic1 = result.checkUnordered(
2135-
diagnostic: .contains("the target 'Bar2' in product 'TransitiveBar' contains unsafe build flags"),
2136-
severity: .error
2137-
)
2138-
XCTAssertEqual(diagnostic1?.metadata?.moduleName, "Foo2")
2139-
let diagnostic2 = result.checkUnordered(
2140-
diagnostic: .contains("the target 'Bar' in product 'Bar' contains unsafe build flags"),
2141-
severity: .error
2142-
)
2143-
XCTAssertEqual(diagnostic2?.metadata?.moduleName, "Foo")
2144-
let diagnostic3 = result.checkUnordered(
2145-
diagnostic: .contains("the target 'Bar2' in product 'Bar' contains unsafe build flags"),
2146-
severity: .error
2147-
)
2148-
XCTAssertEqual(diagnostic3?.metadata?.moduleName, "Foo")
2149-
}
2130+
// We have turned off the unsafe flags check
2131+
XCTAssertEqual(observability.diagnostics.count, 0)
21502132
}
21512133

21522134
func testConditionalTargetDependency() throws {

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,20 +5793,8 @@ final class WorkspaceTests: XCTestCase {
57935793

57945794
// We should only see errors about use of unsafe flag in the version-based dependency.
57955795
try await workspace.checkPackageGraph(roots: ["Foo", "Bar"]) { _, diagnostics in
5796-
testDiagnostics(diagnostics) { result in
5797-
let diagnostic1 = result.checkUnordered(
5798-
diagnostic: .equal("the target 'Baz' in product 'Baz' contains unsafe build flags"),
5799-
severity: .error
5800-
)
5801-
XCTAssertEqual(diagnostic1?.metadata?.packageIdentity, .plain("foo"))
5802-
XCTAssertEqual(diagnostic1?.metadata?.moduleName, "Foo")
5803-
let diagnostic2 = result.checkUnordered(
5804-
diagnostic: .equal("the target 'Bar' in product 'Baz' contains unsafe build flags"),
5805-
severity: .error
5806-
)
5807-
XCTAssertEqual(diagnostic2?.metadata?.packageIdentity, .plain("foo"))
5808-
XCTAssertEqual(diagnostic2?.metadata?.moduleName, "Foo")
5809-
}
5796+
// We have disabled the check so there shouldn't be any errors.
5797+
XCTAssert(diagnostics.filter({ $0.severity == .error }).isEmpty)
58105798
}
58115799
}
58125800

0 commit comments

Comments
 (0)