Skip to content

Don’t use workingDirectory when creating a SwiftPMDependencyProject #1215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
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
26 changes: 12 additions & 14 deletions Sources/SKTestSupport/SwiftPMDependencyProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ public class SwiftPMDependencyProject {
/// The directory in which the repository lives.
public let packageDirectory: URL

private func runCommand(_ toolName: String, _ arguments: [String], workingDirectory: URL) async throws {
private func runGitCommand(_ arguments: [String], workingDirectory: URL) async throws {
enum Error: Swift.Error {
case cannotFindTool(toolName: String)
case cannotFindGit
case processedTerminatedWithNonZeroExitCode(ProcessResult)
}
guard let toolUrl = findTool(name: toolName) else {
guard let toolUrl = findTool(name: "git") else {
if ProcessEnv.block["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Never skip the test in CI, similar to what SkipUnless does.
throw XCTSkip("\(toolName) cannot be found")
throw XCTSkip("git cannot be found")
}
throw Error.cannotFindTool(toolName: toolName)
throw Error.cannotFindGit
}
print([toolUrl.path] + arguments)
// We can't use `workingDirectory` because Amazon Linux doesn't support working directories (or at least
// TSCBasic.Process doesn't support working directories on Amazon Linux)
let process = TSCBasic.Process(
arguments: [toolUrl.path] + arguments,
workingDirectory: try AbsolutePath(validating: workingDirectory.path)
arguments: [toolUrl.path, "-C", workingDirectory.path] + arguments
)
try process.launch()
let processResult = try await process.waitUntilExit()
Expand Down Expand Up @@ -80,18 +80,16 @@ public class SwiftPMDependencyProject {
try contents.write(to: fileURL, atomically: true, encoding: .utf8)
}

try await runCommand("git", ["init"], workingDirectory: packageDirectory)
try await runCommand(
"git",
try await runGitCommand(["init"], workingDirectory: packageDirectory)
try await runGitCommand(
["add"] + files.keys.map { $0.url(relativeTo: packageDirectory).path },
workingDirectory: packageDirectory
)
try await runCommand(
"git",
try await runGitCommand(
["-c", "user.name=Dummy", "-c", "[email protected]", "commit", "-m", "Initial commit"],
workingDirectory: packageDirectory
)
try await runCommand("git", ["tag", "1.0.0"], workingDirectory: packageDirectory)
try await runGitCommand(["tag", "1.0.0"], workingDirectory: packageDirectory)
}

deinit {
Expand Down