Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't deduplicate files in include with different paths but a same name #849

Merged
merged 3 commits into from Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
- Implicitly include bundles in the Copy Bundle Resources build phase. [#838](https://github.com/yonaskolb/XcodeGen/pull/838) @skirchmeier
- Fixed dumping a project manifest which contains an array of project references @paciej00
- Generate correct PBXTargetDependency for external targets. [#843](https://github.com/yonaskolb/XcodeGen/pull/843) @ileitch
- Don't deduplicate files in `include` with different path but same name. [#849](https://github.com/yonaskolb/XcodeGen/pull/849) @akkyie

## 2.15.1

Expand Down
20 changes: 10 additions & 10 deletions Sources/ProjectSpec/SpecFile.swift
Expand Up @@ -8,7 +8,7 @@ public struct SpecFile {
public let jsonDictionary: JSONDictionary
public let subSpecs: [SpecFile]

private let filename: String
private let filePath: Path

fileprivate struct Include {
let path: Path
Expand Down Expand Up @@ -41,34 +41,34 @@ public struct SpecFile {
}

public init(path: Path) throws {
try self.init(filename: path.lastComponent, basePath: path.parent())
try self.init(filePath: path, basePath: path.parent())
}

public init(filename: String, jsonDictionary: JSONDictionary, basePath: Path = "", relativePath: Path = "", subSpecs: [SpecFile] = []) {
public init(filePath: Path, jsonDictionary: JSONDictionary, basePath: Path = "", relativePath: Path = "", subSpecs: [SpecFile] = []) {
self.basePath = basePath
self.relativePath = relativePath
self.jsonDictionary = jsonDictionary
self.subSpecs = subSpecs
self.filename = filename
self.filePath = filePath
}

private init(include: Include, basePath: Path, relativePath: Path) throws {
let basePath = include.relativePaths ? (basePath + relativePath) : (basePath + relativePath + include.path.parent())
let relativePath = include.relativePaths ? include.path.parent() : Path()

try self.init(filename: include.path.lastComponent, basePath: basePath, relativePath: relativePath)
try self.init(filePath: include.path, basePath: basePath, relativePath: relativePath)
}

private init(filename: String, basePath: Path, relativePath: Path = "") throws {
let path = basePath + relativePath + filename
private init(filePath: Path, basePath: Path, relativePath: Path = "") throws {
let path = basePath + relativePath + filePath.lastComponent
let jsonDictionary = try SpecFile.loadDictionary(path: path)

let includes = Include.parse(json: jsonDictionary["include"])
let subSpecs: [SpecFile] = try includes.map { include in
try SpecFile(include: include, basePath: basePath, relativePath: relativePath)
}

self.init(filename: filename, jsonDictionary: jsonDictionary, basePath: basePath, relativePath: relativePath, subSpecs: subSpecs)
self.init(filePath: filePath, jsonDictionary: jsonDictionary, basePath: basePath, relativePath: relativePath, subSpecs: subSpecs)
}

static func loadDictionary(path: Path) throws -> JSONDictionary {
Expand Down Expand Up @@ -97,7 +97,7 @@ public struct SpecFile {
}

func mergedDictionary(set mergedTargets: inout Set<String>) -> JSONDictionary {
let name = (basePath + relativePath + Path(filename)).description
let name = filePath.description

guard !mergedTargets.contains(name) else { return [:] }
mergedTargets.insert(name)
Expand All @@ -116,7 +116,7 @@ public struct SpecFile {

let jsonDictionary = Project.pathProperties.resolvingPaths(in: self.jsonDictionary, relativeTo: relativePath)
return SpecFile(
filename: filename,
filePath: filePath,
jsonDictionary: jsonDictionary,
relativePath: self.relativePath,
subSpecs: subSpecs.map { $0.resolvingPaths(relativeTo: relativePath) }
Expand Down
@@ -0,0 +1,3 @@
name: DuplicatedImportRoot
fileGroups:
- Third
Expand Up @@ -2,6 +2,7 @@ include:
- duplicated_import_transitive.yml
- duplicated_import_root.yml
- duplicated_import_root.yml
- different_path/duplicated_import_root.yml
name: DuplicatedImportDependent
targets:
IncludedTarget:
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProjectSpecTests/SpecLoadingTests.swift
Expand Up @@ -16,7 +16,7 @@ class SpecLoadingTests: XCTestCase {
let path = fixturePath + "duplicated_include/duplicated_import_sut.yml"
let project = try loadSpec(path: path)

try expect(project.fileGroups) == ["First", "Second"]
try expect(project.fileGroups) == ["First", "Second", "Third"]

let sutTarget = project.targets.first
try expect(sutTarget?.sources) == [TargetSource(path: "template")]
Expand Down