Commit a4d211ee authored by Drew's avatar Drew

Support Xcode 8 GM

* Drop test coverage for Xcode 7 since it's likely not installed
* We now pull paths from xcode-select when we don't specify a toolchain which is saner than using hardcoded paths
* We now more robustly test if a given toolchain is from xcode 7 or not rather than rely on the filename
* Bootstrap for Xcode 8 installed to Xcode.app
parent 3255fef3
Pipeline #2594 passed with stage
in 5 minutes and 20 seconds
......@@ -14,6 +14,39 @@
import atfoundation
/**Drew's incredibly dumb string library */
extension String {
func match(_ b: String) -> ClosedRange<String.CharacterView.Index>? {
var idx = characters.startIndex
while idx != endIndex {
var l_idx_pre = idx
var l_idx = idx
var found = true
for charB in b.characters {
let charAL = characters[l_idx]
if charAL != charB { found = false; break }
l_idx_pre = l_idx
l_idx = characters.index(after: l_idx)
}
if found {
return ClosedRange(uncheckedBounds: (lower: idx, upper: l_idx_pre))
}
idx = characters.index(after: idx)
}
return nil
}
func prefix(to: String.CharacterView.Index) -> String {
let notEndIndex = characters.index(before: characters.endIndex)
let notStartIndex = characters.index(after: to)
let closedRange = ClosedRange(uncheckedBounds: (lower: notStartIndex, upper: notEndIndex))
var s = self
s.removeSubrange(closedRange)
return s
}
}
public enum Architecture {
case x86_64
case i386
......@@ -56,7 +89,34 @@ public enum Platform {
public static var toolchain: String? = nil
static var isXcode7: Bool { return Platform.toolchain!.contains(string: "Xcode.app") }
private static var isXcode7: Bool {
#if os(OSX)
return FS.fileExists(path: Path("\(Platform.developerPath)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"))
#else
return false //no linux platform uses xcode 7
//unless you count Project Marklar 2
#endif
}
private static var developerPath: String {
//first, look at the toolchain for clues
if let match = Platform.toolchain!.match(".app/Contents/Developer") {
return Platform.toolchain!.prefix(to: match.upperBound)
}
//assuming that failed, try xcode-select
#if os(OSX)
var xcode_select_path = ""
anarchySystem("xcode-select -p", environment:[:], redirectOutput: &xcode_select_path)
//lop off the newline
var notEndIndex = xcode_select_path.characters.index(before: xcode_select_path.characters.endIndex)
notEndIndex = xcode_select_path.characters.index(before: notEndIndex)
xcode_select_path = xcode_select_path.prefix(to: notEndIndex)
return xcode_select_path
#else
//on linux, let's just use /Applications/Xcode.app
return "/Applications/Xcode.app/Contents/Developer"
#endif
}
//generic platforms
case iOSGeneric
......@@ -117,22 +177,27 @@ public enum Platform {
var sdkPath: String? {
switch(self) {
case .OSX:
//look for a current-generation path
if Platform.isXcode7 {
return "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"
return "\(Platform.developerPath)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"
}
return "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
return "\(Platform.developerPath)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
case .Linux:
return nil
case .iOS(.x86_64), .iOS(.i386):
if Platform.isXcode7 {
return "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk"
return "\(Platform.developerPath)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk"
}
else {
return "\(Platform.developerPath)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
}
return "/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
case .iOS(.armv7), .iOS(.arm64):
if Platform.isXcode7 {
return "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk"
return "\(Platform.developerPath)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk"
}
else {
return "\(Platform.developerPath)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
}
return "/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
case .iOSGeneric:
fatalError("No SDK for generic iOS platform; choose a specific platform or use atbin")
}
......@@ -251,7 +316,6 @@ func findToolPath(toolName: String) -> Path {
if toolName == "swift-build-tool" {
let sbtPath = Path("\(Platform.hostPlatform.defaultToolchainPath)/usr/bin/\(toolName)")
if FS.fileExists(path: sbtPath) { return sbtPath }
}
}
else {
......
......@@ -109,6 +109,10 @@ func waitpid(_ pid: pid_t) -> Int32 {
///- note: This function call is appropriate for commands that are user-perceivable (such as compilation)
///Rather than calls that aren't
func anarchySystem(_ cmd: String, environment: [String: String]) {
var output = ""
anarchySystem(cmd, environment: environment, redirectOutput: &output, shouldRedirectOutput: false)
}
func anarchySystem(_ cmd: String, environment: [String: String],redirectOutput: inout String, shouldRedirectOutput: Bool = true) {
var pid : pid_t = 0
//copy a few well-known values
var environment = environment
......@@ -117,7 +121,10 @@ func anarchySystem(_ cmd: String, environment: [String: String]) {
environment[arg] = String(validatingUTF8: path)!
}
}
var cmd = cmd
if shouldRedirectOutput {
cmd += ">/tmp/anarchySystem.out"
}
let args: [String] = ["sh","-c",cmd]
let argv = args.map{ $0.withCString(strdup) }
let env: [UnsafeMutablePointer<CChar>?] = environment.map{ "\($0.0)=\($0.1)".withCString(strdup) }
......@@ -125,7 +132,7 @@ func anarchySystem(_ cmd: String, environment: [String: String]) {
let directory = try! FS.getWorkingDirectory()
defer {try! FS.changeWorkingDirectory(path: directory)}
if let e = environment["PWD"] {
try! FS.changeWorkingDirectory(path: Path(environment["PWD"]!))
try! FS.changeWorkingDirectory(path: Path(e))
}
let status = posix_spawn(&pid, "/bin/sh",nil,nil,argv + [nil],env + [nil])
......@@ -134,8 +141,9 @@ func anarchySystem(_ cmd: String, environment: [String: String]) {
fatalError("spawn error \(status)")
}
let returnCode = try! waitpid(pid)
if returnCode != 0 {
fatalError("process \(cmd) error \(returnCode)")
let returnCode = waitpid(pid)
if shouldRedirectOutput {
redirectOutput = try! File(path: Path("/tmp/anarchySystem.out"), mode:.ReadOnly).readAll()!
}
if returnCode != 0 { exit(1) }
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ commands:
module-name: atfoundation
module-output-path: .atllbuild/products/atfoundation.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/", "-enable-testing", "-g", "-Xcc", "-D_GNU_SOURCE", "-g", "-DATBUILD_DEBUG"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-enable-testing", "-g", "-Xcc", "-D_GNU_SOURCE", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/charset.swift.o", ".atllbuild/objects/date.swift.o", ".atllbuild/objects/timeinterval.swift.o", ".atllbuild/objects/file.swift.o", ".atllbuild/objects/fileinfo.swift.o", ".atllbuild/objects/fs.swift.o", ".atllbuild/objects/path.swift.o", ".atllbuild/objects/logger.swift.o", ".atllbuild/objects/replace.swift.o", ".atllbuild/objects/search.swift.o", ".atllbuild/objects/split.swift.o", ".atllbuild/objects/substring.swift.o", ".atllbuild/objects/whitespace.swift.o", ".atllbuild/objects/string.swift.o", ".atllbuild/objects/syserror.swift.o", ".atllbuild/objects/tools.swift.o", ".atllbuild/objects/url.swift.o"]
......
......@@ -20,7 +20,7 @@ commands:
module-name: atpkg
module-output-path: .atllbuild/products/atpkg.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/", "-g", "-DATBUILD_DEBUG"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/Binary.swift.o", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
......
......@@ -20,7 +20,7 @@ commands:
module-name: attools
module-output-path: .atllbuild/products/attools.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/", "-g", "-DATBUILD_DEBUG"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/atllbuild.swift.o", ".atllbuild/objects/Configuration.swift.o", ".atllbuild/objects/CustomTool.swift.o", ".atllbuild/objects/Nop.swift.o", ".atllbuild/objects/PackageAtbin.swift.o", ".atllbuild/objects/PackageFramework.swift.o", ".atllbuild/objects/PlatformPaths.swift.o", ".atllbuild/objects/Shell.swift.o", ".atllbuild/objects/TaskRunner.swift.o", ".atllbuild/objects/Tools.swift.o", ".atllbuild/objects/XCTestRun.swift.o"]
......
......@@ -19,7 +19,7 @@ commands:
module-name: atbuild
module-output-path: .atllbuild/products/atbuild.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/", "-g", "-DATBUILD_DEBUG"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o", ".atllbuild/products/attools.a", ".atllbuild/products/atpkg.a", ".atllbuild/products/atfoundation.a"]
......
......@@ -72,7 +72,7 @@
:bootstrap {
:tool "shell"
:script "atbuild atbuild --use-overlay bootstrap-linux --platform linux && atbuild atbuild --use-overlay bootstrap-osx --platform osx"
:script "bin/atbuild atbuild --use-overlay bootstrap-linux --platform linux && bin/atbuild atbuild --use-overlay bootstrap-osx --platform osx"
}
:atbin {
......
......@@ -19,7 +19,7 @@ commands:
module-name: platforms
module-output-path: .atllbuild/products/platforms.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-D", "OSX", "-g", "-DATBUILD_DEBUG"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-D", "OSX", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
......
......@@ -2,13 +2,6 @@
:name "xcode_toolchain"
:tasks {
:default {
:tool "atllbuild"
:sources ["test.swift"]
:name "hello"
:output-type "executable"
:publish-product true
}
:swiftthree {
:tool "atllbuild"
:sources ["test-3.swift"]
......
......@@ -415,16 +415,9 @@ echo "****************XCODE TOOLCHAIN TEST**************"
if [ -e "/Applications/Xcode.app" ]; then
cd $DIR/tests/fixtures/xcode_toolchain
$ATBUILD --toolchain xcode
$ATBUILD swiftthree --toolchain xcode
else
echo "Xcode is not installed; skipping test"
fi
if [ -e "/Applications/Xcode-beta.app" ]; then
cd $DIR/tests/fixtures/xcode_toolchain
$ATBUILD swiftthree --toolchain xcode-beta
else
echo "Xcode beta toolchain is not installed; skipping test"
echo "Xcode toolchain is not installed; skipping test"
fi
echo "****************PACKAGE FRAMEWORK TESTS**************"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment