Skip to content
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

Get the cli building on Linux (but not necessarily working) #29

Merged
merged 3 commits into from
Jun 21, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:

jobs:
build:
runs-on: macos-12
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer

steps:
- name: Checkout
Expand Down
50 changes: 34 additions & 16 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
"revision" : "36f73bea370315e7a5af1f450fa013180ba2c584"
}
},
{
"identity" : "swift-asn1",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-asn1.git",
"state" : {
"revision" : "805deae27a7506dcad043604c00a9dc52d465dcb",
"version" : "0.7.0"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
Expand All @@ -72,6 +81,15 @@
"version" : "0.8.1"
}
},
{
"identity" : "swift-certificates",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-certificates.git",
"state" : {
"revision" : "35a7df2d9d71c401a47de9be2e3de629a01370c2",
"version" : "0.4.1"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand All @@ -86,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "ddb07e896a2a8af79512543b1c7eb9797f8898a5",
"version" : "1.1.7"
"revision" : "33a20e650c33f6d72d822d558333f2085effa3dc",
"version" : "2.5.0"
}
},
{
Expand All @@ -104,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-driver.git",
"state" : {
"branch" : "release/5.7",
"revision" : "719426df790661020de657bf38beb2a8b1de5ad3"
"branch" : "release/5.9",
"revision" : "7555785f8b8f27e3f4e7aafdb6f76efe29f87b00"
}
},
{
Expand All @@ -122,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-llbuild.git",
"state" : {
"branch" : "release/5.7",
"revision" : "564424db5fdb62dcb5d863bdf7212500ef03a87b"
"branch" : "release/5.9",
"revision" : "17a88707e99dc0379eccfcf190ee2361227369fc"
}
},
{
Expand All @@ -149,8 +167,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-package-manager",
"state" : {
"branch" : "release/5.7",
"revision" : "c5da46610e82d22508532fdaa6858cc74b3bb870"
"branch" : "release/5.9",
"revision" : "49ec9c61b2c6bd74eafb72143d310b492fe184c7"
}
},
{
Expand Down Expand Up @@ -185,8 +203,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-tools-support-core.git",
"state" : {
"branch" : "release/5.7",
"revision" : "184eba382f6abbb362ffc02942d790ff35019ad4"
"branch" : "release/5.9",
"revision" : "279be8ac3fe7829cc15e93693c45931a1bf7f112"
}
},
{
Expand All @@ -203,8 +221,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/SwiftXcodeProj.git",
"state" : {
"branch" : "main",
"revision" : "b1aaf2fb0f7754bc274a5b539d5fe94a9e92fa77"
"revision" : "46e9b907e3ec66010cf2204594549ff1dc195032",
"version" : "8.10.1"
}
},
{
Expand All @@ -230,8 +248,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/XcodeGen",
"state" : {
"branch" : "renamed",
"revision" : "aafcc23bdb92dfd02444729bfdb58e340fdb6f6a"
"revision" : "adbf99beb7afb4844774d14e9275da9a503a427c",
"version" : "2.35.1"
}
},
{
Expand All @@ -248,8 +266,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
"version" : "4.0.6"
"revision" : "f47ba4838c30dbd59998a4e4c87ab620ff959e8a",
"version" : "5.0.5"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ let package = Package(
.package(url: "https://github.com/LebJe/TOMLKit", branch: "main"),
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"),
.package(url: "https://github.com/mxcl/Version.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-package-manager", branch: "release/5.7"),
.package(url: "https://github.com/apple/swift-package-manager", branch: "release/5.9"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/stackotter/XcodeGen", branch: "renamed"),
.package(url: "https://github.com/stackotter/XcodeGen", exact: "2.35.1"),
.package(url: "https://github.com/apple/swift-syntax", exact: "0.50800.0-SNAPSHOT-2022-12-29-a"),
.package(url: "https://github.com/apple/swift-format", exact: "0.50800.0-SNAPSHOT-2022-12-29-a"),
.package(url: "https://github.com/pointfreeco/swift-overture", from: "0.5.0"),
Expand Down
3 changes: 3 additions & 0 deletions Sources/swift-bundler/Bundler/Runner/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ enum Runner {
arguments: [String],
environmentVariables: [String: String]
) -> Result<Void, RunnerError> {
// `ios-deploy` is explicitly resolved (instead of allowing `Process.create`
// to handle running programs located on the user's PATH) so that a detailed
// error message can be emitted for this easy misconfiguration issue.
return Process.locate("ios-deploy").mapError { error in
return .failedToLocateIOSDeploy(error)
}.flatMap { iosDeployExecutable in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import struct Basics.Diagnostic
/// A utility for interacting with the Swift package manager and performing some other package
/// related operations.
enum SwiftPackageManager {
/// The path to the swift executable.
static let swiftExecutable = "/usr/bin/swift"

/// Creates a new package using the given directory as the package's root directory.
/// - Parameters:
/// - directory: The package's root directory (will be created if it doesn't exist).
Expand Down Expand Up @@ -45,15 +42,15 @@ enum SwiftPackageManager {
]

let process = Process.create(
Self.swiftExecutable,
"swift",
arguments: arguments,
directory: directory)
process.setOutputPipe(Pipe())

return process.runAndWait()
.mapError { error in
.failedToRunSwiftInit(
command: "\(Self.swiftExecutable) \(arguments.joined(separator: " "))",
command: "swift \(arguments.joined(separator: " "))",
error
)
}
Expand Down Expand Up @@ -103,15 +100,15 @@ enum SwiftPackageManager {
platformVersion: platformVersion
).flatMap { arguments in
let process = Process.create(
swiftExecutable,
"swift",
arguments: arguments,
directory: packageDirectory,
runSilentlyWhenNotVerbose: false
)

return process.runAndWait().mapError { error in
return .failedToRunSwiftBuild(
command: "\(swiftExecutable) \(arguments.joined(separator: " "))",
command: "swift \(arguments.joined(separator: " "))",
error
)
}
Expand Down Expand Up @@ -215,28 +212,51 @@ enum SwiftPackageManager {
/// - Returns: The swift version, or a failure if an error occurs.
static func getSwiftVersion() -> Result<Version, SwiftPackageManagerError> {
let process = Process.create(
swiftExecutable,
"swift",
arguments: ["--version"])

return process.getOutput()
.mapError { error in
.failedToGetSwiftVersion(error)
}
.flatMap { output in
// The first two examples are for release versions of Swift (the first on macOS, the second on Linux).
// The next two examples are for snapshot versions of Swift (the first on macOS, the second on Linux).
// Sample: "swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)"
let parser = Parse {
Prefix { $0 != "(" }
"(swiftlang-"
Parse({ Version(major: $0, minor: $1, patch: $2) }) {
Int.parser(of: Substring.self, radix: 10)
"."
Int.parser(of: Substring.self, radix: 10)
"."
Int.parser(of: Substring.self, radix: 10)
// OR: "swift-driver version: 1.45.2 Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)"
// OR: "Apple Swift version 5.9-dev (LLVM 464b04eb9b157e3, Swift 7203d52cb1e074d)"
// OR: "Swift version 5.9-dev (LLVM 464b04eb9b157e3, Swift 7203d52cb1e074d)"
let parser = OneOf {
Parse {
"swift-driver version"
Prefix { $0 != "(" }
"(swiftlang-"
Parse({ Version(major: $0, minor: $1, patch: $2) }) {
Int.parser(of: Substring.self, radix: 10)
"."
Int.parser(of: Substring.self, radix: 10)
"."
Int.parser(of: Substring.self, radix: 10)
}
Rest<Substring>()
}.map { (_: Substring, version: Version, _: Substring) in
version
}

Parse {
Optionally {
"Apple "
}
"Swift version "
Parse({ Version(major: $0, minor: $1, patch: 0) }) {
Int.parser(of: Substring.self, radix: 10)
"."
Int.parser(of: Substring.self, radix: 10)
}
Rest<Substring>()
}.map { (_: Void?, version: Version, _: Substring) in
version
}
Rest<Substring>()
}.map { (_: Substring, version: Version, _: Substring) in
version
}

do {
Expand Down Expand Up @@ -272,7 +292,7 @@ enum SwiftPackageManager {
platformVersion: platformVersion
).flatMap { arguments in
let process = Process.create(
"/usr/bin/swift",
"swift",
arguments: arguments + ["--show-bin-path"],
directory: packageDirectory
)
Expand All @@ -281,7 +301,7 @@ enum SwiftPackageManager {
let path = output.trimmingCharacters(in: .newlines)
return .success(URL(fileURLWithPath: path))
}.mapError { error in
let command = "/usr/bin/swift " + arguments.joined(separator: " ")
let command = "swift " + arguments.joined(separator: " ")
return .failedToGetProductsDirectory(command: command, error)
}
}
Expand All @@ -293,12 +313,12 @@ enum SwiftPackageManager {
static func loadPackageManifest(
from packageDirectory: URL
) async -> Result<Manifest, SwiftPackageManagerError> {
var diagnostics: [Basics.Diagnostic] = []
let diagnostics: Box<[Basics.Diagnostic]> = Box([])
let result: Result<Manifest, Error>
do {
let packagePath = try AbsolutePath(validating: packageDirectory.path)
let scope = ObservabilitySystem({ _, diagnostic in
diagnostics.append(diagnostic)
diagnostics.wrapped.append(diagnostic)
}).topScope

let workspace = try Workspace(forRootPackage: packagePath)
Expand All @@ -325,7 +345,7 @@ enum SwiftPackageManager {
}

return result.mapError { error in
return .failedToLoadPackageManifest(directory: packageDirectory, diagnostics, error)
return .failedToLoadPackageManifest(directory: packageDirectory, diagnostics.wrapped, error)
}
}
}
8 changes: 4 additions & 4 deletions Sources/swift-bundler/Bundler/Templater/Templater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ enum Templater {
.flatMap { templatesDirectory in
if FileManager.default.itemExists(at: templatesDirectory, withType: .directory) {
let result = Process.create(
"/usr/bin/git",
"git",
arguments: [
"fetch"
],
directory: templatesDirectory
).runAndWait().flatMap { _ in
return Process.create(
"/usr/bin/git",
"git",
arguments: [
"checkout", "v\(SwiftBundler.version.major)"
],
directory: templatesDirectory
).runAndWait()
}.flatMap { _ in
return Process.create(
"/usr/bin/git",
"git",
arguments: ["pull"],
directory: templatesDirectory
).runAndWait()
Expand Down Expand Up @@ -339,7 +339,7 @@ enum Templater {

// Clone the templates repository
let process = Process.create(
"/usr/bin/git",
"git",
arguments: [
"clone", "-b", "v\(SwiftBundler.version.major)",
"\(defaultTemplateRepository)",
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-bundler/Bundler/VariableEvaluator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ enum VariableEvaluator {

// TODO: Consider using git library
let result = Process.create(
"/usr/bin/git",
"git",
arguments: ["rev-parse", "HEAD"],
directory: packageDirectory
).getOutput()
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-bundler/Bundler/VariableEvaluatorError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum VariableEvaluatorError: LocalizedError {
return "Found unknown variable '\(variable)'"
case .failedToEvaluateCommitHash(let directory):
return "Failed to evaluate the 'COMMIT_HASH' variable. Ensure that '\(directory.relativePath)' is a git repository and"
+ " that git is installed at '/usr/bin/git'."
+ " that git is installed and on your PATH."
case .customEvaluatorFailedToEvaluateVariable(let variable, _):
return "Custom evaluator failed to evaluate variable '\(variable)'"
case .packageDirectoryRequiredToEvaluateCommitHash:
Expand Down
Loading