Skip to content

[Xcodeproj] Add -DSWIFT_PACKAGE=1 to the C/C++ preprocessor defines #1910

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
Dec 6, 2018
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
4 changes: 2 additions & 2 deletions Sources/Xcodeproj/XcodeProjectModelSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ fileprivate func combineBuildSettingsPropertyLists(
// Iterate over the overlay values and apply them to the base.
var resultDict = baseDict
for (name, value) in overlayDict {
if let array = baseDict[name]?.array, array.first?.string == "$(inherited)" {
resultDict[name] = .array(array + (value.array ?? []))
if let array = baseDict[name]?.array, let overlayArray = value.array, overlayArray.first?.string == "$(inherited)" {
resultDict[name] = .array(array + overlayArray.dropFirst())
} else {
resultDict[name] = value
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Xcodeproj/pbxproj().swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func xcodeProject(
projectSettings.common.COMBINE_HIDPI_IMAGES = "YES"

// Defined for regular `swift build` instantiations, so also should be defined here.
projectSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["SWIFT_PACKAGE"]
projectSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["$(inherited)", "SWIFT_PACKAGE"]
projectSettings.common.GCC_PREPROCESSOR_DEFINITIONS += ["$(inherited)", "SWIFT_PACKAGE=1"]

// Opt out of headermaps. The semantics of the build should be explicitly
// defined by the project structure, so that we don't get any additional
Expand All @@ -161,10 +162,10 @@ func xcodeProject(
projectSettings.debug.DEBUG_INFORMATION_FORMAT = "dwarf"
projectSettings.debug.ENABLE_NS_ASSERTIONS = "YES"
projectSettings.debug.GCC_OPTIMIZATION_LEVEL = "0"
projectSettings.debug.GCC_PREPROCESSOR_DEFINITIONS = ["DEBUG=1", "$(inherited)"]
projectSettings.debug.GCC_PREPROCESSOR_DEFINITIONS = ["$(inherited)", "DEBUG=1"]
projectSettings.debug.ONLY_ACTIVE_ARCH = "YES"
projectSettings.debug.SWIFT_OPTIMIZATION_LEVEL = "-Onone"
projectSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["SWIFT_PACKAGE", "DEBUG"]
projectSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["$(inherited)", "DEBUG"]

// Add some release-specific settings.
projectSettings.release.COPY_PHASE_STRIP = "YES"
Expand Down
5 changes: 3 additions & 2 deletions Tests/XcodeprojTests/PackageGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ class PackageGraphTests: XCTestCase {
XCTAssertEqual(project.buildSettings.common.CLANG_ENABLE_OBJC_ARC, "YES")
XCTAssertEqual(project.buildSettings.release.SWIFT_OPTIMIZATION_LEVEL, "-Owholemodule")
XCTAssertEqual(project.buildSettings.debug.SWIFT_OPTIMIZATION_LEVEL, "-Onone")
XCTAssertEqual(project.buildSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["SWIFT_PACKAGE", "DEBUG"])
XCTAssertEqual(project.buildSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["SWIFT_PACKAGE"])
XCTAssertEqual(project.buildSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["$(inherited)", "DEBUG"])
XCTAssertEqual(project.buildSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["$(inherited)", "SWIFT_PACKAGE"])
XCTAssertEqual(project.buildSettings.common.GCC_PREPROCESSOR_DEFINITIONS, ["$(inherited)", "SWIFT_PACKAGE=1"])

result.check(target: "Foo") { targetResult in
targetResult.check(productType: .framework)
Expand Down