Skip to content

Commit

Permalink
Revert "Embed external xcframeworks regardless of linking type (#6217)…
Browse files Browse the repository at this point in the history
…" (#6237)

This reverts commit 3bebe42.
  • Loading branch information
fortmarek committed Apr 26, 2024
1 parent 492b350 commit e04d3ce
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 193 deletions.
10 changes: 4 additions & 6 deletions Sources/TuistCore/Graph/GraphLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ public final class GraphLoader: GraphLoading {
cache: cache
)

case let .xcframework(frameworkPath, status, _, isExternal):
case let .xcframework(frameworkPath, status, _):
return try loadXCFramework(
path: frameworkPath,
cache: cache,
status: status,
isExternal: isExternal
status: status
)

case let .sdk(name, status, _):
Expand Down Expand Up @@ -250,8 +249,7 @@ public final class GraphLoader: GraphLoading {
private func loadXCFramework(
path: AbsolutePath,
cache: Cache,
status: FrameworkStatus,
isExternal: Bool
status: FrameworkStatus
) throws -> GraphDependency {
if let loaded = cache.xcframeworks[path] {
return loaded
Expand All @@ -268,7 +266,7 @@ public final class GraphLoader: GraphLoading {
linking: metadata.linking,
mergeable: metadata.mergeable,
status: metadata.status,
isExternal: isExternal
macroPath: metadata.macroPath
))
cache.add(xcframework: xcframework, at: path)
return xcframework
Expand Down
6 changes: 3 additions & 3 deletions Sources/TuistCore/Graph/GraphTraverser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public class GraphTraverser: GraphTraversing {
/// Precompiled frameworks
var precompiledFrameworks = filterDependencies(
from: .target(name: name, path: path),
test: { $0.isPrecompiledAndEmbeddable },
test: { $0.isPrecompiledDynamicAndLinkable },
skip: or(canDependencyEmbedProducts, isDependencyPrecompiledMacro)
)
// Skip merged precompiled libraries from merging into the runnable binary
Expand Down Expand Up @@ -362,7 +362,7 @@ public class GraphTraverser: GraphTraversing {
}

let precompiledLibrariesAndFrameworks = Set(precompiled + precompiledDependencies)
.filter(\.isPrecompiledAndEmbeddable)
.filter(\.isPrecompiledDynamicAndLinkable)
.compactMap { dependencyReference(to: $0, from: targetGraphDependency) }

references.formUnion(precompiledLibrariesAndFrameworks)
Expand Down Expand Up @@ -525,7 +525,7 @@ public class GraphTraverser: GraphTraversing {
let from = GraphDependency.target(name: name, path: path)
let precompiledFrameworksPaths = filterDependencies(
from: from,
test: { $0.isPrecompiledAndEmbeddable },
test: { $0.isPrecompiledDynamicAndLinkable },
skip: canDependencyEmbedProducts
)
.lazy
Expand Down
9 changes: 3 additions & 6 deletions Sources/TuistCore/NodeLoaders/XCFrameworkLoader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Mockable
import TSCBasic
import TuistGraph
import TuistSupport
Expand All @@ -24,13 +23,11 @@ enum XCFrameworkLoaderError: FatalError, Equatable {
}
}

@Mockable
public protocol XCFrameworkLoading {
/// Reads an existing xcframework and returns its in-memory representation, `GraphDependency.xcframework`.
/// - Parameter path: Path to the .xcframework.
/// - Parameter status: `.optional` to weakly reference the .xcframework.
/// - Parameter isExternal: Whether the XCFramework comes from an external SPM project
func load(path: AbsolutePath, status: FrameworkStatus, isExternal: Bool) throws -> GraphDependency
func load(path: AbsolutePath, status: FrameworkStatus) throws -> GraphDependency
}

public final class XCFrameworkLoader: XCFrameworkLoading {
Expand All @@ -47,7 +44,7 @@ public final class XCFrameworkLoader: XCFrameworkLoading {
self.xcframeworkMetadataProvider = xcframeworkMetadataProvider
}

public func load(path: AbsolutePath, status: FrameworkStatus, isExternal: Bool) throws -> GraphDependency {
public func load(path: AbsolutePath, status: FrameworkStatus) throws -> GraphDependency {
guard FileHandler.shared.exists(path) else {
throw XCFrameworkLoaderError.xcframeworkNotFound(path)
}
Expand All @@ -62,7 +59,7 @@ public final class XCFrameworkLoader: XCFrameworkLoading {
linking: metadata.linking,
mergeable: metadata.mergeable,
status: metadata.status,
isExternal: isExternal
macroPath: metadata.macroPath
)
return .xcframework(xcframework)
}
Expand Down
17 changes: 17 additions & 0 deletions Sources/TuistCoreTesting/NodeLoaders/MockXCFrameworkLoader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation
import TSCBasic
import TuistCore
import TuistGraph

public final class MockXCFrameworkLoader: XCFrameworkLoading {
public init() {}

var loadStub: ((AbsolutePath) throws -> GraphDependency)?
public func load(path: AbsolutePath, status: FrameworkStatus) throws -> GraphDependency {
if let loadStub {
return try loadStub(path)
} else {
return .testXCFramework(path: path, status: status)
}
}
}
2 changes: 1 addition & 1 deletion Sources/TuistGenerator/Linter/TargetLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ extension TargetDependency {
return target
case let .framework(path, _, _):
return path.basename
case let .xcframework(path, _, _, _):
case let .xcframework(path, _, _):
return path.basename
case let .library(path, _, _, _):
return path.basename
Expand Down
10 changes: 3 additions & 7 deletions Sources/TuistGraph/Graph/GraphDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public enum GraphDependency: Hashable, CustomStringConvertible, Comparable, Coda
public let linking: BinaryLinking
public let mergeable: Bool
public let status: FrameworkStatus
public let isExternal: Bool

public init(
path: AbsolutePath,
Expand All @@ -18,15 +17,14 @@ public enum GraphDependency: Hashable, CustomStringConvertible, Comparable, Coda
linking: BinaryLinking,
mergeable: Bool,
status: FrameworkStatus,
isExternal: Bool
macroPath _: AbsolutePath?
) {
self.path = path
self.infoPlist = infoPlist
self.primaryBinaryPath = primaryBinaryPath
self.linking = linking
self.mergeable = mergeable
self.status = status
self.isExternal = isExternal
}

public var description: String {
Expand Down Expand Up @@ -208,13 +206,11 @@ public enum GraphDependency: Hashable, CustomStringConvertible, Comparable, Coda
}
}

public var isPrecompiledAndEmbeddable: Bool {
public var isPrecompiledDynamicAndLinkable: Bool {
switch self {
case .macro: return false
case let .xcframework(xcframework):
return xcframework
.linking == .dynamic ||
(xcframework.isExternal && xcframework.infoPlist.libraries.first?.path.extension == "framework")
return xcframework.linking == .dynamic
case let .framework(_, _, _, _, linking, _, _),
let .library(path: _, publicHeaders: _, linking: linking, architectures: _, swiftModuleMap: _):
return linking == .dynamic
Expand Down
8 changes: 4 additions & 4 deletions Sources/TuistGraph/Models/TargetDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum TargetDependency: Equatable, Hashable, Codable {
case target(name: String, condition: PlatformCondition? = nil)
case project(target: String, path: AbsolutePath, condition: PlatformCondition? = nil)
case framework(path: AbsolutePath, status: FrameworkStatus, condition: PlatformCondition? = nil)
case xcframework(path: AbsolutePath, status: FrameworkStatus, condition: PlatformCondition? = nil, isExternal: Bool = false)
case xcframework(path: AbsolutePath, status: FrameworkStatus, condition: PlatformCondition? = nil)
case library(
path: AbsolutePath,
publicHeaders: AbsolutePath,
Expand All @@ -40,7 +40,7 @@ public enum TargetDependency: Equatable, Hashable, Codable {
condition
case .framework(path: _, status: _, condition: let condition):
condition
case .xcframework(path: _, status: _, condition: let condition, _):
case .xcframework(path: _, status: _, condition: let condition):
condition
case .library(path: _, publicHeaders: _, swiftModuleMap: _, condition: let condition):
condition
Expand All @@ -60,8 +60,8 @@ public enum TargetDependency: Equatable, Hashable, Codable {
return .project(target: target, path: path, condition: condition)
case .framework(path: let path, status: let status, condition: _):
return .framework(path: path, status: status, condition: condition)
case .xcframework(path: let path, status: let status, condition: _, isExternal: let isExternal):
return .xcframework(path: path, status: status, condition: condition, isExternal: isExternal)
case .xcframework(path: let path, status: let status, condition: _):
return .xcframework(path: path, status: status, condition: condition)
case .library(path: let path, publicHeaders: let headers, swiftModuleMap: let moduleMap, condition: _):
return .library(path: path, publicHeaders: headers, swiftModuleMap: moduleMap, condition: condition)
case .package(product: let product, type: let type, condition: _):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension GraphDependency {
.appending(try! RelativePath(validating: "Test.xcframework/Test")),
linking: BinaryLinking = .dynamic,
status: FrameworkStatus = .required,
isExternal: Bool = false
macroPath: AbsolutePath? = nil
) -> GraphDependency {
.xcframework(
GraphDependency.XCFramework(
Expand All @@ -49,7 +49,7 @@ extension GraphDependency {
linking: linking,
mergeable: false,
status: status,
isExternal: isExternal
macroPath: macroPath
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension ProjectAutomation.Target {
frameworkStatus = .required
}
return .framework(path: path.pathString, status: frameworkStatus)
case let .xcframework(path, status, _, _):
case let .xcframework(path, status, _):
let frameworkStatus: ProjectAutomation.FrameworkStatus
switch status {
case .optional:
Expand Down
3 changes: 1 addition & 2 deletions Sources/TuistLoader/Loaders/ManifestModelConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public final class ManifestModelConverter: ManifestModelConverting {
try TuistGraph.TargetDependency.from(
manifest: targetDependencyManifest,
generatorPaths: GeneratorPaths(manifestDirectory: path),
externalDependencies: [:], // externalDependencies manifest can't contain other external dependencies,
isExternal: true
externalDependencies: [:] // externalDependencies manifest can't contain other external dependencies,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ extension TuistGraph.Project {
try TuistGraph.Target.from(
manifest: $0,
generatorPaths: generatorPaths,
externalDependencies: externalDependencies,
isExternal: isExternal
externalDependencies: externalDependencies
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ extension TuistGraph.Target {
static func from(
manifest: ProjectDescription.Target,
generatorPaths: GeneratorPaths,
externalDependencies: [String: [TuistGraph.TargetDependency]],
isExternal: Bool
externalDependencies: [String: [TuistGraph.TargetDependency]]
) throws -> TuistGraph.Target {
let name = manifest.name
let destinations = try TuistGraph.Destination.from(destinations: manifest.destinations)
Expand All @@ -44,8 +43,7 @@ extension TuistGraph.Target {
try TuistGraph.TargetDependency.from(
manifest: $0,
generatorPaths: generatorPaths,
externalDependencies: externalDependencies,
isExternal: isExternal
externalDependencies: externalDependencies
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ extension TuistGraph.TargetDependency {
static func from( // swiftlint:disable:this function_body_length
manifest: ProjectDescription.TargetDependency,
generatorPaths: GeneratorPaths,
externalDependencies: [String: [TuistGraph.TargetDependency]],
isExternal: Bool
externalDependencies: [String: [TuistGraph.TargetDependency]]
) throws -> [TuistGraph.TargetDependency] {
switch manifest {
case let .target(name, condition):
Expand Down Expand Up @@ -80,8 +79,7 @@ extension TuistGraph.TargetDependency {
.xcframework(
path: try generatorPaths.resolve(path: path),
status: .from(manifest: status),
condition: condition?.asGraphCondition,
isExternal: isExternal
condition: condition?.asGraphCondition
),
]
case .xctest:
Expand Down
18 changes: 1 addition & 17 deletions Tests/TuistAutomationAcceptanceTests/BuildAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,7 @@ final class BuildAcceptanceTestMultiplatformAppWithSDK: TuistAcceptanceTestCase
try setUpFixture(.multiplatformAppWithSdk)
try await run(InstallCommand.self)
try await run(GenerateCommand.self)
try System.shared.runAndPrint(
[
"/usr/bin/xcrun",
"xcodebuild",
"clean",
"build",
"-scheme",
"App",
"-workspace",
workspacePath.pathString,
"-destination",
"platform=macOS",
"CODE_SIGN_IDENTITY=\"\"",
"CODE_SIGNING_REQUIRED=NO",
"CODE_SIGNING_ALLOWED=NO",
]
)
try await run(BuildCommand.self, "App", "--platform", "macos")
try await run(BuildCommand.self, "App", "--platform", "ios")
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TuistCoreTests/Graph/GraphLoaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ final class GraphLoaderTests: TuistUnitTestCase {
linking: .dynamic,
mergeable: false,
status: .required,
isExternal: false
macroPath: nil
)
),
]),
Expand Down Expand Up @@ -440,7 +440,7 @@ final class GraphLoaderTests: TuistUnitTestCase {
linking: .dynamic,
mergeable: true,
status: .required,
isExternal: false
macroPath: nil
)
),
]),
Expand Down

0 comments on commit e04d3ce

Please sign in to comment.