Skip to content

Commit

Permalink
Merge remote-tracking branch 'isShownConfig/hide_scheme'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaelzs committed Jun 16, 2022
2 parents f65dad7 + 0a25f25 commit b7a95fc
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ This is a convenience used to automatically generate schemes for a target based
- [ ] **testPlans**: **[[Test Plan](#test-plan)]** - List of test plan locations that will be referenced in the scheme.
- [ ] **preActions**: **[[Execution Action](#execution-action)]** - Scripts that are run *before* the build action
- [ ] **postActions**: **[[Execution Action](#execution-action)]** - Scripts that are run *after* the build action
- [ ] **shared**: **Bool** - indicates whether the scheme is shared. This defaults to true
- [ ] **orderHint**: **Int** - used by Xcode to sort the schemes
- [ ] **isShown**: **Bool** ** - indicates whether the sheme is shown in the scheme list
- [ ] **storeKitConfiguration**: **String** - specify storekit configuration to use during run. See [Options](#options).

For example, the spec below would create 3 schemes called:
Expand Down Expand Up @@ -760,6 +763,7 @@ Schemes allows for more control than the convenience [Target Scheme](#target-sch
- [ ] ***profile***: The profile action
- [ ] ***analyze***: The analyze action
- [ ] ***archive***: The archive action
- [ ] ***management***: **[Scheme Management](#scheme-management)]** - Scheme management metadata

### Build

Expand Down Expand Up @@ -893,6 +897,10 @@ targets:

Note that the path the gpx file will be prefixed according to the `schemePathPrefix` option in order to support both `.xcodeproj` and `.xcworkspace` setups. See [Options](#options).

### Scheme Management
- [x] **shared**: **Bool** - indicates whether the scheme is shared
- [x] **orderHint**: **Int** - used by Xcode to sort the schemes
- [x] **isShown**: **Bool** - indicates whether the sheme is shown in the scheme list

### Environment Variable

Expand Down
54 changes: 53 additions & 1 deletion Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct Scheme: Equatable {
public var analyze: Analyze?
public var test: Test?
public var profile: Profile?
public var management: Management?

public init(
name: String,
Expand All @@ -22,7 +23,8 @@ public struct Scheme: Equatable {
test: Test? = nil,
profile: Profile? = nil,
analyze: Analyze? = nil,
archive: Archive? = nil
archive: Archive? = nil,
management: Management? = nil
) {
self.name = name
self.build = build
Expand All @@ -31,6 +33,25 @@ public struct Scheme: Equatable {
self.profile = profile
self.analyze = analyze
self.archive = archive
self.management = management
}

public struct Management: Equatable {
public static let sharedDefault = true

public var shared: Bool
public var orderHint: Int?
public var isShown: Bool?

public init(
shared: Bool = true,
orderHint: Int?,
isShown: Bool?
) {
self.shared = shared
self.orderHint = orderHint
self.isShown = isShown
}
}

public struct SimulateLocation: Equatable {
Expand Down Expand Up @@ -400,6 +421,35 @@ extension Scheme.SimulateLocation: JSONEncodable {
}
}

extension Scheme.Management: JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
shared = jsonDictionary.json(atKeyPath: "shared") ?? Scheme.Management.sharedDefault
orderHint = jsonDictionary.json(atKeyPath: "orderHint")
isShown = jsonDictionary.json(atKeyPath: "isShown")
}
}

extension Scheme.Management: JSONEncodable {
public func toJSONValue() -> Any {
var dict: [String: Any?] = [:]

if shared != Scheme.Management.sharedDefault {
dict["shared"] = isShown
}

if let isShown = isShown {
dict["isShown"] = isShown
}

if let orderHint = orderHint {
dict["orderHint"] = orderHint
}

return dict
}
}

extension Scheme.Run: JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
Expand Down Expand Up @@ -706,6 +756,7 @@ extension Scheme: NamedJSONDictionaryConvertible {
analyze = jsonDictionary.json(atKeyPath: "analyze")
profile = jsonDictionary.json(atKeyPath: "profile")
archive = jsonDictionary.json(atKeyPath: "archive")
management = jsonDictionary.json(atKeyPath: "management")
}
}

Expand All @@ -718,6 +769,7 @@ extension Scheme: JSONEncodable {
"analyze": analyze?.toJSONValue(),
"profile": profile?.toJSONValue(),
"archive": archive?.toJSONValue(),
"management": management?.toJSONValue(),
] as [String: Any?]
}
}
Expand Down
36 changes: 35 additions & 1 deletion Sources/ProjectSpec/TargetScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct TargetScheme: Equatable {
public static let disableMainThreadCheckerDefault = false
public static let stopOnEveryMainThreadCheckerIssueDefault = false
public static let buildImplicitDependenciesDefault = true
public static let sharedDefault = true

public var testTargets: [Scheme.Test.TestTarget]
public var configVariants: [String]
Expand All @@ -23,6 +24,9 @@ public struct TargetScheme: Equatable {
public var preActions: [Scheme.ExecutionAction]
public var postActions: [Scheme.ExecutionAction]
public var testPlans: [TestPlan]
public var shared: Bool
public var orderHint: Int?
public var isShown: Bool?

public init(
testTargets: [Scheme.Test.TestTarget] = [],
Expand All @@ -39,7 +43,10 @@ public struct TargetScheme: Equatable {
commandLineArguments: [String: Bool] = [:],
environmentVariables: [XCScheme.EnvironmentVariable] = [],
preActions: [Scheme.ExecutionAction] = [],
postActions: [Scheme.ExecutionAction] = []
postActions: [Scheme.ExecutionAction] = [],
shared: Bool = sharedDefault,
orderHint: Int? = nil,
isShown: Bool? = nil
) {
self.testTargets = testTargets
self.testPlans = testPlans
Expand All @@ -51,11 +58,23 @@ public struct TargetScheme: Equatable {
self.region = region
self.disableMainThreadChecker = disableMainThreadChecker
self.stopOnEveryMainThreadCheckerIssue = stopOnEveryMainThreadCheckerIssue
self.isShown = isShown
self.buildImplicitDependencies = buildImplicitDependencies
self.commandLineArguments = commandLineArguments
self.environmentVariables = environmentVariables
self.preActions = preActions
self.postActions = postActions
self.shared = shared
self.orderHint = orderHint
self.postActions = postActions
}

public var management: Scheme.Management? {
guard shared != TargetScheme.sharedDefault || orderHint != nil || isShown != nil else {
return nil
}

return Scheme.Management(shared: shared,orderHint: orderHint,isShown: isShown)
}
}

Expand Down Expand Up @@ -105,6 +124,9 @@ extension TargetScheme: JSONObjectConvertible {
environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary)
preActions = jsonDictionary.json(atKeyPath: "preActions") ?? []
postActions = jsonDictionary.json(atKeyPath: "postActions") ?? []
shared = jsonDictionary.json(atKeyPath: "shared") ?? TargetScheme.sharedDefault
orderHint = jsonDictionary.json(atKeyPath: "orderHint")
isShown = jsonDictionary.json(atKeyPath: "isShown")
}
}

Expand Down Expand Up @@ -149,6 +171,18 @@ extension TargetScheme: JSONEncodable {
dict["region"] = region
}

if shared != TargetScheme.sharedDefault {
dict["shared"] = shared
}

if let orderHint = orderHint {
dict["orderHint"] = orderHint
}

if let isShown = isShown {
dict["isShown"] = isShown
}

return dict
}
}
Expand Down
19 changes: 19 additions & 0 deletions Sources/XcodeGenCLI/Commands/GenerateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ class GenerateCommand: ProjectCommand {
do {
let projectGenerator = ProjectGenerator(project: project)
xcodeProject = try projectGenerator.generateXcodeProject(in: projectDirectory)

} catch {
throw GenerationError.generationError(error)
}

info("⚙️ Generating userdata...")
do {
guard let userName = ProcessInfo.processInfo.environment["LOGNAME"] else {
throw GenerationError.missingUsername
}

let schemeManagement = ProjectGenerator(project: project).generateSchemeManagement()
// create directory
let schemeManagementDirectory = projectPath + "xcuserdata/\(userName).xcuserdatad/xcschemes"
if !schemeManagementDirectory.exists {
try schemeManagementDirectory.mkpath()
}

try schemeManagement.write(path: schemeManagementDirectory + "xcschememanagement.plist")
} catch {
throw GenerationError.generationError(error)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/XcodeGenCLI/GenerationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum GenerationError: Error, CustomStringConvertible, ProcessError {
case cacheGenerationError(Error)
case validationError(SpecValidationError)
case generationError(Error)
case missingUsername
case writingError(Error)

var description: String {
Expand All @@ -24,6 +25,8 @@ enum GenerationError: Error, CustomStringConvertible, ProcessError {
return error.description
case let .generationError(error):
return String(describing: error)
case .missingUsername:
return "Couldn't find current username"
case let .writingError(error):
return String(describing: error)
}
Expand Down
19 changes: 19 additions & 0 deletions Sources/XcodeGenKit/ProjectGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public class ProjectGenerator {
let sharedData = XCSharedData(schemes: schemes)
return XcodeProj(workspace: workspace, pbxproj: pbxProj, sharedData: sharedData)
}

public func generateSchemeManagement() -> XCSchemeManagement {
let userStateSchemes = project.targets.map { target -> XCSchemeManagement.UserStateScheme in
XCSchemeManagement.UserStateScheme(
name: target.name + ".xcscheme",
shared: target.scheme?.shared ?? TargetScheme.sharedDefault,
orderHint: target.scheme?.orderHint,
isShown: target.scheme?.isShown ?? nil
)
}

let schemeManagement = XCSchemeManagement(
schemeUserState: userStateSchemes,
suppressBuildableAutocreation: nil
)

return schemeManagement
}


func generateWorkspace() throws -> XCWorkspace {
let selfReference = XCWorkspaceDataFileRef(location: .`self`(""))
Expand Down
3 changes: 2 additions & 1 deletion Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ extension Scheme {
),
archive: .init(
config: releaseConfig
)
),
management: targetScheme.management
)
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/PerformanceTests/TestProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ extension Project {
XCScheme.EnvironmentVariable(variable: "ENV2", value: "HELLO", enabled: false),
],
preActions: [Scheme.ExecutionAction(name: "run", script: "script")],
postActions: [Scheme.ExecutionAction(name: "run", script: "script")]
postActions: [Scheme.ExecutionAction(name: "run", script: "script")],
shared: false,
orderHint: 1,
isShown: true
)
for platform in Platform.allCases {
let appTarget = Target(
Expand Down

0 comments on commit b7a95fc

Please sign in to comment.