From 8d06dbe8cab6253b5f54b16d84b2738707c6fa5f Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Mon, 28 Jan 2019 21:43:11 +1100 Subject: [PATCH] add createIntermediateGroups to TargetSource --- Docs/ProjectSpec.md | 5 +++-- Sources/ProjectSpec/TargetSource.swift | 7 ++++++- Sources/XcodeGenKit/SourceGenerator.swift | 8 +++++--- Tests/XcodeGenKitTests/SourceGeneratorTests.swift | 4 ++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 3dbfbf4b..002d9878 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -88,7 +88,7 @@ Note that target names can also be changed by adding a `name` property to a targ - [ ] **minimumXcodeGenVersion**: **String** - The minimum version of XcodeGen required. - [ ] **carthageBuildPath**: **String** - The path to the carthage build directory. Defaults to `Carthage/Build`. This is used when specifying target carthage dependencies - [ ] **carthageExecutablePath**: **String** - The path to the carthage executable. Defaults to `carthage`. You can specify when you use custom built or locally installed Carthage using [Mint](https://github.com/yonaskolb/Mint), for example. -- [ ] **createIntermediateGroups**: **Bool** - If this is specified and set to `true`, then intermediate groups will be created for every path component between the folder containing the source and next existing group it finds or the base path. For example, when enabled if a source path is specified as `Vendor/Foo/Hello.swift`, the group `Vendor` will created as a parent of the `Foo` group. +- [ ] **createIntermediateGroups**: **Bool** - If this is specified and set to `true`, then intermediate groups will be created for every path component between the folder containing the source and next existing group it finds or the base path. For example, when enabled if a source path is specified as `Vendor/Foo/Hello.swift`, the group `Vendor` will created as a parent of the `Foo` group. This can be overriden in a specific [Target source](#target-source) - [ ] **bundleIdPrefix**: **String** - If this is specified then any target that doesn't have an `PRODUCT_BUNDLE_IDENTIFIER` (via all levels of build settings) will get an autogenerated one by combining `bundleIdPrefix` and the target name: `bundleIdPrefix.name`. The target name will be stripped of all characters that aren't alphanumerics, hyphens, or periods. Underscores will be replaced with hyphens. - [ ] **settingPresets**: **String** - This controls the settings that are automatically applied to the project and its targets. These are the same build settings that Xcode would add when creating a new project. Project settings are applied by config type. Target settings are applied by the product type and platform. By default this is set to `all` - `all`: project and target settings @@ -283,12 +283,13 @@ Specifies the source directories for a target. This can either be a single sourc A source can be provided via a string (the path) or an object of the form: -**Target Source Object**: +#### Target Source - [x] **path**: **String** - The path to the source file or directory. - [ ] **name**: **String** - Can be used to override the name of the source file or directory. By default the last component of the path is used for the name - [ ] **compilerFlags**: **[String]** or **String** - A list of compilerFlags to add to files under this specific path provided as a list or a space delimitted string. Defaults to empty. - [ ] **excludes**: **[String]** - A list of [global patterns](https://en.wikipedia.org/wiki/Glob_(programming)) representing the files to exclude. These rules are relative to `path` and _not the directory where `project.yml` resides_. +- [ ] **createIntermediateGroups**: **Bool** - This overrides the value in [Options](#options) - [ ] **optional**: **Bool** - Disable missing path check. Defaults to false. - [ ] **buildPhase**: **String** - This manually sets the build phase this file or files in this directory will be added to, otherwise XcodeGen will guess based on the file extension. Note that `Info.plist` files will never be added to any build phases, no matter what this setting is. Possible values are: - `sources` - Compile Sources phase diff --git a/Sources/ProjectSpec/TargetSource.swift b/Sources/ProjectSpec/TargetSource.swift index 950142b1..e1049783 100644 --- a/Sources/ProjectSpec/TargetSource.swift +++ b/Sources/ProjectSpec/TargetSource.swift @@ -13,6 +13,7 @@ public struct TargetSource: Equatable { public var optional: Bool public var buildPhase: BuildPhase? public var headerVisibility: HeaderVisibility? + public var createIntermediateGroups: Bool? public enum HeaderVisibility: String { case `public` @@ -124,7 +125,8 @@ public struct TargetSource: Equatable { type: SourceType? = nil, optional: Bool = false, buildPhase: BuildPhase? = nil, - headerVisibility: HeaderVisibility? = nil + headerVisibility: HeaderVisibility? = nil, + createIntermediateGroups: Bool? = nil ) { self.path = path self.name = name @@ -134,6 +136,7 @@ public struct TargetSource: Equatable { self.optional = optional self.buildPhase = buildPhase self.headerVisibility = headerVisibility + self.createIntermediateGroups = createIntermediateGroups } } @@ -173,6 +176,8 @@ extension TargetSource: JSONObjectConvertible { } else if let dict: JSONDictionary = jsonDictionary.json(atKeyPath: "buildPhase") { buildPhase = try BuildPhase(jsonDictionary: dict) } + + createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups") } } diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 4ca61025..1dd2473c 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -443,13 +443,15 @@ class SourceGenerator { } } + let createIntermediateGroups = targetSource.createIntermediateGroups ?? project.options.createIntermediateGroups + let group = getGroup( path: path, mergingChildren: groupChildren, - createIntermediateGroups: project.options.createIntermediateGroups, + createIntermediateGroups: createIntermediateGroups, isBaseGroup: isBaseGroup ) - if project.options.createIntermediateGroups { + if createIntermediateGroups { createIntermediaGroups(for: group, at: path) } @@ -464,7 +466,7 @@ class SourceGenerator { targetSourceExcludePaths = getSourceExcludes(targetSource: targetSource) let type = targetSource.type ?? (path.isFile || path.extension != nil ? .file : .group) - let createIntermediateGroups = project.options.createIntermediateGroups + let createIntermediateGroups = targetSource.createIntermediateGroups ?? project.options.createIntermediateGroups var sourceFiles: [SourceFile] = [] let sourceReference: PBXFileElement diff --git a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift index a3092f27..416d1660 100644 --- a/Tests/XcodeGenKitTests/SourceGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SourceGeneratorTests.swift @@ -367,6 +367,8 @@ class SourceGeneratorTests: XCTestCase { F: - G: - h.swift + B: + - b.swift """ try createDirectories(directories) let outOfSourceFile = outOfRootPath + "C/D/e.swift" @@ -377,6 +379,7 @@ class SourceGeneratorTests: XCTestCase { "Sources/A/b.swift", "Sources/F/G/h.swift", "../OtherDirectory/C/D/e.swift", + TargetSource(path: "Sources/B", createIntermediateGroups: false) ]) let options = SpecOptions(createIntermediateGroups: true) let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options) @@ -385,6 +388,7 @@ class SourceGeneratorTests: XCTestCase { try pbxProj.expectFile(paths: ["Sources", "A", "b.swift"], buildPhase: .sources) try pbxProj.expectFile(paths: ["Sources", "F", "G", "h.swift"], buildPhase: .sources) try pbxProj.expectFile(paths: [(outOfRootPath + "C/D").string, "e.swift"], names: ["D", "e.swift"], buildPhase: .sources) + try pbxProj.expectFile(paths: ["Sources/B", "b.swift"], names: ["B", "b.swift"], buildPhase: .sources) } $0.it("generates folder references") {