-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPM danger
- Loading branch information
Showing
14 changed files
with
234 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
|
||
public struct SPMDanger { | ||
private static let dangerDepsPrefix = "DangerDeps" | ||
public static let buildFolder = ".build/debug" | ||
public let depsLibName: String | ||
|
||
public init?(packagePath: String = "Package.swift") { | ||
let packageContent = (try? String(contentsOfFile: packagePath)) ?? "" | ||
|
||
let regex = try? NSRegularExpression(pattern: "\\.library\\(name:[\\ ]?\"(\(SPMDanger.dangerDepsPrefix)[A-Za-z]*)", | ||
options: .allowCommentsAndWhitespace) | ||
let firstMatch = regex?.firstMatch(in: packageContent, | ||
options: .withTransparentBounds, | ||
range: NSRange(location: 0, length: packageContent.count)) | ||
|
||
if let depsLibNameRange = firstMatch?.range(at: 1), | ||
let range = Range(depsLibNameRange, in: packageContent) { | ||
depsLibName = String(packageContent[range]) | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
public func buildDepsIfNeeded(executor: ShellOutExecuting = ShellOutExecutor(), | ||
fileManager: FileManager = .default) { | ||
if !fileManager.fileExists(atPath: "\(SPMDanger.buildFolder)/lib\(depsLibName).dylib"), // OSX | ||
!fileManager.fileExists(atPath: "\(SPMDanger.buildFolder)/lib\(depsLibName).so") { // Linux | ||
_ = try? executor.shellOut(command: "swift build --product \(depsLibName)") | ||
} | ||
} | ||
|
||
public var libImport: String { | ||
return "-l\(depsLibName)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import RunnerLib | ||
|
||
final class MockedExecutor: ShellOutExecuting { | ||
var receivedCommand: String! | ||
var result = "" | ||
|
||
func shellOut(command: String) throws -> String { | ||
receivedCommand = command | ||
return result | ||
} | ||
} |
Oops, something went wrong.