From 015f9a44dfef933ba484500cab9822c93d8295c0 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:09:18 +0900 Subject: [PATCH 1/6] apply excludes for localised directories --- Sources/XcodeGenKit/SourceGenerator.swift | 62 ++++++++++++++--------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index 751d2e3b..b027aa46 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -188,26 +188,24 @@ class SourceGenerator { return variantGroup } - private func getSourceChildren(targetSource: TargetSource, dirPath: Path) throws -> [Path] { + 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. @@ -216,21 +214,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 } @@ -238,7 +238,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) @@ -291,8 +292,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) @@ -310,7 +322,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 From 53cf0faa21efa509d85bd43d18d5388d86b566c8 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:16:41 +0900 Subject: [PATCH 2/6] Update .gitignore and spec fixtures --- .gitignore | 2 +- Fixtures/TestProject/.DS_Store | Bin 0 -> 6148 bytes .../TestProject/App_iOS/Base.lproj/.DS_Store | 0 .../TestProject/App_iOS/Base.lproj/excluded-file | 0 Tests/Fixtures/TestProject/spec.yml | 2 ++ 5 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Fixtures/TestProject/.DS_Store create mode 100644 Tests/Fixtures/TestProject/App_iOS/Base.lproj/.DS_Store create mode 100644 Tests/Fixtures/TestProject/App_iOS/Base.lproj/excluded-file diff --git a/.gitignore b/.gitignore index fbb30c55..43c7ce33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.DS_Store +./.DS_Store /.build /Packages xcuserdata diff --git a/Fixtures/TestProject/.DS_Store b/Fixtures/TestProject/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4e5e1b682fcc84f1f68f5dbb943b3227ef0bb302 GIT binary patch literal 6148 zcmeHKO-jR15T2)56y0bn=nX z?W}f(GvEyTHwO6b9@8oA>@Bo;f0tC!HGCOv^acu8SE>%bq1UPXW)|o{yxM|#>B8zlurkYv;e>eZV`;Rm*AM# zFfptZF#`!23e?bGEk@9A_+wj_7}km!PQjXwU?&IbP=cI}{bN~9AyIVe3^)UA26pvv z$n}5negEGM@+W7&8Q3ZYLX^(ZF;cSH+DVRUZ4AADvhccEQ9@v>9Ls=9@gY55#{2ga$Xxz@IYk0pvY@s{jB1 literal 0 HcmV?d00001 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/spec.yml b/Tests/Fixtures/TestProject/spec.yml index 70f127b9..adba50ce 100644 --- a/Tests/Fixtures/TestProject/spec.yml +++ b/Tests/Fixtures/TestProject/spec.yml @@ -29,6 +29,8 @@ targets: name: App compilerFlags: - "-Werror" + excludes: + - "**/excluded-file" - path: StandaloneFiles/Standalone.swift - FileGroup/UnderFileGroup - Resources/MyBundle.bundle From 5da20cd570d17effe753f99f620f67bebe1a7c78 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:18:44 +0900 Subject: [PATCH 3/6] improve scope --- Sources/XcodeGenKit/SourceGenerator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index b027aa46..4289a78b 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -188,7 +188,7 @@ class SourceGenerator { return variantGroup } - func getSourceExcludes(targetSource: TargetSource) -> [Path] { + private func getSourceExcludes(targetSource: TargetSource) -> [Path] { let rootSourcePath = spec.basePath + targetSource.path return targetSource.excludes.map { From 5ff5dfd9449402bc156edf8d9b0457662adddb86 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:26:56 +0900 Subject: [PATCH 4/6] Leave NOTE in .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 43c7ce33..efb14e67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +# NOTE: Do not ignore .DS_Store for test fixtures. +# .DS_Store ./.DS_Store + /.build /Packages xcuserdata From 8220a891b21a2f69c584b676b72a5dcc1c27f563 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:28:43 +0900 Subject: [PATCH 5/6] Add additional .DS_Store fixtures --- Tests/Fixtures/TestProject/.DS_Store | 0 Tests/Fixtures/TestProject/App_iOS/.DS_Store | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tests/Fixtures/TestProject/.DS_Store create mode 100644 Tests/Fixtures/TestProject/App_iOS/.DS_Store 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 From 3ad9270f1ed53dc4d15a5ee72edb40f8affaf7bd Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Feb 2018 05:30:03 +0900 Subject: [PATCH 6/6] improve test coverage --- Tests/Fixtures/TestProject/App_iOS/excluded-file | 0 Tests/Fixtures/TestProject/excluded-file | 0 Tests/Fixtures/TestProject/spec.yml | 1 + 3 files changed, 1 insertion(+) create mode 100644 Tests/Fixtures/TestProject/App_iOS/excluded-file create mode 100644 Tests/Fixtures/TestProject/excluded-file 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 adba50ce..35949491 100644 --- a/Tests/Fixtures/TestProject/spec.yml +++ b/Tests/Fixtures/TestProject/spec.yml @@ -31,6 +31,7 @@ targets: - "-Werror" excludes: - "**/excluded-file" + - "excluded-file" - path: StandaloneFiles/Standalone.swift - FileGroup/UnderFileGroup - Resources/MyBundle.bundle