diff --git a/.gitignore b/.gitignore index fbb30c55..efb14e67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -.DS_Store +# NOTE: Do not ignore .DS_Store for test fixtures. +# .DS_Store +./.DS_Store + /.build /Packages xcuserdata diff --git a/Fixtures/TestProject/.DS_Store b/Fixtures/TestProject/.DS_Store new file mode 100644 index 00000000..4e5e1b68 Binary files /dev/null and b/Fixtures/TestProject/.DS_Store differ diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 55939c73..563c76f9 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -220,26 +220,24 @@ class SourceGenerator { return variantGroup } - private func getSourceChildren(targetSource: TargetSource, dirPath: Path) throws -> [Path] { + private func getSourceExcludes(targetSource: TargetSource) -> [Path] { + let rootSourcePath = spec.basePath + targetSource.path - func getSourceExcludes(dirPath: Path) -> [Path] { - return targetSource.excludes.map { - Path.glob("\(dirPath)/\($0)") - .map { - guard $0.isDirectory else { - return [$0] - } - - return (try? $0.recursiveChildren().filter { $0.isFile }) ?? [] + return targetSource.excludes.map { + Path.glob("\(rootSourcePath)/\($0)") + .map { + guard $0.isDirectory else { + return [$0] } - .reduce([], +) + + return (try? $0.recursiveChildren().filter { $0.isFile }) ?? [] + } + .reduce([], +) } .reduce([], +) - } + } - let defaultExcludedFiles = [".DS_Store"].map { dirPath + Path($0) } - - let rootSourcePath = spec.basePath + targetSource.path + private func getSourceChildren(targetSource: TargetSource, dirPath: Path) throws -> [Path] { /* Exclude following if mentioned in TargetSource.excludes. @@ -248,21 +246,23 @@ class SourceGenerator { */ let sourceExcludeFilePaths: Set = Set( - getSourceExcludes(dirPath: rootSourcePath) - + defaultExcludedFiles + getSourceExcludes(targetSource: targetSource) ) + func isNotExcludeFilePath(_ path: Path) -> Bool { + return !path.lastComponent.contains(".DS_Store") + && !sourceExcludeFilePaths.contains(path) + } + return try dirPath.children() .filter { if $0.isDirectory { let pathChildren = try $0.children() - .filter { - return !sourceExcludeFilePaths.contains($0) - } + .filter(isNotExcludeFilePath(_:)) return !pathChildren.isEmpty } else if $0.isFile { - return !sourceExcludeFilePaths.contains($0) + return isNotExcludeFilePath($0) } else { return false } @@ -270,7 +270,8 @@ class SourceGenerator { } private func getGroupSources(targetSource: TargetSource, path: Path, isBaseGroup: Bool) - throws -> (sourceFiles: [SourceFile], groups: [ObjectReference]) { + throws -> (sourceFiles: [SourceFile], groups: [ObjectReference]) + { let children = try getSourceChildren(targetSource: targetSource, dirPath: path) @@ -323,8 +324,19 @@ class SourceGenerator { // create variant groups of the base localisation first var baseLocalisationVariantGroups: [PBXVariantGroup] = [] + let sourceExcludeFilePaths: Set = Set( + getSourceExcludes(targetSource: targetSource) + ) + + func isNotExcludeFilePath(_ path: Path) -> Bool { + return !path.lastComponent.contains(".DS_Store") + && !sourceExcludeFilePaths.contains(path) + } + if let baseLocalisedDirectory = baseLocalisedDirectory { - for filePath in try baseLocalisedDirectory.children().sorted() { + for filePath in try baseLocalisedDirectory.children() + .filter(isNotExcludeFilePath(_:)) + .sorted() { let variantGroup = getVariantGroup(path: filePath, inPath: path) groupChildren.append(variantGroup.reference) baseLocalisationVariantGroups.append(variantGroup.object) @@ -342,7 +354,9 @@ class SourceGenerator { // add references to localised resources into base localisation variant groups for localisedDirectory in localisedDirectories { let localisationName = localisedDirectory.lastComponentWithoutExtension - for filePath in try localisedDirectory.children().sorted { $0.lastComponent < $1.lastComponent } { + for filePath in try localisedDirectory.children() + .filter(isNotExcludeFilePath(_:)) + .sorted { $0.lastComponent < $1.lastComponent } { // find base localisation variant group // ex: Foo.strings will be added to Foo.strings or Foo.storyboard variant group let variantGroup = baseLocalisationVariantGroups diff --git a/Tests/Fixtures/TestProject/.DS_Store b/Tests/Fixtures/TestProject/.DS_Store new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/App_iOS/.DS_Store b/Tests/Fixtures/TestProject/App_iOS/.DS_Store new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/App_iOS/Base.lproj/.DS_Store b/Tests/Fixtures/TestProject/App_iOS/Base.lproj/.DS_Store new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/App_iOS/Base.lproj/excluded-file b/Tests/Fixtures/TestProject/App_iOS/Base.lproj/excluded-file new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/App_iOS/excluded-file b/Tests/Fixtures/TestProject/App_iOS/excluded-file new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/excluded-file b/Tests/Fixtures/TestProject/excluded-file new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/TestProject/spec.yml b/Tests/Fixtures/TestProject/spec.yml index ebee406e..33ee362a 100644 --- a/Tests/Fixtures/TestProject/spec.yml +++ b/Tests/Fixtures/TestProject/spec.yml @@ -29,6 +29,9 @@ targets: name: App compilerFlags: - "-Werror" + excludes: + - "**/excluded-file" + - "excluded-file" - path: StandaloneFiles/Standalone.swift - FileGroup/UnderFileGroup - Resources/MyBundle.bundle