Merge pull request #238 from yonaskolb/ts-exclude-dsstore-bug

sources.excludes wasn't applied for localisedDirectory such as Base.lproj
This commit is contained in:
Yonas Kolb 2018-03-03 09:15:14 +11:00 committed by GitHub
commit cc76e37d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 25 deletions

5
.gitignore vendored
View File

@ -1,4 +1,7 @@
.DS_Store
# NOTE: Do not ignore .DS_Store for test fixtures.
# .DS_Store
./.DS_Store
/.build
/Packages
xcuserdata

BIN
Fixtures/TestProject/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -220,11 +220,11 @@ 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)")
Path.glob("\(rootSourcePath)/\($0)")
.map {
guard $0.isDirectory else {
return [$0]
@ -237,9 +237,7 @@ class SourceGenerator {
.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<Path> = 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<PBXGroup>]) {
throws -> (sourceFiles: [SourceFile], groups: [ObjectReference<PBXGroup>])
{
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<Path> = 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

0
Tests/Fixtures/TestProject/.DS_Store vendored Normal file
View File

View File

View File

View File

@ -29,6 +29,9 @@ targets:
name: App
compilerFlags:
- "-Werror"
excludes:
- "**/excluded-file"
- "excluded-file"
- path: StandaloneFiles/Standalone.swift
- FileGroup/UnderFileGroup
- Resources/MyBundle.bundle