Skip to content

Commit 031cd65

Browse files
authored
Merge pull request #76 from kareman/Support_older_macOS
Support older macOS
2 parents 4a104a5 + fc130c4 commit 031cd65

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

Package.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import PackageDescription
33

44
let package = Package(
55
name: "SwiftShell",
6-
platforms: [
7-
.macOS(.v10_13),
8-
],
96
products: [
107
.library(
118
name: "SwiftShell",

Sources/SwiftShell/Command.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,18 @@ extension CommandRunning {
7373

7474
let process = Process()
7575
process.arguments = args
76-
process.executableURL = URL(fileURLWithPath: path(for: executable))
76+
if #available(OSX 10.13, *) {
77+
process.executableURL = URL(fileURLWithPath: path(for: executable))
78+
} else {
79+
process.launchPath = path(for: executable)
80+
}
7781

7882
process.environment = context.env
79-
process.currentDirectoryURL = URL(fileURLWithPath: context.currentdirectory, isDirectory: true)
83+
if #available(OSX 10.13, *) {
84+
process.currentDirectoryURL = URL(fileURLWithPath: context.currentdirectory, isDirectory: true)
85+
} else {
86+
process.currentDirectoryPath = context.currentdirectory
87+
}
8088

8189
process.standardInput = context.stdin.filehandle
8290
process.standardOutput = context.stdout.filehandle
@@ -399,9 +407,9 @@ extension CommandRunning {
399407
- parameter executable: path to an executable file.
400408
- parameter args: arguments to the executable.
401409
- throws:
402-
`CommandError.returnedErrorCode(command: String, errorcode: Int)` if the exit code is anything but 0.
410+
`CommandError.returnedErrorCode(command: String, errorcode: Int)` if the exit code is anything but 0.
403411

404-
`CommandError.inAccessibleExecutable(path: String)` if 'executable’ turned out to be not so executable after all.
412+
`CommandError.inAccessibleExecutable(path: String)` if 'executable’ turned out to be not so executable after all.
405413
*/
406414
public func runAndPrint(_ executable: String, _ args: Any ...) throws {
407415
let stringargs = args.flatten().map(String.init(describing:))
@@ -458,7 +466,7 @@ Runs executable and prints output and errors.
458466
- parameter args: arguments to the executable.
459467
- throws: `CommandError.returnedErrorCode(command: String, errorcode: Int)` if the exit code is anything but 0.
460468

461-
`CommandError.inAccessibleExecutable(path: String)` if 'executable’ turned out to be not so executable after all.
469+
`CommandError.inAccessibleExecutable(path: String)` if 'executable’ turned out to be not so executable after all.
462470
*/
463471
public func runAndPrint(_ executable: String, _ args: Any ...) throws {
464472
return try main.runAndPrint(executable, args)

Sources/SwiftShell/Process.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ extension Process {
2222
}
2323
#endif
2424
do {
25-
try run()
25+
if #available(OSX 10.13, *) {
26+
try run()
27+
} else {
28+
launch()
29+
}
2630
} catch CocoaError.fileNoSuchFile {
27-
throw CommandError.inAccessibleExecutable(path: self.executableURL!.lastPathComponent)
31+
if #available(OSX 10.13, *) {
32+
throw CommandError.inAccessibleExecutable(path: self.executableURL!.lastPathComponent)
33+
} else {
34+
throw CommandError.inAccessibleExecutable(path: self.launchPath!)
35+
}
2836
}
2937
}
3038

@@ -35,7 +43,12 @@ extension Process {
3543
public func finish() throws {
3644
/// The full path to the executable + all arguments, each one quoted if it contains a space.
3745
func commandAsString() -> String {
38-
let path = self.executableURL?.path ?? ""
46+
let path: String
47+
if #available(OSX 10.13, *) {
48+
path = self.executableURL?.path ?? ""
49+
} else {
50+
path = self.launchPath ?? ""
51+
}
3952
return (self.arguments ?? []).reduce(path) { (acc: String, arg: String) in
4053
return acc + " " + ( arg.contains(" ") ? ("\"" + arg + "\"") : arg )
4154
}

SwiftShell.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@
439439
GCC_WARN_UNINITIALIZED_AUTOS = YES;
440440
GCC_WARN_UNUSED_FUNCTION = YES;
441441
GCC_WARN_UNUSED_VARIABLE = YES;
442-
MACOSX_DEPLOYMENT_TARGET = 10.13;
443442
ONLY_ACTIVE_ARCH = YES;
444443
OTHER_SWIFT_FLAGS = "-DXcode";
445444
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -465,6 +464,7 @@
465464
HEADER_SEARCH_PATHS = "$(inherited)";
466465
INFOPLIST_FILE = SwiftShell.xcodeproj/SwiftShell_Info.plist;
467466
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
467+
MACOSX_DEPLOYMENT_TARGET = 10.11;
468468
OTHER_LDFLAGS = "$(inherited)";
469469
OTHER_SWIFT_FLAGS = "$(inherited) -D DEBUG";
470470
PRODUCT_BUNDLE_IDENTIFIER = SwiftShell;
@@ -568,7 +568,6 @@
568568
GCC_WARN_UNINITIALIZED_AUTOS = YES;
569569
GCC_WARN_UNUSED_FUNCTION = YES;
570570
GCC_WARN_UNUSED_VARIABLE = YES;
571-
MACOSX_DEPLOYMENT_TARGET = 10.13;
572571
OTHER_SWIFT_FLAGS = "-DXcode";
573572
PRODUCT_NAME = "$(TARGET_NAME)";
574573
SDKROOT = macosx;
@@ -593,6 +592,7 @@
593592
HEADER_SEARCH_PATHS = "$(inherited)";
594593
INFOPLIST_FILE = SwiftShell.xcodeproj/SwiftShell_Info.plist;
595594
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
595+
MACOSX_DEPLOYMENT_TARGET = 10.11;
596596
OTHER_LDFLAGS = "$(inherited)";
597597
OTHER_SWIFT_FLAGS = "$(inherited)";
598598
PRODUCT_BUNDLE_IDENTIFIER = SwiftShell;
@@ -698,7 +698,6 @@
698698
GCC_WARN_UNINITIALIZED_AUTOS = YES;
699699
GCC_WARN_UNUSED_FUNCTION = YES;
700700
GCC_WARN_UNUSED_VARIABLE = YES;
701-
MACOSX_DEPLOYMENT_TARGET = 10.13;
702701
ONLY_ACTIVE_ARCH = YES;
703702
OTHER_SWIFT_FLAGS = "-DXcode";
704703
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -746,7 +745,6 @@
746745
GCC_WARN_UNINITIALIZED_AUTOS = YES;
747746
GCC_WARN_UNUSED_FUNCTION = YES;
748747
GCC_WARN_UNUSED_VARIABLE = YES;
749-
MACOSX_DEPLOYMENT_TARGET = 10.13;
750748
OTHER_SWIFT_FLAGS = "-DXcode";
751749
PRODUCT_NAME = "$(TARGET_NAME)";
752750
SDKROOT = macosx;
@@ -771,6 +769,7 @@
771769
HEADER_SEARCH_PATHS = "$(inherited)";
772770
INFOPLIST_FILE = SwiftShell.xcodeproj/SwiftShell_Info.plist;
773771
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
772+
MACOSX_DEPLOYMENT_TARGET = 10.11;
774773
OTHER_LDFLAGS = "$(inherited)";
775774
OTHER_SWIFT_FLAGS = "$(inherited) -D DEBUG";
776775
PRODUCT_BUNDLE_IDENTIFIER = SwiftShell;
@@ -795,6 +794,7 @@
795794
HEADER_SEARCH_PATHS = "$(inherited)";
796795
INFOPLIST_FILE = SwiftShell.xcodeproj/SwiftShell_Info.plist;
797796
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
797+
MACOSX_DEPLOYMENT_TARGET = 10.11;
798798
OTHER_LDFLAGS = "$(inherited)";
799799
OTHER_SWIFT_FLAGS = "$(inherited)";
800800
PRODUCT_BUNDLE_IDENTIFIER = SwiftShell;

0 commit comments

Comments
 (0)