diff --git a/CHANGELOG.md b/CHANGELOG.md index 76f425b61..de0d648b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Unused import detection is now enabled by default. - Added the `--retain-encodable-properties` option to retain all properties on `Encodable` types only. +- Added the `--xcode-list-arguments` option to pass additional arguments to `xcodebuild -list`. ##### Bug Fixes diff --git a/Sources/Shared/Configuration.swift b/Sources/Shared/Configuration.swift index 5f68ac702..30543f1da 100644 --- a/Sources/Shared/Configuration.swift +++ b/Sources/Shared/Configuration.swift @@ -41,8 +41,8 @@ public final class Configuration { @Setting(key: "build_arguments", defaultValue: []) public var buildArguments: [String] - @Setting(key: "schemes_arguments", defaultValue: []) - public var schemesArguments: [String] + @Setting(key: "xcode_list_arguments", defaultValue: []) + public var xcodeListArguments: [String] @Setting(key: "retain_assign_only_property_types", defaultValue: [], valueSanitizer: PropertyTypeSanitizer.sanitize) public var retainAssignOnlyPropertyTypes: [String] @@ -253,6 +253,10 @@ public final class Configuration { config[$buildArguments.key] = buildArguments } + if $xcodeListArguments.hasNonDefaultValue { + config[$xcodeListArguments.key] = xcodeListArguments + } + if $relativeResults.hasNonDefaultValue { config[$relativeResults.key] = relativeResults } @@ -350,8 +354,8 @@ public final class Configuration { $cleanBuild.assign(value) case $buildArguments.key: $buildArguments.assign(value) - case $schemesArguments.key: - $schemesArguments.assign(value) + case $xcodeListArguments.key: + $xcodeListArguments.assign(value) case $relativeResults.key: $relativeResults.assign(value) case $retainCodableProperties.key: @@ -398,6 +402,7 @@ public final class Configuration { $skipBuild.reset() $cleanBuild.reset() $buildArguments.reset() + $xcodeListArguments.reset() $relativeResults.reset() $retainCodableProperties.reset() $retainEncodableProperties.reset() diff --git a/Sources/XcodeSupport/XcodeProjectDriver.swift b/Sources/XcodeSupport/XcodeProjectDriver.swift index 67a06b447..bb0245da0 100644 --- a/Sources/XcodeSupport/XcodeProjectDriver.swift +++ b/Sources/XcodeSupport/XcodeProjectDriver.swift @@ -48,7 +48,7 @@ public final class XcodeProjectDriver { // Ensure schemes exist within the project let schemes = try project.schemes( - additionalArguments: configuration.schemesArguments + additionalArguments: configuration.xcodeListArguments ).filter { configuration.schemes.contains($0) } let validSchemeNames = schemes.mapSet { $0 } diff --git a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift index b3ec0b134..eb7c46679 100644 --- a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift +++ b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift @@ -44,7 +44,7 @@ public final class XcodeProjectSetupGuide: SetupGuideHelpers, ProjectSetupGuide configuration.targets = select(multiple: targets, allowAll: true).selectedValues let schemes = try filter( - project.schemes(additionalArguments: configuration.schemesArguments), + project.schemes(additionalArguments: configuration.xcodeListArguments), project ).map { $0 }.sorted() @@ -88,7 +88,7 @@ public final class XcodeProjectSetupGuide: SetupGuideHelpers, ProjectSetupGuide return try xcodebuild.schemes( type: "project", path: path.lexicallyNormalized().string, - additionalArguments: configuration.schemesArguments + additionalArguments: configuration.xcodeListArguments ) } diff --git a/Sources/XcodeSupport/Xcodebuild.swift b/Sources/XcodeSupport/Xcodebuild.swift index 8e72b96fc..8c344afee 100644 --- a/Sources/XcodeSupport/Xcodebuild.swift +++ b/Sources/XcodeSupport/Xcodebuild.swift @@ -39,20 +39,7 @@ public final class Xcodebuild { "INDEX_ENABLE_DATA_STORE=\"YES\"" ] - // Apply quotes to additional option values is needed. - var quotedArguments = additionalArguments - - for (i, arg) in additionalArguments.enumerated() { - if arg.hasPrefix("-"), - let value = additionalArguments[safe: i + 1], - !value.hasPrefix("-"), - !value.hasPrefix("\""), - !value.hasPrefix("\'") - { - quotedArguments[i + 1] = "\"\(value)\"" - } - } - + let quotedArguments = quote(arguments: additionalArguments) let xcodebuild = "xcodebuild \((args + [cmd] + envs + quotedArguments).joined(separator: " "))" return try shell.exec(["/bin/sh", "-c", xcodebuild]) } @@ -86,19 +73,7 @@ public final class Xcodebuild { "-json" ] - var quotedArguments = additionalArguments - - for (i, arg) in additionalArguments.enumerated() { - if arg.hasPrefix("-"), - let value = additionalArguments[safe: i + 1], - !value.hasPrefix("-"), - !value.hasPrefix("\""), - !value.hasPrefix("\'") - { - quotedArguments[i + 1] = "\"\(value)\"" - } - } - + let quotedArguments = quote(arguments: additionalArguments) let xcodebuild = "xcodebuild \((args + quotedArguments).joined(separator: " "))" let lines = try shell.exec(["/bin/sh", "-c", xcodebuild], stderr: false).split(separator: "\n").map { String($0).trimmed } @@ -143,4 +118,21 @@ public final class Xcodebuild { return try Constants.cachePath().appending("DerivedData-\(xcodeVersionHash)-\(projectHash)-\(schemesHash)") } + + private func quote(arguments: [String]) -> [String] { + var quotedArguments = arguments + + for (i, arg) in arguments.enumerated() { + if arg.hasPrefix("-"), + let value = arguments[safe: i + 1], + !value.hasPrefix("-"), + !value.hasPrefix("\""), + !value.hasPrefix("\'") + { + quotedArguments[i + 1] = "\"\(value)\"" + } + } + + return quotedArguments + } }