Skip to content

Commit

Permalink
allow multiple spec files to be provided to XcodeGen (#1270)
Browse files Browse the repository at this point in the history
* allow spec to be a comma separated list of specs instead of one

* update readme and --spec command documentation

* update Changelog

* print project name
  • Loading branch information
skofgar committed Nov 2, 2022
1 parent 87d7c7e commit 3e9fd04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added support for `enableGPUFrameCaptureMode` #1251 @bsudekum
- Config setting presets can now also be loaded from the main bundle when bundling XcodeGenKit #1135 @SofteqDG
- Added ability to generate multiple projects in one XcodeGen launch #1270 @skofgar

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This will look for a project spec in the current directory called `project.yml`

Options:

- **--spec**: An optional path to a `.yml` or `.json` project spec. Defaults to `project.yml`
- **--spec**: An optional path to a `.yml` or `.json` project spec. 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.)
- **--project**: An optional path to a directory where the project will be generated. By default this is the directory the spec lives in.
- **--quiet**: Suppress informational and success messages.
- **--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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenCLI/Commands/GenerateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GenerateCommand: ProjectCommand {
do {
let existingCacheFile: String = try cacheFilePath.read()
if cacheFile.string == existingCacheFile {
info("Project has not changed since cache was written")
info("Project \(project.name) has not changed since cache was written")
return
}
} catch {
Expand Down
44 changes: 26 additions & 18 deletions Sources/XcodeGenCLI/Commands/ProjectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ProjectCommand: Command {
let name: String
let shortDescription: String

@Key("-s", "--spec", description: "The path to the project spec file. Defaults to project.yml")
var spec: Path?
@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?

@Key("-r", "--project-root", description: "The path to the project root directory. Defaults to the directory containing the project spec.")
var projectRoot: Path?
Expand All @@ -29,24 +29,32 @@ class ProjectCommand: Command {

func execute() throws {

let projectSpecPath = (spec ?? "project.yml").absolute()

if !projectSpecPath.exists {
throw GenerationError.missingProjectSpec(projectSpecPath)
var projectSpecs: [Path] = []
if let spec = spec {
projectSpecs = spec.components(separatedBy: ",").map { Path($0).absolute() }
} else {
projectSpecs = [ Path("project.yml").absolute() ]
}

let specLoader = SpecLoader(version: version)
let project: Project

let variables: [String: String] = disableEnvExpansion ? [:] : ProcessInfo.processInfo.environment

do {
project = try specLoader.loadProject(path: projectSpecPath, projectRoot: projectRoot, variables: variables)
} catch {
throw GenerationError.projectSpecParsingError(error)

for projectSpecPath in projectSpecs {
if !projectSpecPath.exists {
throw GenerationError.missingProjectSpec(projectSpecPath)
}


let specLoader = SpecLoader(version: version)
let project: Project

let variables: [String: String] = disableEnvExpansion ? [:] : ProcessInfo.processInfo.environment

do {
project = try specLoader.loadProject(path: projectSpecPath, projectRoot: projectRoot, variables: variables)
} catch {
throw GenerationError.projectSpecParsingError(error)
}

try execute(specLoader: specLoader, projectSpecPath: projectSpecPath, project: project)
}

try execute(specLoader: specLoader, projectSpecPath: projectSpecPath, project: project)
}

func execute(specLoader: SpecLoader, projectSpecPath: Path, project: Project) throws {}
Expand Down

0 comments on commit 3e9fd04

Please sign in to comment.