Skip to content

Commit e862cc4

Browse files
authored
Fix caching for unused platforms (#6824)
1 parent 8336a9f commit e862cc4

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

Sources/TuistCore/Graph/GraphTraverser.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ public class GraphTraverser: GraphTraversing {
919919
.map { GraphDependency.target(name: $0.target.name, path: $0.project.path) }
920920
)
921921

922+
let externalTargetSupportedPlatforms = externalTargetSupportedPlatforms()
923+
922924
let allTargetExternalDependendedUponTargets = filterDependencies(
923925
from: graphDependenciesWithExternalDependencies
924926
)
@@ -929,7 +931,14 @@ public class GraphTraverser: GraphTraversing {
929931
else {
930932
return nil
931933
}
932-
return GraphTarget(path: path, target: target, project: project)
934+
let graphTarget = GraphTarget(path: path, target: target, project: project)
935+
936+
if externalTargetSupportedPlatforms[graphTarget]?.isEmpty == false {
937+
return graphTarget
938+
} else {
939+
return nil
940+
}
941+
933942
} else {
934943
return nil
935944
}

Tests/TuistCoreTests/Graph/GraphTraverserTests.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4692,6 +4692,59 @@ final class GraphTraverserTests: TuistUnitTestCase {
46924692
XCTAssertEqual(got, Set([GraphTarget(path: packageProject.path, target: packageDevProduct, project: packageProject)]))
46934693
}
46944694

4695+
func test_orphanExternalDependencies_when_a_dependency_condition_platforms_are_not_used_downstream() throws {
4696+
// Given
4697+
let app = Target.test(name: "App", destinations: [.iPhone], product: .app)
4698+
let project = Project.test(path: try! AbsolutePath(validating: "/App"), targets: [app])
4699+
let appDependency = GraphDependency.target(name: app.name, path: project.path)
4700+
let directPackageProduct = Target.test(
4701+
name: "DirectPackage",
4702+
destinations: [.iPhone],
4703+
product: .app
4704+
)
4705+
let packageProject = Project.test(
4706+
path: try! AbsolutePath(validating: "/Package"),
4707+
name: "Package",
4708+
targets: [directPackageProduct],
4709+
isExternal: true
4710+
)
4711+
let directPackageProductDependency = GraphDependency.target(
4712+
name: directPackageProduct.name,
4713+
path: packageProject.path
4714+
)
4715+
4716+
let graph = Graph.test(
4717+
path: project.path,
4718+
projects: [project.path: project, packageProject.path: packageProject],
4719+
dependencies: [
4720+
appDependency: Set([directPackageProductDependency]),
4721+
],
4722+
dependencyConditions: [
4723+
GraphEdge(
4724+
from: appDependency,
4725+
to: directPackageProductDependency
4726+
): try XCTUnwrap(.when([.macos])),
4727+
]
4728+
)
4729+
4730+
// When
4731+
let got = GraphTraverser(graph: graph).allOrphanExternalTargets()
4732+
4733+
// Then
4734+
XCTAssertEqual(
4735+
got,
4736+
Set(
4737+
[
4738+
GraphTarget(
4739+
path: packageProject.path,
4740+
target: directPackageProduct,
4741+
project: packageProject
4742+
),
4743+
]
4744+
)
4745+
)
4746+
}
4747+
46954748
func test_targetsWithExternalDependencies() {
46964749
// Given
46974750
let app = Target.test(name: "App", destinations: [.iPhone], product: .app)

0 commit comments

Comments
 (0)