Skip to content

Commit

Permalink
feat: Add mise support
Browse files Browse the repository at this point in the history
  • Loading branch information
msnazarow committed Dec 9, 2024
1 parent 808ad84 commit d007386
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Sources/Runner/Commands/Edit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func editDanger(version dangerSwiftVersion: String, logger: Logger) throws {
absoluteLibPath = spmDanger.buildFolder
libsImport = spmDanger.xcodeImportFlags
} else {
guard let libPath = Runtime.getLibDangerPath() else {
let potentialFolders = Runtime.potentialLibraryFolders
guard let libPath = Runtime.getLibDangerPath(forDangerSwiftVersion: dangerSwiftVersion) else {
let potentialFolders = Runtime.potentialLibraryFolders(forDangerSwiftVersion: dangerSwiftVersion)
logger.logError("Could not find a libDanger to link against at any of: \(potentialFolders)",
"Or via Homebrew, or Marathon",
"Or via Homebrew, or Marathon, or Mise",
separator: "\n")
exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Runner/Commands/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func runDanger(version dangerSwiftVersion: String, logger: Logger) throws {
libArgs += ["-I", spmDanger.moduleFolder]
libArgs += [spmDanger.swiftcLibImport]
} else {
guard let libDangerPath = Runtime.getLibDangerPath() else {
let potentialFolders = Runtime.potentialLibraryFolders
guard let libDangerPath = Runtime.getLibDangerPath(forDangerSwiftVersion: dangerSwiftVersion) else {
let potentialFolders = Runtime.potentialLibraryFolders(forDangerSwiftVersion: dangerSwiftVersion)
logger.logError("Could not find a libDanger to link against at any of: \(potentialFolders)",
"Or via Homebrew, or Marathon",
separator: "\n")
Expand Down
20 changes: 11 additions & 9 deletions Sources/RunnerLib/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ public enum Runtime {
}

/// Is this a dev build: e.g. running inside a cloned danger/danger-swift
public static let potentialLibraryFolders = [
".build/debug", // Working in Xcode / CLI
".build/x86_64-unknown-linux/debug", // Danger Swift's CI
".build/release", // Testing prod
"/usr/local/lib/danger", // Intel Homebrew installs lib stuff to here
"/opt/homebrew/lib/danger", // Apple Silicon Homebrew installs lib stuff to here
]
public static func potentialLibraryFolders(forDangerSwiftVersion version: String) -> [String] { [
".build/debug", // Working in Xcode / CLI
".build/x86_64-unknown-linux/debug", // Danger Swift's CI
".build/release", // Testing prod
"/usr/local/lib/danger", // Intel Homebrew installs lib stuff to here
"/opt/homebrew/lib/danger", // Apple Silicon Homebrew installs lib stuff to here
NSHomeDirectory() + "/.local/share/mise/installs/danger-swift/\(version)/lib/danger"
]
}

/// Finds a path to add at runtime to the compiler, which links
/// to the library Danger
public static func getLibDangerPath() -> String? {
public static func getLibDangerPath(forDangerSwiftVersion version: String) -> String? {
let fileManager = FileManager.default

// Was danger-swift installed via marathon?
Expand All @@ -49,7 +51,7 @@ public enum Runtime {
} ?? []

// Check and find where we can link to libDanger from
let libPaths = commandArgPath + potentialLibraryFolders + depManagerDangerLibPaths
let libPaths = commandArgPath + potentialLibraryFolders(forDangerSwiftVersion: version) + depManagerDangerLibPaths

func isTheDangerLibPath(path: String) -> Bool {
fileManager.fileExists(atPath: path + "/libDanger.dylib") || // OSX
Expand Down

0 comments on commit d007386

Please sign in to comment.