Skip to content

Commit

Permalink
Add Linux docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Dec 22, 2024
1 parent fd2da1a commit 0779211
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git/
.build/
.swiftpm/
.release/
bazel-*
docker/
7 changes: 7 additions & 0 deletions .mise/tasks/scan-linux
Original file line number Diff line number Diff line change
@@ -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 "$@"
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
25 changes: 11 additions & 14 deletions Sources/Shared/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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: " "))")
Expand All @@ -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)
Expand All @@ -109,7 +102,7 @@ open class Shell {
encoding: .utf8
)
}
stdout = stdoutStr
standardOutput = stdoutStr
}

if let stderrData = try stderrPipe?.fileHandleForReading.readToEnd() {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion Tests/XcodeTests/ShellMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions docker/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM swift:6.0
WORKDIR /workspace
COPY . /workspace
RUN swift build --product periphery
ENTRYPOINT [".build/debug/periphery"]

0 comments on commit 0779211

Please sign in to comment.