diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..6dd2e713d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git/ +.build/ +.swiftpm/ +.release/ +bazel-* +docker/ diff --git a/.mise/tasks/scan-linux b/.mise/tasks/scan-linux new file mode 100755 index 000000000..3bd3bde9a --- /dev/null +++ b/.mise/tasks/scan-linux @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +export DOCKER_CLI_HINTS=false +docker build -t periphery -f docker/Dockerfile.linux . +docker run --rm -t periphery scan "$@" diff --git a/Package.swift b/Package.swift index fbb87dba9..45dc3336f 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ var dependencies: [Package.Dependency] = [ .package(url: "https://github.com/jpsim/Yams", from: "5.0.0"), .package(url: "https://github.com/tadija/AEXML", from: "4.0.0"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), - .package(url: "https://github.com/kateinoigakukun/swift-indexstore", from: "0.3.0"), + .package(url: "https://github.com/ileitch/swift-indexstore", revision: "a8a375fa31d7f861a8ee44a4d3acab9ecaf742ea"), .package(url: "https://github.com/apple/swift-syntax", from: "600.0.1"), .package(url: "https://github.com/ileitch/swift-filename-matcher", from: "2.0.0"), ] diff --git a/Sources/Shared/Shell.swift b/Sources/Shared/Shell.swift index d9e834732..6a7b7a58f 100644 --- a/Sources/Shared/Shell.swift +++ b/Sources/Shared/Shell.swift @@ -26,15 +26,9 @@ public class ShellProcessStore { } open class Shell { - private let environment: [String: String] private let logger: ContextualLogger - public convenience init(logger: Logger) { - self.init(environment: ProcessInfo.processInfo.environment, logger: logger) - } - - public required init(environment: [String: String], logger: Logger) { - self.environment = environment + public init(logger: Logger) { self.logger = logger.contextualized(with: "shell") } @@ -78,7 +72,6 @@ open class Shell { let process = Process() process.launchPath = launchPath - process.environment = environment process.arguments = newArgs logger.debug("\(launchPath) \(newArgs.joined(separator: " "))") @@ -96,8 +89,8 @@ open class Shell { process.launch() - var stdout = "" - var stderr = "" + var standardOutput = "" + var standardError = "" if let stdoutData = try stdoutPipe?.fileHandleForReading.readToEnd() { guard let stdoutStr = String(data: stdoutData, encoding: .utf8) @@ -109,7 +102,7 @@ open class Shell { encoding: .utf8 ) } - stdout = stdoutStr + standardOutput = stdoutStr } if let stderrData = try stderrPipe?.fileHandleForReading.readToEnd() { @@ -122,11 +115,15 @@ open class Shell { encoding: .utf8 ) } - stderr = stderrStr + standardError = stderrStr } - process.waitUntilExit() + // Workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/5153 + let semaphore = DispatchSemaphore(value: 0) + process.terminationHandler = { _ in semaphore.signal() } + semaphore.wait() + ShellProcessStore.shared.remove(process) - return (process.terminationStatus, stdout, stderr) + return (process.terminationStatus, standardOutput, standardError) } } diff --git a/Tests/XcodeTests/ShellMock.swift b/Tests/XcodeTests/ShellMock.swift index 8a99a60b7..c3cacb8ba 100644 --- a/Tests/XcodeTests/ShellMock.swift +++ b/Tests/XcodeTests/ShellMock.swift @@ -7,7 +7,7 @@ class ShellMock: Shell { convenience init() { let logger = Logger(quiet: true) - self.init(environment: ProcessInfo.processInfo.environment, logger: logger) + self.init(logger: logger) } override func exec(_: [String]) throws -> String { diff --git a/docker/Dockerfile.linux b/docker/Dockerfile.linux new file mode 100644 index 000000000..e1aabf2a6 --- /dev/null +++ b/docker/Dockerfile.linux @@ -0,0 +1,5 @@ +FROM swift:6.0 +WORKDIR /workspace +COPY . /workspace +RUN swift build --product periphery +ENTRYPOINT [".build/debug/periphery"]