Skip to content

Commit 9c3ef3c

Browse files
authored
Allow empty arrays of unsafe flags (#3586)
This is currently only disallowed using assertions, and those are compiled out for release builds. There is no reason to disallow this, and it's useful when programmatically building up lists of unsafe flags.
1 parent e4201de commit 9c3ef3c

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

Sources/PackageModel/Manifest/TargetBuildSettingDescription.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public enum TargetBuildSettingDescription {
6161
assert(value.count == 1, "\(tool) \(name) \(value)")
6262
break
6363
case .unsafeFlags:
64-
assert(value.count >= 1, "\(tool) \(name) \(value)")
6564
break
6665
}
6766

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,82 @@ class PackageBuilderTests: XCTestCase {
19741974
}
19751975
}
19761976

1977+
func testEmptyUnsafeFlagsAreAllowed() throws {
1978+
let fs = InMemoryFileSystem(emptyFiles:
1979+
"/Sources/foo/foo.swift",
1980+
"/Sources/bar/bar.cpp",
1981+
"/Sources/bar/bar.c",
1982+
"/Sources/bar/include/bar.h"
1983+
)
1984+
1985+
let manifest = Manifest.createManifest(
1986+
name: "pkg",
1987+
v: .v5,
1988+
targets: [
1989+
try TargetDescription(
1990+
name: "foo",
1991+
settings: [
1992+
.init(tool: .c, name: .unsafeFlags, value: []),
1993+
.init(tool: .cxx, name: .unsafeFlags, value: []),
1994+
.init(tool: .cxx, name: .unsafeFlags, value: [], condition: .init(config: "release")),
1995+
.init(tool: .linker, name: .unsafeFlags, value: []),
1996+
]
1997+
),
1998+
try TargetDescription(
1999+
name: "bar",
2000+
settings: [
2001+
.init(tool: .swift, name: .unsafeFlags, value: [], condition: .init(platformNames: ["macos"], config: "debug")),
2002+
.init(tool: .linker, name: .unsafeFlags, value: []),
2003+
.init(tool: .linker, name: .unsafeFlags, value: [], condition: .init(platformNames: ["linux"])),
2004+
]
2005+
),
2006+
]
2007+
)
2008+
2009+
PackageBuilderTester(manifest, in: fs) { package, _ in
2010+
package.checkModule("foo") { package in
2011+
let macosDebugScope = BuildSettings.Scope(
2012+
package.target.buildSettings,
2013+
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
2014+
)
2015+
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_CFLAGS), [])
2016+
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_CPLUSPLUSFLAGS), [])
2017+
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_LDFLAGS), [])
2018+
2019+
let macosReleaseScope = BuildSettings.Scope(
2020+
package.target.buildSettings,
2021+
environment: BuildEnvironment(platform: .macOS, configuration: .release)
2022+
)
2023+
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_CFLAGS), [])
2024+
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_CPLUSPLUSFLAGS), [])
2025+
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_LDFLAGS), [])
2026+
}
2027+
2028+
package.checkModule("bar") { package in
2029+
let linuxDebugScope = BuildSettings.Scope(
2030+
package.target.buildSettings,
2031+
environment: BuildEnvironment(platform: .linux, configuration: .debug)
2032+
)
2033+
XCTAssertEqual(linuxDebugScope.evaluate(.OTHER_SWIFT_FLAGS), [])
2034+
XCTAssertEqual(linuxDebugScope.evaluate(.OTHER_LDFLAGS), [])
2035+
2036+
let linuxReleaseScope = BuildSettings.Scope(
2037+
package.target.buildSettings,
2038+
environment: BuildEnvironment(platform: .linux, configuration: .release)
2039+
)
2040+
XCTAssertEqual(linuxReleaseScope.evaluate(.OTHER_SWIFT_FLAGS), [])
2041+
XCTAssertEqual(linuxReleaseScope.evaluate(.OTHER_LDFLAGS), [])
2042+
2043+
let macosDebugScope = BuildSettings.Scope(
2044+
package.target.buildSettings,
2045+
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
2046+
)
2047+
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS), [])
2048+
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_LDFLAGS), [])
2049+
}
2050+
}
2051+
}
2052+
19772053
func testInvalidHeaderSearchPath() throws {
19782054
let fs = InMemoryFileSystem(emptyFiles:
19792055
"/pkg/Sources/exe/main.swift"

0 commit comments

Comments
 (0)