Skip to content
Merged
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
10 changes: 8 additions & 2 deletions Plugins/BridgeJS/Sources/TS2Skeleton/TS2Skeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
@preconcurrency import class Foundation.FileManager
@preconcurrency import struct Foundation.URL
@preconcurrency import struct Foundation.Data
@preconcurrency import struct Foundation.ObjCBool
@preconcurrency import func Foundation.kill
@preconcurrency import var Foundation.SIGINT
@preconcurrency import var Foundation.SIGTERM
import protocol Dispatch.DispatchSourceSignal
import class Dispatch.DispatchSource

internal func which(_ executable: String) throws -> URL {
func checkCandidate(_ candidate: URL) -> Bool {
var isDirectory: ObjCBool = false
let fileExists = FileManager.default.fileExists(atPath: candidate.path, isDirectory: &isDirectory)
return fileExists && !isDirectory.boolValue && FileManager.default.isExecutableFile(atPath: candidate.path)
}
do {
// Check overriding environment variable
let envVariable = executable.uppercased().replacingOccurrences(of: "-", with: "_") + "_PATH"
if let path = ProcessInfo.processInfo.environment[envVariable] {
let url = URL(fileURLWithPath: path).appendingPathComponent(executable)
if FileManager.default.isExecutableFile(atPath: url.path) {
if checkCandidate(url) {
return url
}
}
Expand All @@ -31,7 +37,7 @@ internal func which(_ executable: String) throws -> URL {
let paths = ProcessInfo.processInfo.environment["PATH"]!.split(separator: pathSeparator)
for path in paths {
let url = URL(fileURLWithPath: String(path)).appendingPathComponent(executable)
if FileManager.default.isExecutableFile(atPath: url.path) {
if checkCandidate(url) {
return url
}
}
Expand Down
9 changes: 7 additions & 2 deletions Plugins/PackageToJS/Sources/PackageToJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,17 @@ final class DefaultPackagingSystem: PackagingSystem {
}

internal func which(_ executable: String) throws -> URL {
func checkCandidate(_ candidate: URL) -> Bool {
var isDirectory: ObjCBool = false
let fileExists = FileManager.default.fileExists(atPath: candidate.path, isDirectory: &isDirectory)
return fileExists && !isDirectory.boolValue && FileManager.default.isExecutableFile(atPath: candidate.path)
}
do {
// Check overriding environment variable
let envVariable = executable.uppercased().replacingOccurrences(of: "-", with: "_") + "_PATH"
if let path = ProcessInfo.processInfo.environment[envVariable] {
let url = URL(fileURLWithPath: path).appendingPathComponent(executable)
if FileManager.default.isExecutableFile(atPath: url.path) {
if checkCandidate(url) {
return url
}
}
Expand All @@ -336,7 +341,7 @@ internal func which(_ executable: String) throws -> URL {
let paths = ProcessInfo.processInfo.environment["PATH"]!.split(separator: pathSeparator)
for path in paths {
let url = URL(fileURLWithPath: String(path)).appendingPathComponent(executable)
if FileManager.default.isExecutableFile(atPath: url.path) {
if checkCandidate(url) {
return url
}
}
Expand Down