Skip to content
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

[Xcodeproj] Fix logic for generating SWIFT_VERSION setting #1607

Merged
merged 1 commit into from Jun 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions Sources/Xcodeproj/pbxproj().swift
Expand Up @@ -78,7 +78,7 @@ func xcodeProject(
interpreterFlags[3] = "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/" + String(package.manifest.manifestVersion.rawValue)
}
pdTarget.buildSettings.common.OTHER_SWIFT_FLAGS += interpreterFlags
pdTarget.buildSettings.common.SWIFT_VERSION = "\(package.manifest.manifestVersion.rawValue).0"
pdTarget.buildSettings.common.SWIFT_VERSION = package.manifest.manifestVersion.swiftLanguageVersion.xcodeBuildSettingValue
pdTarget.buildSettings.common.LD = "/usr/bin/true"
}

Expand Down Expand Up @@ -459,7 +459,7 @@ func xcodeProject(

// Set the correct SWIFT_VERSION for the Swift targets.
if case let swiftTarget as SwiftTarget = target.underlyingTarget {
targetSettings.common.SWIFT_VERSION = "\(swiftTarget.swiftVersion).0"
targetSettings.common.SWIFT_VERSION = swiftTarget.swiftVersion.xcodeBuildSettingValue
}

// Add header search paths for any C target on which we depend.
Expand Down Expand Up @@ -716,3 +716,16 @@ private extension ResolvedTarget {
}
}
}

private extension SwiftLanguageVersion {
/// Returns the build setting value for the given Swift language version.
var xcodeBuildSettingValue: String {
// Swift version setting are represented differently in Xcode:
// 3 -> 4.0, 4 -> 4.0, 4.2 -> 4.2
var swiftVersion = "\(rawValue)"
if !rawValue.contains(".") {
swiftVersion += ".0"
}
return swiftVersion
}
}
31 changes: 31 additions & 0 deletions Tests/XcodeprojTests/PackageGraphTests.swift
Expand Up @@ -311,13 +311,44 @@ class PackageGraphTests: XCTestCase {
XCTAssertEqual(schemes["Foo-Package"]?.testTargets.map({ $0.name }).sorted(), ["aTests", "bcTests", "dTests", "libdTests"])
XCTAssertEqual(schemes["Foo-Package"]?.regularTargets.map({ $0.name }).sorted(), ["a", "b", "c", "d", "libd"])
}

func testSwiftVersion() throws {
// FIXME: Unfortunately, we can't test 4.2 right now.
for swiftVersion in [3, 4] {
let fs = InMemoryFileSystem(emptyFiles:
"/Foo/Sources/a/main.swift",
"/end"
)

let diagnostics = DiagnosticsEngine()
let graph = loadMockPackageGraph4([
"/Foo": .init(
name: "Foo",
targets: [
.target(name: "a"),
],
swiftLanguageVersions: [swiftVersion]
),
], root: "/Foo", diagnostics: diagnostics, in: fs)

let project = try xcodeProject(xcodeprojPath: AbsolutePath("/Foo").appending(component: "xcodeproj"), graph: graph, extraDirs: [], options: XcodeprojOptions(), fileSystem: fs, diagnostics: diagnostics)
XCTAssertNoDiagnostics(diagnostics)

XcodeProjectTester(project) { result in
result.check(target: "a") { targetResult in
XCTAssertEqual(targetResult.target.buildSettings.common.SWIFT_VERSION, "\(swiftVersion).0")
}
}
}
}

static var allTests = [
("testAggregateTarget", testAggregateTarget),
("testBasics", testBasics),
("testModuleLinkage", testModuleLinkage),
("testModulemap", testModulemap),
("testSchemes", testSchemes),
("testSwiftVersion", testSwiftVersion),
]
}

Expand Down