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 diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 91a91fb3..956a634c 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 `false`. ```yaml options: diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index 9d559578..f218c88b 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 = false ) { 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") ?? false } } 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