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

๐Ÿ› Fix getting resources from variant group #291

Merged
merged 3 commits into from
Nov 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"test_string" = "stringa di prova";
22 changes: 13 additions & 9 deletions Sources/RugbyFoundation/XcodeProject/Models/BuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ extension BuildPhase {

private extension PBXBuildPhase {
func filePaths() -> [String] {
guard let files else { return [] }
return files.compactMap {
guard let displayName = $0.file?.displayName,
let fullPath = $0.file?.fullPath else { return nil }
// PBXFileElement can't return correct path for PBXVariantGroup
if let variantGroup = $0.file as? PBXVariantGroup {
return variantGroup.fullPath
(files ?? []).flatMap { buildFile -> [String] in
guard let fullPath = buildFile.file?.fullPath else { return [] }

if let variantGroup = buildFile.file as? PBXVariantGroup, let path = variantGroup.path {
// Returning children in group instead of a path to directory
return variantGroup.children.compactMap {
guard let childPath = $0.path else { return nil }
return "\(fullPath)/\(path)/\(childPath)"
}
}

guard let displayName = buildFile.file?.displayName else { return [] }

// Skipping files with a broken reference.
// If the reference is broken, the name is non-relative to a full path.
return fullPath.hasSuffix(displayName) ? fullPath : nil
}.uniqued()
return fullPath.hasSuffix(displayName) ? [fullPath] : []
}
}
}

Expand Down
15 changes: 8 additions & 7 deletions Tests/FoundationTests/XcodeProject/Models/BuildPhaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import XCTest

final class BuildPhaseTests: XCTestCase {
func test_init() throws {
let localPodGroup = PBXGroup(sourceTree: .group, name: "LocalPod", path: "LocalPod")
let developmentPodsGroup = PBXGroup(sourceTree: .sourceRoot, name: "Development Pods")
let developmentPodsGroup = PBXGroup(sourceTree: .sourceRoot, name: "LocalPods")
let localPodGroup = PBXGroup(sourceTree: .group, name: "LocalPod")
localPodGroup.parent = developmentPodsGroup
let resourcesGroup = PBXGroup(sourceTree: .group, name: "Resources", path: "Resources")
let resourcesGroup = PBXGroup(sourceTree: .group, name: "LocalPod", path: "../LocalPods")
resourcesGroup.parent = localPodGroup

// Dummy file without localization
Expand All @@ -35,8 +35,9 @@ final class BuildPhaseTests: XCTestCase {
runOnlyForDeploymentPostprocessing: false
)
let expectedFiles = [
"\(Folder.current.path)/Pods/LocalPod/Resources/dummy.json",
"\(Folder.current.path)/Pods/LocalPod/Resources/Localization"
"\(Folder.current.path)/LocalPods/LocalPod/Resources/dummy.json",
"\(Folder.current.path)/LocalPods/Localization/LocalPod/Resources/ru.lproj/Localizable.strings",
"\(Folder.current.path)/LocalPods/Localization/LocalPod/Resources/en.lproj/Localizable.strings"
]

// Act
Expand All @@ -58,7 +59,7 @@ final class BuildPhaseTests: XCTestCase {
private func dummyJSONStub(parent: PBXGroup) -> PBXFileElement {
let dummyJSON = PBXFileElement.mock(
name: "dummy.json",
path: "dummy.json",
path: "LocalPod/Resources/dummy.json",
parent: parent
)
return dummyJSON
Expand All @@ -78,7 +79,7 @@ final class BuildPhaseTests: XCTestCase {
let localizableStrings = PBXVariantGroup.mock(
children: children,
name: "Localizable.strings",
path: ".",
path: "LocalPod/Resources",
parent: parent
)
return localizableStrings
Expand Down