Skip to content
Open
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
38 changes: 29 additions & 9 deletions ScriptWorker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,24 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Stephen Marquis";
TargetAttributes = {
AA514C971D6900BE00D563F2 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0830;
LastSwiftMigration = 0930;
};
AA514CA11D6900BE00D563F2 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0930;
};
AA514CC81D6927C500D563F2 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
};
B15A76B81E9558EF00AEABA3 = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 0930;
ProvisioningStyle = Automatic;
};
B15A76D91E959C9A00AEABA3 = {
Expand All @@ -404,6 +405,7 @@
};
B1D5BD511DF2219000E93D97 = {
CreatedOnToolsVersion = 8.1;
LastSwiftMigration = 0930;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -558,14 +560,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -609,14 +619,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -663,7 +681,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -685,7 +703,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.BobDevil.ScriptWorker;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -697,6 +715,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.BobDevil.ScriptWorkerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -708,6 +727,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.BobDevil.ScriptWorkerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down Expand Up @@ -743,7 +763,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -753,7 +773,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down Expand Up @@ -792,7 +812,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -802,7 +822,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion ScriptWorker/PipeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
@import Foundation;

// Need to catch broken pipe NSException, so small objective c shim
void forwardBrokenPipeToChild(pid_t child, void (^block)());
void forwardBrokenPipeToChild(pid_t child, void (^block)(void));
2 changes: 1 addition & 1 deletion ScriptWorker/PipeWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "PipeWriter.h"

void forwardBrokenPipeToChild(pid_t child, void (^block)()) {
void forwardBrokenPipeToChild(pid_t child, void (^block)(void)) {
@try {
block();
} @catch(NSException *e) {
Expand Down
5 changes: 3 additions & 2 deletions ScriptWorker/ScriptTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class ScriptTask {
return description
}

private func setup(pipe: Pipe, stdout: Bool) -> ((Void) -> Void) {
private func setup(pipe: Pipe, stdout: Bool) -> (() -> Void) {
let readHandle = pipe.fileHandleForReading
let semaphore = DispatchSemaphore(value: 1)

Expand All @@ -260,7 +260,8 @@ public class ScriptTask {
semaphore.signal()
}

return { [weak self] in
return {
[weak self] in
// The 'readabilityHandler' for a file handle doesn't get triggered for EOF for whatever reason, so we clear out the readability handler and read the last available data when the task is done.
semaphore.wait()
readHandle.readabilityHandler = nil
Expand Down
2 changes: 1 addition & 1 deletion ScriptWorker/trap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum Signal: Int32 {
case TERM = 15
}

func trap(signal: Signal, action: @convention(c) (Int32) -> ()) {
func trap(signal: Signal, action: @escaping @convention(c) (Int32) -> ()) {
// From Swift, sigaction.init() collides with the Darwin.sigaction() function.
// This local typealias allows us to disambiguate them.
typealias SignalAction = sigaction
Expand Down
2 changes: 1 addition & 1 deletion swiftscript/SwiftScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SwiftScript {
return nil
}

var path = trimmedLine.substring(from: range.upperBound).trimmingCharacters(in: .whitespaces)
var path = String(trimmedLine[range.upperBound...]).trimmingCharacters(in: .whitespaces)
path = (path as NSString).expandingTildeInPath
let url: URL
if (path as NSString).isAbsolutePath {
Expand Down
37 changes: 21 additions & 16 deletions swiftscript/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,33 @@ func runExec(task: String, args: [String], overrideExecutablePath: String? = nil
// Returns the path to the executable in the temporary directory
func setup(file: URL, withAdditionalFiles additionalFiles: [URL], searchPaths: [URL]) -> URL {
let workingDirectoryTemplate = NSTemporaryDirectory() + "/swiftscript-XXX"
guard let cstring = mkdtemp(UnsafeMutablePointer(mutating: workingDirectoryTemplate.cString(using: .utf8))) else {
print("Failed to create temporary directory for compilation: errno \(errno)")
exit(1)
}

let workingDirectory = URL(fileURLWithPath: String(cString: cstring))

let swiftFiles = SwiftScript.swiftURLs(for: additionalFiles)
print("working dir template = \(workingDirectoryTemplate)")

let (mainFile, compiledFiles) = SwiftScript.setup(workingDirectory: workingDirectory, for: file, with: swiftFiles)
return workingDirectoryTemplate.withCString { workingDirCString in
guard let cstring = mkdtemp(UnsafeMutablePointer(mutating:workingDirCString)) else {
print("Failed to create temporary directory for compilation: errno \(errno)")
exit(1)
}

let workingDirectory = URL(fileURLWithPath: String(cString: cstring))

let process = Process()
process.launchPath = "/usr/bin/xcrun"
let swiftFiles = SwiftScript.swiftURLs(for: additionalFiles)

let executableURL = workingDirectory.appendingPathComponent(file.deletingPathExtension().lastPathComponent)
let (mainFile, compiledFiles) = SwiftScript.setup(workingDirectory: workingDirectory, for: file, with: swiftFiles)

let args = ["swiftc", "-o", executableURL.path] + SwiftScript.swiftArguments(for: mainFile, additionalFiles: compiledFiles, searchPaths: searchPaths)
process.arguments = args
process.launch()
process.waitUntilExit()
let process = Process()
process.launchPath = "/usr/bin/xcrun"

let executableURL = workingDirectory.appendingPathComponent(file.deletingPathExtension().lastPathComponent)

let args = ["swiftc", "-o", executableURL.path] + SwiftScript.swiftArguments(for: mainFile, additionalFiles: compiledFiles, searchPaths: searchPaths)
process.arguments = args
process.launch()
process.waitUntilExit()

return executableURL
return executableURL
}
}

guard CommandLine.arguments.count >= 2 else {
Expand Down