Handle the scenario where several sources glob patterns match the same paths (#388)

* Handle the scenario where several sources glob patterns match the same paths

* Update changelog

* Reduce verbosity of the tests using sets
This commit is contained in:
Pedro Piñera Buendía 2019-06-05 09:01:03 -07:00 committed by GitHub
parent f0c5b598ff
commit dc2edcbb31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
- Ensuring the correct default settings provider dependency is used https://github.com/tuist/tuist/pull/389 by @kwridan
- Fixing build settings repeated same value https://github.com/tuist/tuist/pull/391 @platonsi
- Duplicated files in the sources build phase when different glob patterns match the same files https://github.com/tuist/tuist/pull/388 by @pepibumur.
## 0.15.0

View File

@ -95,14 +95,16 @@ public class Target: Equatable {
}
public static func sources(projectPath: AbsolutePath, sources: [(glob: String, compilerFlags: String?)]) throws -> [Target.SourceFile] {
return sources.flatMap { source in
var sourceFiles: [AbsolutePath: Target.SourceFile] = [:]
sources.forEach { source in
projectPath.glob(source.glob).filter { path in
if let `extension` = path.extension, Target.validSourceExtensions.contains(`extension`) {
return true
}
return false
}.map { (path: $0, compilerFlags: source.compilerFlags) }
}.forEach { sourceFiles[$0] = (path: $0, compilerFlags: source.compilerFlags) }
}
return Array(sourceFiles.values)
}
public static func isResource(path: AbsolutePath, fileHandler: FileHandling) -> Bool {

View File

@ -62,17 +62,21 @@ final class TargetTests: XCTestCase {
// When
let sources = try Target.sources(projectPath: fileHandler.currentPath,
sources: [(glob: "sources/**", compilerFlags: nil)])
sources: [
(glob: "sources/**", compilerFlags: nil),
(glob: "sources/**", compilerFlags: nil),
])
// Then
let relativeSources = sources.map { $0.path.relative(to: fileHandler.currentPath).pathString }
XCTAssertEqual(relativeSources, [
XCTAssertEqual(Set(relativeSources), Set([
"sources/a.swift",
"sources/b.m",
"sources/c.mm",
"sources/d.c",
"sources/e.cpp",
])
]))
}
func test_resources() throws {

View File

@ -229,6 +229,8 @@ default: ""
<Message info title="ExpressibleByStringLiteral and ExpressibleByArrayLiteral" description="The list of source files can be initialized with a string that represents the glob pattern, or an array of strings, which represents a list of glob patterns. In both cases the comiler flags will have no value."/>
<Message info title="Patterns matching the same paths" description="If multiple patterns match the same paths, the latest one takes preference over the others. That also means that the latest compiler flags will be applied."/>
### Source file glob
It represents a glob pattern that refers to source files and the compiler flags *(if any)* to be set in the build phase: