Skip to content

Commit

Permalink
Added ability to skip schemes validation for Xcode projects (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
rock88 authored May 20, 2024
1 parent 76e45c6 commit 7386710
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ struct ScanCommand: FrontendCommand {
@Flag(help: "Skip the project build step")
var skipBuild: Bool = defaultConfiguration.$skipBuild.defaultValue

@Flag(help: "Skip schemes validation")
var skipSchemesValidation: Bool = defaultConfiguration.$skipSchemesValidation.defaultValue

@Flag(help: "Output result paths relative to the current directory")
var relativeResults: Bool = defaultConfiguration.$relativeResults.defaultValue

Expand Down Expand Up @@ -164,6 +167,7 @@ struct ScanCommand: FrontendCommand {
configuration.apply(\.$strict, strict)
configuration.apply(\.$indexStorePath, indexStorePath)
configuration.apply(\.$skipBuild, skipBuild)
configuration.apply(\.$skipSchemesValidation, skipSchemesValidation)
configuration.apply(\.$cleanBuild, cleanBuild)
configuration.apply(\.$buildArguments, buildArguments)
configuration.apply(\.$relativeResults, relativeResults)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Shared/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public final class Configuration {
@Setting(key: "skip_build", defaultValue: false)
public var skipBuild: Bool

@Setting(key: "skip_schemes_validation", defaultValue: false)
public var skipSchemesValidation: Bool

@Setting(key: "clean_build", defaultValue: false)
public var cleanBuild: Bool

Expand Down Expand Up @@ -245,6 +248,10 @@ public final class Configuration {
config[$skipBuild.key] = skipBuild
}

if $skipSchemesValidation.hasNonDefaultValue {
config[$skipSchemesValidation.key] = skipSchemesValidation
}

if $cleanBuild.hasNonDefaultValue {
config[$cleanBuild.key] = cleanBuild
}
Expand Down Expand Up @@ -350,6 +357,8 @@ public final class Configuration {
$indexStorePath.assign(value)
case $skipBuild.key:
$skipBuild.assign(value)
case $skipSchemesValidation.key:
$skipSchemesValidation.assign(value)
case $cleanBuild.key:
$cleanBuild.assign(value)
case $buildArguments.key:
Expand Down Expand Up @@ -400,6 +409,7 @@ public final class Configuration {
$strict.reset()
$indexStorePath.reset()
$skipBuild.reset()
$skipSchemesValidation.reset()
$cleanBuild.reset()
$buildArguments.reset()
$xcodeListArguments.reset()
Expand Down
22 changes: 14 additions & 8 deletions Sources/XcodeSupport/XcodeProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ public final class XcodeProjectDriver {
throw PeripheryError.invalidTargets(names: invalidTargetNames.sorted(), project: project.path.lastComponent?.string ?? "")
}

// Ensure schemes exist within the project
let schemes = try project.schemes(
additionalArguments: configuration.xcodeListArguments
).filter { configuration.schemes.contains($0) }
let validSchemeNames = schemes.mapSet { $0 }

if let scheme = Set(configuration.schemes).subtracting(validSchemeNames).first {
throw PeripheryError.invalidScheme(name: scheme, project: project.path.lastComponent?.string ?? "")
let schemes: Set<String>

if configuration.skipSchemesValidation {
schemes = Set(configuration.schemes)
} else {
// Ensure schemes exist within the project
schemes = try project.schemes(
additionalArguments: configuration.xcodeListArguments
).filter { configuration.schemes.contains($0) }
let validSchemeNames = schemes.mapSet { $0 }

if let scheme = Set(configuration.schemes).subtracting(validSchemeNames).first {
throw PeripheryError.invalidScheme(name: scheme, project: project.path.lastComponent?.string ?? "")
}
}

return self.init(
Expand Down

0 comments on commit 7386710

Please sign in to comment.