Skip to content

Commit 04bb20f

Browse files
committed
Merge branch 'main' of https://github.com/tuist/tuist into generate-package-resolved-with-transitive-remote
2 parents 09c4048 + a6922e9 commit 04bb20f

11 files changed

Lines changed: 102 additions & 30 deletions

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
}

Sources/TuistKit/Services/BuildService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final class BuildService {
7575
) async throws {
7676
let graph: Graph
7777
let config = try await configLoader.loadConfig(path: path)
78-
let cacheStorage = try cacheStorageFactory.cacheStorage(config: config)
78+
let cacheStorage = try await cacheStorageFactory.cacheStorage(config: config)
7979
let generator = generatorFactory.building(
8080
config: config,
8181
configuration: configuration,

Sources/TuistKit/Services/CleanService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ final class CleanService {
124124
try await fileSystem.exists(directory)
125125
{
126126
try await fileSystem.remove(directory)
127+
try await fileSystem.makeDirectory(at: directory)
127128
logger.notice("Successfully cleaned artifacts at path \(directory.pathString)", metadata: .success)
128129
} else {
129130
logger.notice("There's nothing to clean for \(category.defaultValueDescription)")

Sources/TuistKit/Services/GenerateService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class GenerateService {
4848
let timer = clock.startTimer()
4949
let path = try self.path(path)
5050
let config = try await configLoader.loadConfig(path: path)
51-
let cacheStorage = try cacheStorageFactory.cacheStorage(config: config)
51+
let cacheStorage = try await cacheStorageFactory.cacheStorage(config: config)
5252
let generator = generatorFactory.generation(
5353
config: config,
5454
sources: sources,

Sources/TuistKit/Services/TestService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ final class TestService { // swiftlint:disable:this type_body_length
192192
}
193193
// Load config
194194
let config = try await configLoader.loadConfig(path: path)
195-
let cacheStorage = try cacheStorageFactory.cacheStorage(config: config)
195+
let cacheStorage = try await cacheStorageFactory.cacheStorage(config: config)
196196

197197
let testGenerator = generatorFactory.testing(
198198
config: config,

Sources/TuistServer/Cache/CacheStorageFactorying.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import XcodeGraph
66

77
@Mockable
88
public protocol CacheStorageFactorying {
9-
func cacheStorage(config: Config) throws -> CacheStoring
9+
func cacheStorage(config: Config) async throws -> CacheStoring
1010
}

Tests/TuistAutomationAcceptanceTests/TestAcceptanceTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ final class TestAcceptanceTests: TuistAcceptanceTestCase {
1616
try await run(TestCommand.self, "App", "--", "-testLanguage", "en")
1717
}
1818

19+
func test_with_ios_app_with_frameworks() async throws {
20+
try await setUpFixture(.iosAppWithFrameworks)
21+
try await run(TestCommand.self)
22+
}
23+
1924
func test_with_app_with_test_plan() async throws {
2025
try await setUpFixture(.appWithTestPlan)
2126
try await run(TestCommand.self)

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)

Tests/TuistKitTests/Services/CleanServiceTests.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ final class CleanServiceTests: TuistUnitTestCase {
5656

5757
func test_run_with_category_cleans_category() async throws {
5858
// Given
59-
let cachePaths = try createFolders(["tuist/Manifests", "tuist/ProjectDescriptionHelpers"])
59+
let rootDirectory = try temporaryPath()
60+
let cachePaths = try await createFiles(["tuist/Manifests/manifest.json", "tuist/ProjectDescriptionHelpers/File.swift"])
6061

61-
let cachePath = cachePaths[0].parentDirectory.parentDirectory
6262
given(cacheDirectoriesProvider)
6363
.cacheDirectory(for: .value(.manifests))
64-
.willReturn(cachePaths[0])
64+
.willReturn(cachePaths[0].parentDirectory)
6565
given(cacheDirectoriesProvider)
6666
.cacheDirectory(for: .value(.projectDescriptionHelpers))
67-
.willReturn(cachePaths[1])
67+
.willReturn(cachePaths[1].parentDirectory)
6868
given(rootDirectoryLocator)
6969
.locate(from: .any)
70-
.willReturn(cachePath)
70+
.willReturn(rootDirectory)
7171
given(manifestFilesLocator)
7272
.locatePackageManifest(at: .any)
7373
.willReturn(nil)
@@ -87,19 +87,20 @@ final class CleanServiceTests: TuistUnitTestCase {
8787

8888
func test_run_with_dependencies_cleans_dependencies() async throws {
8989
// Given
90-
let localPaths = try createFolders(["Tuist/.build", "Tuist/ProjectDescriptionHelpers"])
90+
let rootDirectory = try temporaryPath()
91+
let localPaths = try await createFiles(["Tuist/.build/file", "Tuist/ProjectDescriptionHelpers/File.swift"])
9192

9293
given(rootDirectoryLocator)
9394
.locate(from: .any)
94-
.willReturn(localPaths[0].parentDirectory)
95+
.willReturn(rootDirectory)
9596
given(manifestFilesLocator)
9697
.locatePackageManifest(at: .any)
9798
.willReturn(
98-
localPaths[1].parentDirectory
99-
.appending(component: Constants.SwiftPackageManager.packageSwiftName)
99+
rootDirectory
100+
.appending(components: "Tuist", Constants.SwiftPackageManager.packageSwiftName)
100101
)
101102

102-
let cachePath = localPaths[0].parentDirectory.parentDirectory
103+
let cachePath = rootDirectory
103104
given(cacheDirectoriesProvider)
104105
.cacheDirectory()
105106
.willReturn(cachePath)
@@ -119,15 +120,16 @@ final class CleanServiceTests: TuistUnitTestCase {
119120

120121
func test_run_with_dependencies_cleans_dependencies_when_package_is_in_root() async throws {
121122
// Given
122-
let localPaths = try createFolders([".build", "Tuist/ProjectDescriptionHelpers"])
123+
let rootDirectory = try temporaryPath()
124+
let localPaths = try await createFiles([".build/file", "Tuist/ProjectDescriptionHelpers/file"])
123125

124126
given(rootDirectoryLocator)
125127
.locate(from: .any)
126-
.willReturn(localPaths[0].parentDirectory)
128+
.willReturn(rootDirectory)
127129
given(manifestFilesLocator)
128130
.locatePackageManifest(at: .any)
129131
.willReturn(
130-
localPaths[0].parentDirectory
132+
rootDirectory
131133
.appending(component: Constants.SwiftPackageManager.packageSwiftName)
132134
)
133135

@@ -151,11 +153,11 @@ final class CleanServiceTests: TuistUnitTestCase {
151153

152154
func test_run_without_category_cleans_all() async throws {
153155
// Given
154-
let cachePaths = try createFolders(["tuist/Manifests"])
156+
let cachePaths = try await createFiles(["tuist/Manifests/hash"])
155157

156158
given(cacheDirectoriesProvider)
157159
.cacheDirectory(for: .any)
158-
.willReturn(cachePaths[0])
160+
.willReturn(cachePaths[0].parentDirectory)
159161

160162
let projectPath = try temporaryPath()
161163
given(rootDirectoryLocator)
@@ -171,6 +173,8 @@ final class CleanServiceTests: TuistUnitTestCase {
171173
components: Constants.SwiftPackageManager.packageBuildDirectoryName
172174
)
173175
try fileHandler.createFolder(swiftPackageManagerBuildPath)
176+
let swiftPackageManagerBuildFile = swiftPackageManagerBuildPath.appending(component: "file")
177+
try await fileSystem.touch(swiftPackageManagerBuildFile)
174178

175179
// When
176180
try await subject.run(
@@ -182,8 +186,8 @@ final class CleanServiceTests: TuistUnitTestCase {
182186
// Then
183187
let cachePathExists = try await fileSystem.exists(cachePaths[0])
184188
XCTAssertFalse(cachePathExists)
185-
let swiftPackageManagerBuildPathExists = try await fileSystem.exists(swiftPackageManagerBuildPath)
186-
XCTAssertFalse(swiftPackageManagerBuildPathExists)
189+
let swiftPackageManagerBuildFileExists = try await fileSystem.exists(swiftPackageManagerBuildFile)
190+
XCTAssertFalse(swiftPackageManagerBuildFileExists)
187191
}
188192

189193
func test_run_with_remote() async throws {

fixtures/ios_app_with_frameworks/App/Sources/AppDelegate.swift renamed to fixtures/ios_app_with_frameworks/App/Sources/MyApp.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ struct MyApp: SwiftUI.App {
1010
let framework2Objc = MyPublicClass()
1111

1212
print(hello())
13-
print("AppDelegate -> \(framework1.hello())")
14-
print("AppDelegate -> \(framework1.helloFromFramework2())")
15-
print("AppDelegate -> \(framework2.hello())")
16-
print("AppDelegate -> \(framework2Objc.hello())")
13+
print("MyApp -> \(framework1.hello())")
14+
print("MyApp -> \(framework1.helloFromFramework2())")
15+
print("MyApp -> \(framework2.hello())")
16+
print("MyApp -> \(framework2Objc.hello())")
1717
}
1818

1919
var body: some Scene {
@@ -23,6 +23,6 @@ struct MyApp: SwiftUI.App {
2323
}
2424

2525
func hello() -> String {
26-
"AppDelegate.hello()"
26+
"MyApp.hello()"
2727
}
2828
}

0 commit comments

Comments
 (0)