Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved support for simple iOS sticker packs #824

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
## Next Version
#### Added
- Improve speed of metadata parsing and dependency resolution. [#803](https://github.com/yonaskolb/XcodeGen/pull/803) @michaeleisel
- Improve support for iOS sticker packs and add support for `launchAutomaticallySubstyle` to run schemes. [#824](https://github.com/yonaskolb/XcodeGen/pull/824) @scelis

## 2.15.1

1 change: 1 addition & 0 deletions Docs/Examples.md
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ These are a bunch of real world examples of XcodeGen project specs. Feel free to
- [johndpope/swift-models](https://github.com/johndpope/swift-models/tree/stable/Inference)
- [atelier-socle/AppRepositoryTemplate](https://github.com/atelier-socle/AppRepositoryTemplate/blob/master/project.yml)
- [atelier-socle/FrameworkRepositoryTemplate](https://github.com/atelier-socle/FrameworkRepositoryTemplate/blob/master/project.yml)
- [scelis/XcodeGen-TestStickers](https://github.com/scelis/XcodeGen-TestStickers/blob/master/project.yml)
1 change: 1 addition & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
@@ -738,6 +738,7 @@ The different actions share some properties:
- [ ] **region**: **String** - `run` and `test` actions can define a language that is used for Application Region
- [ ] **debugEnabled**: **Bool** - `run` and `test` actions can define a whether debugger should be used. This defaults to true.
- [ ] **simulateLocation**: **[Simulate Location](#simulate-location)** - `run` action can define a simulated location
- [ ] **launchAutomaticallySubstyle**: **String** - `run` action can define the launch automatically substyle ('2' for extensions).

### Execution Action

12 changes: 12 additions & 0 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
@@ -107,6 +107,7 @@ public struct Scheme: Equatable {
public var stopOnEveryMainThreadCheckerIssue: Bool
public var language: String?
public var region: String?
public var launchAutomaticallySubstyle: String?
public var debugEnabled: Bool
public var simulateLocation: SimulateLocation?

@@ -120,6 +121,7 @@ public struct Scheme: Equatable {
stopOnEveryMainThreadCheckerIssue: Bool = stopOnEveryMainThreadCheckerIssueDefault,
language: String? = nil,
region: String? = nil,
launchAutomaticallySubstyle: String? = nil,
debugEnabled: Bool = debugEnabledDefault,
simulateLocation: SimulateLocation? = nil
) {
@@ -132,6 +134,7 @@ public struct Scheme: Equatable {
self.stopOnEveryMainThreadCheckerIssue = stopOnEveryMainThreadCheckerIssue
self.language = language
self.region = region
self.launchAutomaticallySubstyle = launchAutomaticallySubstyle
self.debugEnabled = debugEnabled
self.simulateLocation = simulateLocation
}
@@ -349,6 +352,14 @@ extension Scheme.Run: JSONObjectConvertible {
region = jsonDictionary.json(atKeyPath: "region")
debugEnabled = jsonDictionary.json(atKeyPath: "debugEnabled") ?? Scheme.Run.debugEnabledDefault
simulateLocation = jsonDictionary.json(atKeyPath: "simulateLocation")

// launchAutomaticallySubstyle is defined as a String in XcodeProj but its value is often
// an integer. Parse both to be nice.
if let int: Int = jsonDictionary.json(atKeyPath: "launchAutomaticallySubstyle") {
launchAutomaticallySubstyle = String(int)
} else if let string: String = jsonDictionary.json(atKeyPath: "launchAutomaticallySubstyle") {
launchAutomaticallySubstyle = string
}
}
}

@@ -362,6 +373,7 @@ extension Scheme.Run: JSONEncodable {
"config": config,
"language": language,
"region": region,
"launchAutomaticallySubstyle": launchAutomaticallySubstyle,
]

if disableMainThreadChecker != Scheme.Run.disableMainThreadCheckerDefault {
11 changes: 11 additions & 0 deletions Sources/ProjectSpec/XCProjExtensions.swift
Original file line number Diff line number Diff line change
@@ -41,6 +41,17 @@ extension PBXProductType {
public var name: String {
rawValue.replacingOccurrences(of: "com.apple.product-type.", with: "")
}

public var canSkipCompileSourcesBuildPhase: Bool {
switch self {
case .stickerPack, .messagesApplication:
// Sticker packs and simple messages applications without sources should not include a
// compile sources build phase. Doing so can cause Xcode to produce an error on build.
return true
default:
return false
}
}
}

extension Platform {
4 changes: 1 addition & 3 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
@@ -927,9 +927,7 @@ public class PBXProjGenerator {
}

let sourcesBuildPhaseFiles = getBuildFilesForPhase(.sources)
// Sticker packs should not include a compile sources build phase as they
// are purely based on a set of image files, and nothing else.
let shouldSkipSourcesBuildPhase = sourcesBuildPhaseFiles.isEmpty && target.type == .stickerPack
let shouldSkipSourcesBuildPhase = sourcesBuildPhaseFiles.isEmpty && target.type.canSkipCompileSourcesBuildPhase
if !shouldSkipSourcesBuildPhase {
let sourcesBuildPhase = addObject(PBXSourcesBuildPhase(files: sourcesBuildPhaseFiles))
buildPhases.append(sourcesBuildPhase)
3 changes: 2 additions & 1 deletion Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
@@ -241,7 +241,8 @@ public class SchemeGenerator {
commandlineArguments: launchCommandLineArgs,
environmentVariables: launchVariables,
language: scheme.run?.language,
region: scheme.run?.region
region: scheme.run?.region,
launchAutomaticallySubstyle: scheme.run?.launchAutomaticallySubstyle
)

let profileAction = XCScheme.ProfileAction(
8 changes: 0 additions & 8 deletions Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -1441,7 +1441,6 @@
isa = PBXNativeTarget;
buildConfigurationList = 1FC6945BE13C2202A2BCA3BC /* Build configuration list for PBXNativeTarget "iMessageApp" */;
buildPhases = (
D067D70CFD13DFBED478C228 /* Sources */,
61001E265009194959C2CF36 /* Resources */,
2F0735A423E554B267BBA0A5 /* Embed App Extensions */,
);
@@ -2143,13 +2142,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D067D70CFD13DFBED478C228 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
D1F422E9C4DD531AA88418C9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
3 changes: 2 additions & 1 deletion Tests/ProjectSpecTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
@@ -475,7 +475,8 @@ class ProjectSpecTests: XCTestCase {
settingsTarget: "foo")],
environmentVariables: [XCScheme.EnvironmentVariable(variable: "foo",
value: "bar",
enabled: false)]),
enabled: false)],
launchAutomaticallySubstyle: "2"),
test: Scheme.Test(config: "Config",
gatherCoverageData: true,
disableMainThreadChecker: true,
26 changes: 26 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
@@ -771,6 +771,10 @@ class SpecLoadingTests: XCTestCase {
],
],
],
"run": [
"config": "debug",
"launchAutomaticallySubstyle": 2,
],
"test": [
"config": "debug",
"targets": [
@@ -806,6 +810,12 @@ class SpecLoadingTests: XCTestCase {
try expect(scheme.build.parallelizeBuild) == false
try expect(scheme.build.buildImplicitDependencies) == false

let expectedRun = Scheme.Run(
config: "debug",
launchAutomaticallySubstyle: "2"
)
try expect(scheme.run) == expectedRun

let expectedTest = Scheme.Test(
config: "debug",
gatherCoverageData: true,
@@ -835,6 +845,7 @@ class SpecLoadingTests: XCTestCase {
["variable": "ENVIRONMENT", "value": "VARIABLE"],
["variable": "OTHER_ENV_VAR", "value": "VAL", "isEnabled": false],
],
"launchAutomaticallySubstyle": "2"
],
"test": [
"environmentVariables": [
@@ -864,11 +875,26 @@ class SpecLoadingTests: XCTestCase {
]

try expect(scheme.run?.environmentVariables) == expectedRunVariables
try expect(scheme.run?.launchAutomaticallySubstyle) == "2"
try expect(scheme.test?.environmentVariables) == expectedTestVariables
try expect(scheme.profile?.config) == "Release"
try expect(scheme.profile?.environmentVariables.isEmpty) == true
}

$0.it("parses alternate schemes variables") {
let schemeDictionary: [String: Any] = [
"build": [
"targets": ["Target1": "all"],
],
"run": [
"launchAutomaticallySubstyle": 2, // Both integer and string supported
],
]

let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary)
try expect(scheme.run?.launchAutomaticallySubstyle) == "2"
}

$0.it("parses scheme templates") {
let targetDictionary: [String: Any] = [
"deploymentTarget": "1.2.0",
3 changes: 2 additions & 1 deletion Tests/XcodeGenKitTests/SchemeGeneratorTests.swift
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ class SchemeGeneratorTests: XCTestCase {
let scheme = Scheme(
name: "MyScheme",
build: Scheme.Build(targets: [buildTarget], preActions: [preAction]),
run: Scheme.Run(config: "Debug", simulateLocation: simulateLocation)
run: Scheme.Run(config: "Debug", launchAutomaticallySubstyle: "2", simulateLocation: simulateLocation)
)
let project = Project(
name: "test",
@@ -94,6 +94,7 @@ class SchemeGeneratorTests: XCTestCase {
try expect(xcscheme.launchAction?.selectedDebuggerIdentifier) == XCScheme.defaultDebugger
try expect(xcscheme.testAction?.selectedDebuggerIdentifier) == XCScheme.defaultDebugger

try expect(xcscheme.launchAction?.launchAutomaticallySubstyle) == "2"
try expect(xcscheme.launchAction?.allowLocationSimulation) == true
try expect(xcscheme.launchAction?.locationScenarioReference?.referenceType) == Scheme.SimulateLocation.ReferenceType.predefined.rawValue
try expect(xcscheme.launchAction?.locationScenarioReference?.identifier) == "New York, NY, USA"