Skip to content

Support new XCTest overlays #2160

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 12, 2019
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
5 changes: 3 additions & 2 deletions Sources/Commands/SwiftTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,9 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
var env = try constructTestEnvironment(toolchain: try getToolchain(), options: self.options, buildParameters: self.buildParameters())
// Add the sdk platform path if we have it. If this is not present, we
// might always end up failing.
if let sdkPlatformFrameworksPath = Destination.sdkPlatformFrameworkPath() {
env["DYLD_FRAMEWORK_PATH"] = sdkPlatformFrameworksPath.pathString
if let sdkPlatformFrameworksPath = Destination.sdkPlatformFrameworkPaths() {
env["DYLD_FRAMEWORK_PATH"] = sdkPlatformFrameworksPath.fwk.pathString
env["DYLD_LIBRARY_PATH"] = sdkPlatformFrameworksPath.lib.pathString
}
try Process.checkNonZeroExit(arguments: args, environment: env)
// Read the temporary file's content.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TestSupport/Resources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Resources: ManifestResourceProvider {

#if os(macOS)
public var sdkPlatformFrameworksPath: AbsolutePath {
return Destination.sdkPlatformFrameworkPath()!
return Destination.sdkPlatformFrameworkPaths()!.fwk
}
#endif

Expand Down
32 changes: 24 additions & 8 deletions Sources/Workspace/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,21 @@ public struct Destination {
}

// Compute common arguments for clang and swift.
// This is currently just frameworks path.
let commonArgs = Destination.sdkPlatformFrameworkPath(environment: environment).map({ ["-F", $0.pathString] }) ?? []
var extraCCFlags: [String] = []
var extraSwiftCFlags: [String] = []
if let sdkPaths = Destination.sdkPlatformFrameworkPaths(environment: environment) {
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
}

return Destination(
target: hostTargetTriple,
sdk: sdkPath,
binDir: binDir,
extraCCFlags: commonArgs,
extraSwiftCFlags: commonArgs,
extraCCFlags: extraCCFlags,
extraSwiftCFlags: extraSwiftCFlags,
extraCPPFlags: ["-lc++"]
)
#else
Expand All @@ -127,21 +133,31 @@ public struct Destination {
}

/// Returns macosx sdk platform framework path.
public static func sdkPlatformFrameworkPath(environment: [String:String] = Process.env) -> AbsolutePath? {
public static func sdkPlatformFrameworkPaths(
environment: [String:String] = Process.env
) -> (fwk: AbsolutePath, lib: AbsolutePath)? {
if let path = _sdkPlatformFrameworkPath {
return path
}
let platformPath = try? Process.checkNonZeroExit(
arguments: ["xcrun", "--sdk", "macosx", "--show-sdk-platform-path"], environment: environment).spm_chomp()
arguments: ["xcrun", "--sdk", "macosx", "--show-sdk-platform-path"],
environment: environment).spm_chomp()

if let platformPath = platformPath, !platformPath.isEmpty {
_sdkPlatformFrameworkPath = AbsolutePath(platformPath).appending(
// For XCTest framework.
let fwk = AbsolutePath(platformPath).appending(
components: "Developer", "Library", "Frameworks")

// For XCTest Swift library.
let lib = AbsolutePath(platformPath).appending(
components: "Developer", "usr", "lib")

_sdkPlatformFrameworkPath = (fwk, lib)
}
return _sdkPlatformFrameworkPath
}
/// Cache storage for sdk platform path.
private static var _sdkPlatformFrameworkPath: AbsolutePath? = nil
private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil

/// Target triple for the host system.
private static let hostTargetTriple = Triple.hostTriple
Expand Down