Skip to content

Commit

Permalink
[ManifestLoader] Look for sdk root if not present in resources
Browse files Browse the repository at this point in the history
-- <rdar://problem/31776754> Compute SDKROOT in manifest loader if not provided in resources
  • Loading branch information
aciidgh committed Apr 24, 2017
1 parent 3d57e63 commit 3f61f50
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
@@ -255,8 +255,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
cmd += ["-target", "x86_64-apple-macosx10.10"]
#endif

// Add sdk, if provided in the resources.
if let sdkRoot = resources.sdkRoot {
// Use SDK root from resources or try to compute one locally.
if let sdkRoot = resources.sdkRoot ?? self.sdkRoot() {
cmd += ["-sdk", sdkRoot.asString]
}

@@ -283,6 +283,27 @@ public final class ManifestLoader: ManifestLoaderProtocol {

return json.isEmpty ? nil : json
}

/// Returns path to the sdk, if possible.
private func sdkRoot() -> AbsolutePath? {
if let sdkRoot = _sdkRoot {
return sdkRoot
}

// Find SDKROOT on macOS using xcrun.
#if os(macOS)
let foundPath = try? Process.checkNonZeroExit(
args: "xcrun", "--sdk", "macosx", "--show-sdk-path")
guard let sdkRoot = foundPath?.chomp(), !sdkRoot.isEmpty else {
return nil
}
_sdkRoot = AbsolutePath(sdkRoot)
#endif

return _sdkRoot
}
// Cache storage for computed sdk path.
private var _sdkRoot: AbsolutePath? = nil
}

/// Returns the sandbox profile to be used when parsing manifest on macOS.

0 comments on commit 3f61f50

Please sign in to comment.