mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-09-11 12:56:03 +03:00
Compare commits
8 Commits
abe2e31463
...
12cebdd679
Author | SHA1 | Date | |
---|---|---|---|
|
12cebdd679 | ||
|
f51719ce29 | ||
|
1b0720d139 | ||
|
576739bcb5 | ||
|
aa79a3ed0b | ||
|
f0be240238 | ||
|
b616864b03 | ||
|
ce5d015351 |
10
CHANGELOG.md
10
CHANGELOG.md
@ -2,6 +2,16 @@
|
||||
|
||||
## Next Version
|
||||
|
||||
## 2.41.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added `xcodegen cache` command that writes the cache. Useful for `post-commit` git hook integration #1476 @yonaskolb
|
||||
|
||||
### Changed
|
||||
|
||||
- Include folders in file sorting #1466 @jflan-dd
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `supportedDestinations` validation when it contains watchOS for multiplatform apps. #1470 @tatsuky
|
||||
|
10
Docs/FAQ.md
10
Docs/FAQ.md
@ -9,10 +9,14 @@ Absolutely. You will get the most out of XcodeGen by adding your project to your
|
||||
>Note that you can run `xcodegen` as a step in your build process on CI.
|
||||
|
||||
## What happens when I switch branches
|
||||
If files were added or removed in the new checkout you will most likely need to run `xcodegen` again so that your project will reference all your files. Unfortunately this is a manual step at the moment, but in the future this could be automated.
|
||||
If files were added or removed in the new checkout you will most likely need to run `xcodegen` again so that your project will reference all your files.
|
||||
|
||||
For now you can always add xcodegen as a git `post-checkout` hook.
|
||||
It's recommended to use `--use-cache` so that the project is not needlessly generated.
|
||||
It's recommended to set up some [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to automate the process:
|
||||
- run `xcodegen generate --use-cache` on the following hooks. This will make sure the project is up to date when checking out, merging and rebasing
|
||||
- `post-checkout`
|
||||
- `post-rewrite`
|
||||
- `post-merge`
|
||||
- run `xcodegen cache` on `pre-commit`. This will make sure that when switching branches the cache will be updated in case you made local changes, or are ammending a commit that added a new file.
|
||||
|
||||
## Can I use CocoaPods
|
||||
Yes, you will just need to run `pod install` after the project is generated to integrate Cocoapods changes.
|
||||
|
@ -1039,7 +1039,7 @@ The different actions share some properties:
|
||||
- [ ] **askForAppToLaunch**: **Bool** - `run` and `profile` actions can define the executable set to ask to launch. This defaults to false.
|
||||
- [ ] **launchAutomaticallySubstyle**: **String** - `run` action can define the launch automatically substyle ('2' for extensions).
|
||||
- [ ] **storeKitConfiguration**: **String** - `run` action can specify a storekit configuration. See [Options](#options).
|
||||
- [ ] **macroExpansion**: **String** - `run` action can define the macro expansion from other target. This defaults to nil.
|
||||
- [ ] **macroExpansion**: **String** - `run` and `test` action can define the macro expansion from other target. This defaults to nil.
|
||||
|
||||
### Execution Action
|
||||
|
||||
|
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
TOOL_NAME = XcodeGen
|
||||
export EXECUTABLE_NAME = xcodegen
|
||||
VERSION = 2.40.1
|
||||
VERSION = 2.41.0
|
||||
|
||||
PREFIX = /usr/local
|
||||
INSTALL_PATH = $(PREFIX)/bin/$(EXECUTABLE_NAME)
|
||||
|
@ -113,7 +113,7 @@ swift run xcodegen
|
||||
Add the following to your Package.swift file's dependencies:
|
||||
|
||||
```swift
|
||||
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "2.40.1"),
|
||||
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "2.41.0"),
|
||||
```
|
||||
|
||||
And then import wherever needed: `import XcodeGenKit`
|
||||
@ -136,7 +136,7 @@ Options:
|
||||
- **--use-cache**: Used to prevent unnecessarily generating the project. If this is set, then a cache file will be written to when a project is generated. If `xcodegen` is later run but the spec and all the files it contains are the same, the project won't be generated.
|
||||
- **--cache-path**: A custom path to use for your cache file. This defaults to `~/.xcodegen/cache/{PROJECT_SPEC_PATH_HASH}`
|
||||
|
||||
There are other commands as well such as `xcodegen dump` which lets out output the resolved spec in many different formats, or write it to a file. Use `xcodegen help` to see more detailed usage information.
|
||||
There are other commands as well such as `xcodegen dump` which lets one output the resolved spec in many different formats, or write it to a file. Use `xcodegen help` to see more detailed usage information.
|
||||
|
||||
## Dependency Diagrams
|
||||
<details>
|
||||
|
@ -220,6 +220,7 @@ public struct Scheme: Equatable {
|
||||
public var captureScreenshotsAutomatically: Bool
|
||||
public var deleteScreenshotsWhenEachTestSucceeds: Bool
|
||||
public var testPlans: [TestPlan]
|
||||
public var macroExpansion: String?
|
||||
|
||||
public struct TestTarget: Equatable, ExpressibleByStringLiteral {
|
||||
|
||||
@ -286,7 +287,8 @@ public struct Scheme: Equatable {
|
||||
debugEnabled: Bool = debugEnabledDefault,
|
||||
customLLDBInit: String? = nil,
|
||||
captureScreenshotsAutomatically: Bool = captureScreenshotsAutomaticallyDefault,
|
||||
deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault
|
||||
deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault,
|
||||
macroExpansion: String? = nil
|
||||
) {
|
||||
self.config = config
|
||||
self.gatherCoverageData = gatherCoverageData
|
||||
@ -304,6 +306,7 @@ public struct Scheme: Equatable {
|
||||
self.customLLDBInit = customLLDBInit
|
||||
self.captureScreenshotsAutomatically = captureScreenshotsAutomatically
|
||||
self.deleteScreenshotsWhenEachTestSucceeds = deleteScreenshotsWhenEachTestSucceeds
|
||||
self.macroExpansion = macroExpansion
|
||||
}
|
||||
|
||||
public var shouldUseLaunchSchemeArgsEnv: Bool {
|
||||
@ -620,6 +623,7 @@ extension Scheme.Test: JSONObjectConvertible {
|
||||
customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit")
|
||||
captureScreenshotsAutomatically = jsonDictionary.json(atKeyPath: "captureScreenshotsAutomatically") ?? Scheme.Test.captureScreenshotsAutomaticallyDefault
|
||||
deleteScreenshotsWhenEachTestSucceeds = jsonDictionary.json(atKeyPath: "deleteScreenshotsWhenEachTestSucceeds") ?? Scheme.Test.deleteScreenshotsWhenEachTestSucceedsDefault
|
||||
macroExpansion = jsonDictionary.json(atKeyPath: "macroExpansion")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,6 @@ import ProjectSpec
|
||||
import XcodeGenCLI
|
||||
import Version
|
||||
|
||||
let version = Version("2.40.1")
|
||||
let version = Version("2.41.0")
|
||||
let cli = XcodeGenCLI(version: version)
|
||||
cli.execute()
|
||||
|
44
Sources/XcodeGenCLI/Commands/CacheCommand.swift
Normal file
44
Sources/XcodeGenCLI/Commands/CacheCommand.swift
Normal file
@ -0,0 +1,44 @@
|
||||
import Foundation
|
||||
import PathKit
|
||||
import ProjectSpec
|
||||
import SwiftCLI
|
||||
import XcodeGenKit
|
||||
import XcodeProj
|
||||
import Version
|
||||
|
||||
class CacheCommand: ProjectCommand {
|
||||
|
||||
@Key("--cache-path", description: "Where the cache file will be loaded from and save to. Defaults to ~/.xcodegen/cache/{SPEC_PATH_HASH}")
|
||||
var cacheFilePath: Path?
|
||||
|
||||
init(version: Version) {
|
||||
super.init(version: version,
|
||||
name: "cache",
|
||||
shortDescription: "Write the project cache")
|
||||
}
|
||||
|
||||
override func execute(specLoader: SpecLoader, projectSpecPath: Path, project: Project) throws {
|
||||
|
||||
let cacheFilePath = self.cacheFilePath ?? Path("~/.xcodegen/cache/\(projectSpecPath.absolute().string.md5)").absolute()
|
||||
|
||||
var cacheFile: CacheFile?
|
||||
|
||||
// generate cache
|
||||
do {
|
||||
cacheFile = try specLoader.generateCacheFile()
|
||||
} catch {
|
||||
throw GenerationError.projectSpecParsingError(error)
|
||||
}
|
||||
|
||||
// write cache
|
||||
if let cacheFile = cacheFile {
|
||||
do {
|
||||
try cacheFilePath.parent().mkpath()
|
||||
try cacheFilePath.write(cacheFile.string)
|
||||
success("Wrote cache to \(cacheFilePath)")
|
||||
} catch {
|
||||
info("Failed to write cache: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ class DumpCommand: ProjectCommand {
|
||||
try file.parent().mkpath()
|
||||
try file.write(output)
|
||||
} else {
|
||||
stdout.print(output)
|
||||
success(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,6 @@ import Version
|
||||
|
||||
class GenerateCommand: ProjectCommand {
|
||||
|
||||
@Flag("-q", "--quiet", description: "Suppress all informational and success output")
|
||||
var quiet: Bool
|
||||
|
||||
@Flag("-c", "--use-cache", description: "Use a cache for the xcodegen spec. This will prevent unnecessarily generating the project if nothing has changed")
|
||||
var useCache: Bool
|
||||
|
||||
@ -46,7 +43,7 @@ class GenerateCommand: ProjectCommand {
|
||||
Path("~/.xcodegen/cache/\(projectSpecPath.absolute().string.md5)").absolute()
|
||||
var cacheFile: CacheFile?
|
||||
|
||||
// read cache
|
||||
// generate cache
|
||||
if useCache || self.cacheFilePath != nil {
|
||||
do {
|
||||
cacheFile = try specLoader.generateCacheFile()
|
||||
@ -138,22 +135,4 @@ class GenerateCommand: ProjectCommand {
|
||||
try Task.run(bash: command, directory: projectDirectory.absolute().string)
|
||||
}
|
||||
}
|
||||
|
||||
func info(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string)
|
||||
}
|
||||
}
|
||||
|
||||
func warning(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string.yellow)
|
||||
}
|
||||
}
|
||||
|
||||
func success(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string.green)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ class ProjectCommand: Command {
|
||||
let name: String
|
||||
let shortDescription: String
|
||||
|
||||
@Flag("-q", "--quiet", description: "Suppress all informational and success output")
|
||||
var quiet: Bool
|
||||
|
||||
@Key("-s", "--spec", description: "The path to the project spec file. Defaults to project.yml. (It is also possible to link to multiple spec files by comma separating them. Note that all other flags will be the same.)")
|
||||
var spec: String?
|
||||
|
||||
@ -58,4 +61,22 @@ class ProjectCommand: Command {
|
||||
}
|
||||
|
||||
func execute(specLoader: SpecLoader, projectSpecPath: Path, project: Project) throws {}
|
||||
|
||||
func info(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string)
|
||||
}
|
||||
}
|
||||
|
||||
func warning(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string.yellow)
|
||||
}
|
||||
}
|
||||
|
||||
func success(_ string: String) {
|
||||
if !quiet {
|
||||
stdout.print(string.green)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ public class XcodeGenCLI {
|
||||
description: "Generates Xcode projects",
|
||||
commands: [
|
||||
generateCommand,
|
||||
CacheCommand(version: version),
|
||||
DumpCommand(version: version),
|
||||
]
|
||||
)
|
||||
|
@ -233,6 +233,10 @@ public class SchemeGenerator {
|
||||
let buildableReference = buildActionEntries.first(where: { $0.buildableReference.blueprintName == schemeTarget?.name })?.buildableReference ?? buildActionEntries.first!.buildableReference
|
||||
let runnables = makeProductRunnables(for: schemeTarget, buildableReference: buildableReference)
|
||||
|
||||
let testMacroExpansion: XCScheme.BuildableReference = buildActionEntries.first(
|
||||
where: { $0.buildableReference.blueprintName == scheme.test?.macroExpansion }
|
||||
)?.buildableReference ?? buildableReference
|
||||
|
||||
let buildAction = XCScheme.BuildAction(
|
||||
buildActionEntries: buildActionEntries,
|
||||
preActions: scheme.build.preActions.map(getExecutionAction),
|
||||
@ -289,7 +293,7 @@ public class SchemeGenerator {
|
||||
|
||||
let testAction = XCScheme.TestAction(
|
||||
buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name,
|
||||
macroExpansion: buildableReference,
|
||||
macroExpansion: testMacroExpansion,
|
||||
testables: testables,
|
||||
testPlans: testPlans.isEmpty ? nil : testPlans,
|
||||
preActions: scheme.test?.preActions.map(getExecutionAction) ?? [],
|
||||
|
@ -476,6 +476,41 @@ class SchemeGeneratorTests: XCTestCase {
|
||||
let xcodeProject = try project.generateXcodeProject()
|
||||
|
||||
let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
|
||||
try expect(xcscheme.testAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
try expect(xcscheme.launchAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
}
|
||||
|
||||
$0.it("allows to override test macroExpansion") {
|
||||
let app = Target(
|
||||
name: "MyApp",
|
||||
type: .application,
|
||||
platform: .iOS,
|
||||
dependencies: [Dependency(type: .target, reference: "MyAppExtension", embed: false)]
|
||||
)
|
||||
|
||||
let `extension` = Target(
|
||||
name: "MyAppExtension",
|
||||
type: .appExtension,
|
||||
platform: .iOS
|
||||
)
|
||||
let appTarget = Scheme.BuildTarget(target: .local(app.name), buildTypes: [.running])
|
||||
let extensionTarget = Scheme.BuildTarget(target: .local(`extension`.name), buildTypes: [.running])
|
||||
|
||||
let scheme = Scheme(
|
||||
name: "TestScheme",
|
||||
build: Scheme.Build(targets: [appTarget, extensionTarget]),
|
||||
run: Scheme.Run(config: "Debug", macroExpansion: "MyApp"),
|
||||
test: .init(macroExpansion: "MyAppExtension")
|
||||
)
|
||||
let project = Project(
|
||||
name: "test",
|
||||
targets: [app, `extension`],
|
||||
schemes: [scheme]
|
||||
)
|
||||
let xcodeProject = try project.generateXcodeProject()
|
||||
|
||||
let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
|
||||
try expect(xcscheme.testAction?.macroExpansion?.buildableName) == "MyAppExtension.appex"
|
||||
try expect(xcscheme.launchAction?.macroExpansion?.buildableName) == "MyApp.app"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user