Skip to content

Commit

Permalink
Remove the '--xcargs' option and instead capture all arguments follow…
Browse files Browse the repository at this point in the history
…ing the '--' terminator. Closes #246
  • Loading branch information
ileitch committed Dec 19, 2020
1 parent a1eab92 commit 615307c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

##### Breaking

- None.
- 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.

##### Enhancements

Expand Down
10 changes: 5 additions & 5 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public struct ScanCommand: ParsableCommand {
abstract: "Scan for unused code"
)

@Argument(help: "Arguments following '--' will be passed to the underlying build tool, which is either 'swift build' or 'xcodebuild' depending on your project")
var buildArguments: [String] = []

@Flag(help: "Enable guided setup")
var setup: Bool = false

Expand Down Expand Up @@ -36,9 +39,6 @@ public struct ScanCommand: ParsableCommand {
@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: "|"))
var reportExclude: [String] = []

@Option(help: "Pass additional arguments to xcodebuild for the build phase")
var xcargs: String?

@Option(help: "Path to index store to use. Automatically defaults to the correct store for your project")
var indexStorePath: String?

Expand Down Expand Up @@ -105,8 +105,8 @@ public struct ScanCommand: ParsableCommand {
configuration.schemes = schemes
}

if xcargs != nil {
configuration.xcargs = xcargs
if !buildArguments.isEmpty {
configuration.buildArguments = buildArguments
}

if let formatName = format {
Expand Down
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/SPM/SPM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public struct SPM {
public let sources: [String]
public let moduleType: String

func build() throws {
func build(additionalArguments: [String]) throws {
let shell: Shell = inject()
try shell.exec(["swift", "build", "--enable-test-discovery", "--target", name])
try shell.exec(["swift", "build", "--enable-test-discovery", "--target", name] + additionalArguments)
}
}
}
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/SPM/SPMProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension SPMProjectDriver: ProjectDriver {
logger.info("\(asterisk) Building \($0.name)...")
}

try $0.build()
try $0.build(additionalArguments: configuration.buildArguments)
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions Sources/Shared/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class Configuration: Singleton {
public var targets: [String] = []
public var indexExclude: [String] = []
public var reportExclude: [String] = []
public var buildArguments: [String] = []

public var retainObjcAccessible: Bool = false
public var retainPublic: Bool = false
Expand All @@ -28,7 +29,6 @@ public final class Configuration: Singleton {
public var quiet: Bool = false
public var updateCheck: Bool = true
public var strict: Bool = false
public var xcargs: String? = nil
public var indexStorePath: String?
public var skipBuild: Bool = false
public var cleanBuild: Bool = false
Expand Down Expand Up @@ -59,10 +59,10 @@ public final class Configuration: Singleton {
"quiet": quiet,
"disable_update_check": !updateCheck,
"strict": strict,
"xcargs": xcargs,
"index_store_path": indexStorePath,
"skip_build": skipBuild,
"clean_build": cleanBuild
"clean_build": cleanBuild,
"build_arguments": buildArguments
]

return try Yams.dump(object: config)
Expand Down Expand Up @@ -109,15 +109,18 @@ public final class Configuration: Singleton {
case "strict":
self.strict = convert(value, to: Bool.self) ?? false
case "xcargs":
self.xcargs = convert(value, to: String.self)
logger.warn("\(path.string): 'xcargs' is deprecated and has been superseded by 'build_arguments'")
self.buildArguments = (convert(value, to: String.self) ?? "").split(separator: " ").map { String($0) }
case "index_store_path":
self.indexStorePath = convert(value, to: String.self)
case "skip_build":
self.skipBuild = convert(value, to: Bool.self) ?? false
case "clean_build":
self.cleanBuild = convert(value, to: Bool.self) ?? false
case "build_arguments":
self.buildArguments = convert(value, to: [String].self) ?? []
default:
logger.warn("\(path.string) contains invalid key '\(key)'")
logger.warn("\(path.string): invalid key '\(key)'")
}
}
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Sources/XcodeSupport/XcodeProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extension XcodeProjectDriver: ProjectDriver {
try xcodebuild.build(project: project,
scheme: scheme,
allSchemes: Array(schemes),
additionalArguments: configuration.xcargs,
additionalArguments: configuration.buildArguments,
buildForTesting: buildForTesting)
}
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/XcodeSupport/Xcodebuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class Xcodebuild: Injectable {
}

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

var args = [
Expand All @@ -38,9 +38,7 @@ public final class Xcodebuild: Injectable {
"-quiet"
]

if let additionalArguments = additionalArguments {
args.append(additionalArguments)
}
args.append(contentsOf: additionalArguments)

let envs = [
"CODE_SIGNING_ALLOWED=\"NO\"",
Expand Down

0 comments on commit 615307c

Please sign in to comment.