Skip to content

Commit 615307c

Browse files
committed
Remove the '--xcargs' option and instead capture all arguments following the '--' terminator. Closes #246
1 parent a1eab92 commit 615307c

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
##### Breaking
44

5-
- None.
5+
- The `--xcargs` option has been removed, and superseded by passing arguments following the `--` terminator. E.g `periphery scan --xcargs --foo` is now `periphery scan -- --foo`. This feature can also be used to pass arguments to `swift build` for SwiftPM projects.
66

77
##### Enhancements
88

Sources/Frontend/Commands/ScanCommand.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public struct ScanCommand: ParsableCommand {
99
abstract: "Scan for unused code"
1010
)
1111

12+
@Argument(help: "Arguments following '--' will be passed to the underlying build tool, which is either 'swift build' or 'xcodebuild' depending on your project")
13+
var buildArguments: [String] = []
14+
1215
@Flag(help: "Enable guided setup")
1316
var setup: Bool = false
1417

@@ -36,9 +39,6 @@ public struct ScanCommand: ParsableCommand {
3639
@Option(help: "Path glob of source files which should be excluded from the results. Note that this option is purely cosmetic, these files will still be indexed. Multiple globs may be delimited by a pipe", transform: split(by: "|"))
3740
var reportExclude: [String] = []
3841

39-
@Option(help: "Pass additional arguments to xcodebuild for the build phase")
40-
var xcargs: String?
41-
4242
@Option(help: "Path to index store to use. Automatically defaults to the correct store for your project")
4343
var indexStorePath: String?
4444

@@ -105,8 +105,8 @@ public struct ScanCommand: ParsableCommand {
105105
configuration.schemes = schemes
106106
}
107107

108-
if xcargs != nil {
109-
configuration.xcargs = xcargs
108+
if !buildArguments.isEmpty {
109+
configuration.buildArguments = buildArguments
110110
}
111111

112112
if let formatName = format {

Sources/PeripheryKit/SPM/SPM.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public struct SPM {
3636
public let sources: [String]
3737
public let moduleType: String
3838

39-
func build() throws {
39+
func build(additionalArguments: [String]) throws {
4040
let shell: Shell = inject()
41-
try shell.exec(["swift", "build", "--enable-test-discovery", "--target", name])
41+
try shell.exec(["swift", "build", "--enable-test-discovery", "--target", name] + additionalArguments)
4242
}
4343
}
4444
}

Sources/PeripheryKit/SPM/SPMProjectDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension SPMProjectDriver: ProjectDriver {
5151
logger.info("\(asterisk) Building \($0.name)...")
5252
}
5353

54-
try $0.build()
54+
try $0.build(additionalArguments: configuration.buildArguments)
5555
}
5656
}
5757
}

Sources/Shared/Configuration.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class Configuration: Singleton {
1919
public var targets: [String] = []
2020
public var indexExclude: [String] = []
2121
public var reportExclude: [String] = []
22+
public var buildArguments: [String] = []
2223

2324
public var retainObjcAccessible: Bool = false
2425
public var retainPublic: Bool = false
@@ -28,7 +29,6 @@ public final class Configuration: Singleton {
2829
public var quiet: Bool = false
2930
public var updateCheck: Bool = true
3031
public var strict: Bool = false
31-
public var xcargs: String? = nil
3232
public var indexStorePath: String?
3333
public var skipBuild: Bool = false
3434
public var cleanBuild: Bool = false
@@ -59,10 +59,10 @@ public final class Configuration: Singleton {
5959
"quiet": quiet,
6060
"disable_update_check": !updateCheck,
6161
"strict": strict,
62-
"xcargs": xcargs,
6362
"index_store_path": indexStorePath,
6463
"skip_build": skipBuild,
65-
"clean_build": cleanBuild
64+
"clean_build": cleanBuild,
65+
"build_arguments": buildArguments
6666
]
6767

6868
return try Yams.dump(object: config)
@@ -109,15 +109,18 @@ public final class Configuration: Singleton {
109109
case "strict":
110110
self.strict = convert(value, to: Bool.self) ?? false
111111
case "xcargs":
112-
self.xcargs = convert(value, to: String.self)
112+
logger.warn("\(path.string): 'xcargs' is deprecated and has been superseded by 'build_arguments'")
113+
self.buildArguments = (convert(value, to: String.self) ?? "").split(separator: " ").map { String($0) }
113114
case "index_store_path":
114115
self.indexStorePath = convert(value, to: String.self)
115116
case "skip_build":
116117
self.skipBuild = convert(value, to: Bool.self) ?? false
117118
case "clean_build":
118119
self.cleanBuild = convert(value, to: Bool.self) ?? false
120+
case "build_arguments":
121+
self.buildArguments = convert(value, to: [String].self) ?? []
119122
default:
120-
logger.warn("\(path.string) contains invalid key '\(key)'")
123+
logger.warn("\(path.string): invalid key '\(key)'")
121124
}
122125
}
123126
}
File renamed without changes.

Sources/XcodeSupport/XcodeProjectDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ extension XcodeProjectDriver: ProjectDriver {
120120
try xcodebuild.build(project: project,
121121
scheme: scheme,
122122
allSchemes: Array(schemes),
123-
additionalArguments: configuration.xcargs,
123+
additionalArguments: configuration.buildArguments,
124124
buildForTesting: buildForTesting)
125125
}
126126
}

Sources/XcodeSupport/Xcodebuild.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class Xcodebuild: Injectable {
2727
}
2828

2929
@discardableResult
30-
func build(project: XcodeProjectlike, scheme: XcodeScheme, allSchemes: [XcodeScheme], additionalArguments: String? = nil, buildForTesting: Bool = false) throws -> String {
30+
func build(project: XcodeProjectlike, scheme: XcodeScheme, allSchemes: [XcodeScheme], additionalArguments: [String] = [], buildForTesting: Bool = false) throws -> String {
3131
let cmd = buildForTesting ? "build-for-testing" : "build"
3232

3333
var args = [
@@ -38,9 +38,7 @@ public final class Xcodebuild: Injectable {
3838
"-quiet"
3939
]
4040

41-
if let additionalArguments = additionalArguments {
42-
args.append(additionalArguments)
43-
}
41+
args.append(contentsOf: additionalArguments)
4442

4543
let envs = [
4644
"CODE_SIGNING_ALLOWED=\"NO\"",

0 commit comments

Comments
 (0)