Commit 84d52ae1 authored by Johannes Schriewer's avatar Johannes Schriewer

Fix the remaining bugs. Remove `try!` and replace with do {} catch { fatalError }

parent 77896540
Pipeline #1666 failed with stage
......@@ -80,7 +80,12 @@ overlays.append(contentsOf: Platform.targetPlatform.overlays)
print("enabling overlays \(overlays)")
let package = try! Package(filepath: packageFile, overlay: overlays, focusOnTask: focusOnTask)
var package: Package! = nil
do {
package = try Package(filepath: packageFile, overlay: overlays, focusOnTask: focusOnTask)
} catch {
fatalError("Could not load package file: \(error)")
}
//usage message
if Process.arguments.contains("--help") {
......
Subproject commit 01ec78cbf0a5bb7ca057b8116e04136ae722afcd
Subproject commit a0b4e3b02e1a87bd3ed106903250e6a29d85d1c5
......@@ -63,28 +63,28 @@ class PackageFramework: Tool {
//rm framework if it exists
let frameworkPath = Path("bin/\(name).framework")
let _ = try? FS.removeItem(path: frameworkPath)
try! FS.createDirectory(path: frameworkPath)
let _ = try? FS.removeItem(path: frameworkPath, recursive: true)
let _ = try? FS.createDirectory(path: frameworkPath)
//'a' version
let relativeAVersionPath = Path("Versions/A")
let AVersionPath = frameworkPath + relativeAVersionPath
try! FS.createDirectory(path: AVersionPath, intermediate: true)
//'current' (produces code signing failures if absent)
try! FS.symlinkItem(from: frameworkPath + "Versions/Current", to: Path("A"))
try! FS.symlinkItem(from: Path("A"), to: frameworkPath + "Versions/Current")
//copy payload
let payloadPath = task.importedPath.appending("bin").appending(name + Platform.targetPlatform.dynamicLibraryExtension)
print(payloadPath)
try! FS.copyItem(from: payloadPath, to: AVersionPath.appending(name))
try! FS.symlinkItem(from: frameworkPath.appending(name), to: relativeAVersionPath.appending(name))
try! FS.symlinkItem(from: relativeAVersionPath.appending(name), to: frameworkPath.appending(name))
//copy modules
let modulePath = AVersionPath.appending("Modules").appending(name + ".swiftmodule")
try! FS.createDirectory(path: modulePath, intermediate: true)
try! FS.copyItem(from: Path("bin/\(name).swiftmodule"), to: modulePath.appending(Platform.targetPlatform.architecture + ".swiftmodule"))
try! FS.copyItem(from: Path("bin/\(name).swiftdoc"), to: modulePath.appending(Platform.targetPlatform.architecture + ".swiftdoc"))
try! FS.symlinkItem(from: frameworkPath.appending("Modules"), to: relativeAVersionPath.appending("Modules"))
try! FS.symlinkItem(from: relativeAVersionPath.appending("Modules"), to: frameworkPath.appending("Modules"))
//copy resources
let resourcesPath = AVersionPath.appending("Resources")
......@@ -92,7 +92,7 @@ class PackageFramework: Tool {
for resource in resources {
try! FS.copyItem(from: task.importedPath + resource, to: resourcesPath + resource)
}
try! FS.symlinkItem(from: frameworkPath + "Resources", to: relativeAVersionPath + "Resources")
try! FS.symlinkItem(from: relativeAVersionPath + "Resources", to: frameworkPath + "Resources")
//codesign
let cmd = "codesign --force --deep --sign - --timestamp=none '\(AVersionPath)'"
......
......@@ -43,7 +43,7 @@ final class Shell : Tool {
}
try FS.changeWorkingDirectory(path: task.importedPath)
anarchySystem("/bin/sh -c \"\(script)\"")
} catch {
print("Can not change working directory to '\(task.importedPath)': \(error)")
......
......@@ -24,7 +24,11 @@ final public class TaskRunner {
static public func runTask(task: Task, package: Package, toolchain: String) {
print("Running task \(task.qualifiedName) with overlays \(task.appliedOverlays)")
try! task.checkRequiredOverlays()
do {
try task.checkRequiredOverlays()
} catch {
fatalError("Not all required overlays present: \(error)")
}
let tool = toolByName(name: task.tool)
tool.run(task: task, toolchain: toolchain)
print("Completed task \(task.qualifiedName).")
......
......@@ -55,13 +55,17 @@ private var userPathCreated = false
- postcondition: The path exists at this absolute locaton on disk.
- warning: This path is cleared between atbuild invocations. */
func userPath() -> Path {
let userPath = try! FS.getWorkingDirectory().appending("user")
if !userPathCreated {
let _ = try? FS.removeItem(path: userPath, recursive: true)
try! FS.createDirectory(path: userPath)
userPathCreated = true
do {
let userPath = try FS.getWorkingDirectory().appending("user")
if !userPathCreated {
let _ = try FS.removeItem(path: userPath, recursive: true)
try FS.createDirectory(path: userPath)
userPathCreated = true
}
return userPath
} catch {
fatalError("Could not create user dir: \(error)")
}
return userPath
}
///A wrapper for POSIX "system" call.
......
......@@ -25,44 +25,47 @@ class XCTestRun : Tool {
fatalError("No \(Option.TestExecutable.rawValue) for XCTestRun task \(task.qualifiedName)")
}
switch (Platform.targetPlatform) {
case .OSX:
let workingDirectory = try! FS.temporaryDirectory(prefix: "XCTest-\(task)")
let executablePath = workingDirectory + "XCTestRun.xctest/Contents/MacOS"
try! FS.createDirectory(path: executablePath, intermediate: true)
try! FS.copyItem(from: Path(testExecutable), to: executablePath.appending("XCTestRun"))
var s = ""
s += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
s += "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
s += "<plist version=\"1.0\">\n"
s += "<dict>\n"
s += "<key>CFBundleDevelopmentRegion</key>\n"
s += "<string>en</string>\n"
s += "<key>CFBundleExecutable</key>\n"
s += "<string>XCTestRun</string>\n"
s += "<key>CFBundleIdentifier</key>\n"
s += "<string>org.swift.package-manager.dep-tests</string>\n"
s += "<key>CFBundleInfoDictionaryVersion</key>\n"
s += "<string>6.0</string>\n"
s += "<key>CFBundleName</key>\n"
s += "<string>NaOHTests</string>\n"
s += "<key>CFBundlePackageType</key>\n"
s += "<string>BNDL</string>\n"
s += "<key>CFBundleShortVersionString</key>\n"
s += "<string>1.0</string>\n"
s += "<key>CFBundleSignature</key>\n"
s += "<string>????</string>\n"
s += "<key>CFBundleSupportedPlatforms</key>\n"
s += "<array>\n"
s += "<string>MacOSX</string>\n"
s += "</array>\n"
s += "<key>CFBundleVersion</key>\n"
s += "<string>1</string>\n"
s += "</dict>\n"
s += "</plist>\n"
try! s.write(to: workingDirectory + "XCTestRun.xctest/Contents/Info.plist")
anarchySystem("xcrun xctest \(workingDirectory)/XCTestRun.xctest")
case .OSX:
do {
let workingDirectory = try FS.temporaryDirectory(prefix: "XCTest-\(task)")
let executablePath = workingDirectory + "XCTestRun.xctest/Contents/MacOS"
try FS.createDirectory(path: executablePath, intermediate: true)
try FS.copyItem(from: Path(testExecutable), to: executablePath.appending("XCTestRun"))
var s = ""
s += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
s += "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
s += "<plist version=\"1.0\">\n"
s += "<dict>\n"
s += "<key>CFBundleDevelopmentRegion</key>\n"
s += "<string>en</string>\n"
s += "<key>CFBundleExecutable</key>\n"
s += "<string>XCTestRun</string>\n"
s += "<key>CFBundleIdentifier</key>\n"
s += "<string>org.swift.package-manager.dep-tests</string>\n"
s += "<key>CFBundleInfoDictionaryVersion</key>\n"
s += "<string>6.0</string>\n"
s += "<key>CFBundleName</key>\n"
s += "<string>NaOHTests</string>\n"
s += "<key>CFBundlePackageType</key>\n"
s += "<string>BNDL</string>\n"
s += "<key>CFBundleShortVersionString</key>\n"
s += "<string>1.0</string>\n"
s += "<key>CFBundleSignature</key>\n"
s += "<string>????</string>\n"
s += "<key>CFBundleSupportedPlatforms</key>\n"
s += "<array>\n"
s += "<string>MacOSX</string>\n"
s += "</array>\n"
s += "<key>CFBundleVersion</key>\n"
s += "<string>1</string>\n"
s += "</dict>\n"
s += "</plist>\n"
try s.write(to: workingDirectory + "XCTestRun.xctest/Contents/Info.plist")
anarchySystem("xcrun xctest \(workingDirectory)/XCTestRun.xctest")
} catch {
fatalError("Could not run XCTest: \(error)")
}
case .Linux:
anarchySystem("\(testExecutable)")
}
......
......@@ -90,8 +90,9 @@ final class ATllbuild : Tool {
yaml += " <atllbuild-swiftc>:\n"
yaml += " tool: swift-compiler\n"
yaml += " executable: \"\(swiftCPath)\"\n"
yaml += " inputs: \(sources)\n"
yaml += " sources: \(sources)\n"
let inputs = String.join(parts: sources.map { path in path.description }, delimiter: "\", \"")
yaml += " inputs: [\"\(inputs)\"]\n"
yaml += " sources: [\"\(inputs)\"]\n"
//swiftPM wants "objects" which is just a list of %.swift.o files. We have to put them in a temp directory though.
let objects = sources.map { (source) -> String in
......@@ -259,10 +260,10 @@ final class ATllbuild : Tool {
//and in particular, without erasing the product directory, since that accumulates build products across
//multiple invocations of atllbuild.
if Process.arguments.contains("--clean") {
let _ = try? FS.removeItem(path: workDirectory.appending("objects"))
let _ = try? FS.removeItem(path: workDirectory.appending("llbuildtmp"))
let _ = try? FS.removeItem(path: workDirectory.appending("objects"), recursive: true)
let _ = try? FS.removeItem(path: workDirectory.appending("llbuildtmp"), recursive: true)
}
let _ = try? FS.removeItem(path: workDirectory.appending("include"))
let _ = try? FS.removeItem(path: workDirectory.appending("include"), recursive: true)
......@@ -337,8 +338,12 @@ final class ATllbuild : Tool {
potentially conflicts with other modulemaps, so we give it its own directory, namespaced
by the product name. */
let pathName = workDirectory + "include/\(productName)"
try! FS.createDirectory(path: pathName)
try! FS.copyItem(from: moduleMapPath, to: pathName.appending("module.modulemap"))
let _ = try? FS.createDirectory(path: pathName, intermediate: true)
do {
try FS.copyItem(from: moduleMapPath, to: pathName.appending("module.modulemap"))
} catch {
fatalError("Could not copy modulemap to \(pathName): \(error)")
}
compileOptions.append(contentsOf: ["-I", pathName.description])
}
}
......@@ -354,21 +359,30 @@ final class ATllbuild : Tool {
case .OSX:
compileOptions.append(contentsOf: ["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/"])
linkOptions.append(contentsOf: ["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-target", "x86_64-apple-macosx10.11", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-Xlinker", "-bundle"])
case .Linux:
break
}
}
if task[Options.XCTestStrict.rawValue]?.bool == true {
switch Platform.targetPlatform {
case .OSX:
case .OSX:
//inject XCTestCaseProvider.swift
let xcTestCaseProviderPath = try! FS.temporaryDirectory(prefix: "XCTestCase")
try! ATllbuild.xcTestCaseProvider.write(to: xcTestCaseProviderPath.appending("XCTestCaseProvider.swift"))
sources.append(xcTestCaseProviderPath)
do {
let xcTestCaseProviderPath = try FS.temporaryDirectory(prefix: "XCTestCase")
do {
try ATllbuild.xcTestCaseProvider.write(to: xcTestCaseProviderPath.appending("XCTestCaseProvider.swift"))
sources.append(xcTestCaseProviderPath.appending("XCTestCaseProvider.swift"))
} catch {
print(xcTestCaseProviderPath)
fatalError("Could not inject XCTestCaseProvider: \(error)")
}
} catch {
fatalError("Could not create temp dir for XCTestCaseProvider: \(error)")
}
case .Linux:
case .Linux:
break
}
}
......@@ -395,8 +409,12 @@ final class ATllbuild : Tool {
if let umbrellaHeader = task[Options.UmbrellaHeader.rawValue]?.string {
precondition(moduleMap == .Synthesized, ":\(Options.ModuleMap.rawValue) \"synthesized\" must be used with the \(Options.UmbrellaHeader.rawValue) option")
let s = synthesizeModuleMap(name: name, umbrellaHeader: "Umbrella.h")
try! s.write(to: workDirectory + "include/module.modulemap")
try! FS.copyItem(from: task.importedPath + umbrellaHeader, to: workDirectory + "include/Umbrella.h")
do {
try s.write(to: workDirectory + "include/module.modulemap")
try FS.copyItem(from: task.importedPath + umbrellaHeader, to: workDirectory + "include/Umbrella.h")
} catch {
fatalError("Could not synthesize module map from umbrella header: \(error)")
}
compileOptions.append("-I")
compileOptions.append(workDirectory.appending("include").description + "/")
compileOptions.append("-import-underlying-module")
......@@ -415,7 +433,7 @@ final class ATllbuild : Tool {
///The next task will not be bootstrapped.
defer { Platform.buildPlatform = Platform.hostPlatform }
let sdk: Bool
if task[Options.LinkSDK.rawValue]?.bool == false {
sdk = false
......@@ -444,35 +462,43 @@ final class ATllbuild : Tool {
if bootstrapOnly { return }
switch moduleMap {
case .None:
break
case .Synthesized:
let s = synthesizeModuleMap(name: name, umbrellaHeader: nil)
try! s.write(to: workDirectory + "products/\(name).modulemap")
case .None:
break
case .Synthesized:
let s = synthesizeModuleMap(name: name, umbrellaHeader: nil)
do {
try s.write(to: workDirectory + "products/\(name).modulemap")
} catch {
fatalError("Could not write synthesized module map: \(error)")
}
}
//SR-566
let cmd = "\(findToolPath(toolName: "swift-build-tool",toolchain: toolchain)) -f \(llbuildyamlpath)"
anarchySystem(cmd)
if task[Options.PublishProduct.rawValue]?.bool == true {
if !FS.isDirectory(path: Path("bin")) {
try! FS.createDirectory(path: Path("bin"))
}
try! FS.copyItem(from: workDirectory + "products/\(name).swiftmodule", to: Path("bin/\(name).swiftmodule"))
try! FS.copyItem(from: workDirectory + "products/\(name).swiftdoc", to: Path("bin/\(name).swiftdoc"))
switch outputType {
case .Executable:
try! FS.copyItem(from: workDirectory + "products/\(name)", to: Path("bin/\(name)"))
case .StaticLibrary:
try! FS.copyItem(from: workDirectory + "products/\(name).a", to: Path("bin/\(name).a"))
case .DynamicLibrary:
try! FS.copyItem(from: workDirectory + ("products/\(name)." + Platform.targetPlatform.dynamicLibraryExtension) , to: Path("bin/\(name)." + Platform.targetPlatform.dynamicLibraryExtension))
}
switch moduleMap {
do {
if !FS.isDirectory(path: Path("bin")) {
try FS.createDirectory(path: Path("bin"))
}
try FS.copyItem(from: workDirectory + "products/\(name).swiftmodule", to: Path("bin/\(name).swiftmodule"))
try FS.copyItem(from: workDirectory + "products/\(name).swiftdoc", to: Path("bin/\(name).swiftdoc"))
switch outputType {
case .Executable:
try FS.copyItem(from: workDirectory + "products/\(name)", to: Path("bin/\(name)"))
case .StaticLibrary:
try FS.copyItem(from: workDirectory + "products/\(name).a", to: Path("bin/\(name).a"))
case .DynamicLibrary:
try FS.copyItem(from: workDirectory + ("products/\(name)" + Platform.targetPlatform.dynamicLibraryExtension) , to: Path("bin/\(name)" + Platform.targetPlatform.dynamicLibraryExtension))
}
switch moduleMap {
case .None:
break
break
case .Synthesized:
try! FS.copyItem(from: workDirectory + "products/\(name).modulemap", to: Path("bin/\(name).modulemap"))
try FS.copyItem(from: workDirectory + "products/\(name).modulemap", to: Path("bin/\(name).modulemap"))
}
} catch {
print("Could not publish product: \(error)")
}
}
......
......@@ -16,7 +16,7 @@ commands:
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
module-name: platforms
module-output-path: .atllbuild/products/platforms.swiftmodule
temps-path: .atllbuild//llbuildtmp
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-D", "LINUX"]
<atllbuild>:
tool: shell
......
......@@ -16,7 +16,7 @@ commands:
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
module-name: platforms
module-output-path: .atllbuild/products/platforms.swiftmodule
temps-path: .atllbuild//llbuildtmp
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk", "-D", "OSX"]
<atllbuild>:
tool: shell
......
......@@ -53,7 +53,7 @@ echo "****************XCODE TOOLCHAIN TEST**************"
if [ -e "/Applications/Xcode.app" ]; then
cd $DIR/tests/fixtures/xcode_toolchain
$ATBUILD --toolchain xcode
$ATBUILD --toolchain xcode
else
echo "Xcode is not installed; skipping test"
fi
......
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