From e387ee52a8522e03979954ea3dbab9ba5571295b Mon Sep 17 00:00:00 2001 From: Beniamin Sarkisian Date: Mon, 7 Jan 2019 13:50:23 +0300 Subject: [PATCH 1/4] Added an abbility to generate empty directories --- Sources/ProjectSpec/SpecOptions.swift | 6 +++++- Sources/XcodeGenKit/SourceGenerator.swift | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index 9d559578..12e097f7 100644 --- a/Sources/ProjectSpec/SpecOptions.swift +++ b/Sources/ProjectSpec/SpecOptions.swift @@ -19,6 +19,7 @@ public struct SpecOptions: Equatable { public var defaultConfig: String? public var transitivelyLinkDependencies: Bool public var groupSortPosition: GroupSortPosition + public var generateEmptyDirectories: Bool public enum ValidationType: String { case missingConfigs @@ -71,7 +72,8 @@ public struct SpecOptions: Equatable { disabledValidations: [ValidationType] = [], defaultConfig: String? = nil, transitivelyLinkDependencies: Bool = false, - groupSortPosition: GroupSortPosition = .bottom + groupSortPosition: GroupSortPosition = .bottom, + generateEmptyDirectories: Bool = true ) { self.minimumXcodeGenVersion = minimumXcodeGenVersion self.carthageBuildPath = carthageBuildPath @@ -89,6 +91,7 @@ public struct SpecOptions: Equatable { self.defaultConfig = defaultConfig self.transitivelyLinkDependencies = transitivelyLinkDependencies self.groupSortPosition = groupSortPosition + self.generateEmptyDirectories = generateEmptyDirectories } } @@ -114,5 +117,6 @@ extension SpecOptions: JSONObjectConvertible { defaultConfig = jsonDictionary.json(atKeyPath: "defaultConfig") transitivelyLinkDependencies = jsonDictionary.json(atKeyPath: "transitivelyLinkDependencies") ?? false groupSortPosition = jsonDictionary.json(atKeyPath: "groupSortPosition") ?? .bottom + generateEmptyDirectories = jsonDictionary.json(atKeyPath: "generateEmptyDirectories") ?? true } } diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index b3b86a20..fd7fbc22 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -318,8 +318,12 @@ class SourceGenerator { return try dirPath.children() .filter { if $0.isDirectory { - let children = try $0.children().filter(isIncludedPath) - return !children.isEmpty + if project.options.generateEmptyDirectories { + return true + } else { + let children = try $0.children().filter(isIncludedPath) + return !children.isEmpty + } } else if $0.isFile { return isIncludedPath($0) } else { @@ -352,18 +356,18 @@ class SourceGenerator { for path in directories { let subGroups = try getGroupSources(targetType: targetType, targetSource: targetSource, path: path, isBaseGroup: false) - guard !subGroups.sourceFiles.isEmpty else { + guard !subGroups.sourceFiles.isEmpty || project.options.generateEmptyDirectories else { continue } allSourceFiles += subGroups.sourceFiles - guard let firstGroup = subGroups.groups.first else { - continue + if let firstGroup = subGroups.groups.first { + groupChildren.append(firstGroup) + groups += subGroups.groups + } else if project.options.generateEmptyDirectories { + groups += subGroups.groups } - - groupChildren.append(firstGroup) - groups += subGroups.groups } // find the base localised directory From 6f8d459c3f28bd0028b78dbef26bb89fae8f63fe Mon Sep 17 00:00:00 2001 From: Beniamin Sarkisian Date: Mon, 7 Jan 2019 13:58:43 +0300 Subject: [PATCH 2/4] Updated ProjectSpec.md --- Docs/ProjectSpec.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 91a91fb3..79924e88 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -93,6 +93,7 @@ Note that target names can also be changed by adding a `name` property to a targ - `bottom` - at the bottom, after other files - `none` - sorted alphabetically with all the other files - [ ] **transitivelyLinkDependencies**: **Bool** - If this is `true` then targets will link to the dependencies of their target dependencies. If a target should embed its dependencies, such as application and test bundles, it will embed these transitive dependencies as well. Some complex setups might want to set this to `false` and explicitly specify dependencies at every level. Targets can override this with [Target](#target).transitivelyLinkDependencies. Defaults to `false`. +- [ ] **generateEmptyDirectories**: **Bool** - If this is `true` then empty directories will be added to project too else will be missed. Defaults to `true`. ```yaml options: From 976841ba4072f137472f02877b20483806ace909 Mon Sep 17 00:00:00 2001 From: Beniamin Sarkisian Date: Mon, 7 Jan 2019 15:27:17 +0300 Subject: [PATCH 3/4] Changed the default value of `generateEmptyDirectories` option to `false` --- Docs/ProjectSpec.md | 2 +- Sources/ProjectSpec/SpecOptions.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 79924e88..956a634c 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -93,7 +93,7 @@ Note that target names can also be changed by adding a `name` property to a targ - `bottom` - at the bottom, after other files - `none` - sorted alphabetically with all the other files - [ ] **transitivelyLinkDependencies**: **Bool** - If this is `true` then targets will link to the dependencies of their target dependencies. If a target should embed its dependencies, such as application and test bundles, it will embed these transitive dependencies as well. Some complex setups might want to set this to `false` and explicitly specify dependencies at every level. Targets can override this with [Target](#target).transitivelyLinkDependencies. Defaults to `false`. -- [ ] **generateEmptyDirectories**: **Bool** - If this is `true` then empty directories will be added to project too else will be missed. Defaults to `true`. +- [ ] **generateEmptyDirectories**: **Bool** - If this is `true` then empty directories will be added to project too else will be missed. Defaults to `false`. ```yaml options: diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index 12e097f7..f218c88b 100644 --- a/Sources/ProjectSpec/SpecOptions.swift +++ b/Sources/ProjectSpec/SpecOptions.swift @@ -73,7 +73,7 @@ public struct SpecOptions: Equatable { defaultConfig: String? = nil, transitivelyLinkDependencies: Bool = false, groupSortPosition: GroupSortPosition = .bottom, - generateEmptyDirectories: Bool = true + generateEmptyDirectories: Bool = false ) { self.minimumXcodeGenVersion = minimumXcodeGenVersion self.carthageBuildPath = carthageBuildPath @@ -117,6 +117,6 @@ extension SpecOptions: JSONObjectConvertible { defaultConfig = jsonDictionary.json(atKeyPath: "defaultConfig") transitivelyLinkDependencies = jsonDictionary.json(atKeyPath: "transitivelyLinkDependencies") ?? false groupSortPosition = jsonDictionary.json(atKeyPath: "groupSortPosition") ?? .bottom - generateEmptyDirectories = jsonDictionary.json(atKeyPath: "generateEmptyDirectories") ?? true + generateEmptyDirectories = jsonDictionary.json(atKeyPath: "generateEmptyDirectories") ?? false } } From 73a345ab6d5a7471e12676955102cdb4f95487cc Mon Sep 17 00:00:00 2001 From: Beniamin Date: Tue, 8 Jan 2019 14:17:15 +0300 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a0eaf17..c96b5e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Master +#### Added +- Added new ability to generate empty directories via `options.generateEmptyDirectories` [#480](https://github.com/yonaskolb/XcodeGen/pull/480) @Beniamiiin + ## 2.1.0 #### Added