Skip to content

Commit

Permalink
Add cached artifacts into cache group
Browse files Browse the repository at this point in the history
Adding a new group called Cache that contains the cached artifacts instead of adding them into the Framework group
  • Loading branch information
mustiikhalil committed Mar 11, 2024
1 parent 87cdf10 commit dd86e1f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/TuistGenerator/Generator/ProjectFileElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class ProjectFileElements {
from: sourceRootPath,
fileAbsolutePath: path,
name: path.basename,
toGroup: groups.frameworks,
toGroup: groups.cachedFrameworks,
pbxproj: pbxproj
)
compiled[path] = fileElement
Expand Down
9 changes: 9 additions & 0 deletions Sources/TuistGenerator/Generator/ProjectGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ProjectGroups {
@SortedPBXGroup var sortedMain: PBXGroup
let products: PBXGroup
let frameworks: PBXGroup
let cachedFrameworks: PBXGroup

private let pbxproj: PBXProj
private let projectGroups: [String: PBXGroup]
Expand All @@ -40,12 +41,14 @@ class ProjectGroups {
projectGroups: [(name: String, group: PBXGroup)],
products: PBXGroup,
frameworks: PBXGroup,
cachedFrameworks: PBXGroup,
pbxproj: PBXProj
) {
sortedMain = main
self.projectGroups = Dictionary(uniqueKeysWithValues: projectGroups)
self.products = products
self.frameworks = frameworks
self.cachedFrameworks = cachedFrameworks
self.pbxproj = pbxproj
}

Expand Down Expand Up @@ -98,6 +101,11 @@ class ProjectGroups {
pbxproj.add(object: frameworksGroup)
mainGroup.children.append(frameworksGroup)

/// Cached frameworks
let cacheGroup = PBXGroup(children: [], sourceTree: .group, name: "Cache")
pbxproj.add(object: cacheGroup)
mainGroup.children.append(cacheGroup)

/// Products
let productsGroup = PBXGroup(children: [], sourceTree: .group, name: "Products")
pbxproj.add(object: productsGroup)
Expand All @@ -108,6 +116,7 @@ class ProjectGroups {
projectGroups: projectGroups,
products: productsGroup,
frameworks: frameworksGroup,
cachedFrameworks: cacheGroup,
pbxproj: pbxproj
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,62 @@ final class ProjectFileElementsTests: TuistUnitTestCase {
)

// Then
XCTAssertEqual(groups.frameworks.flattenedChildren, [
XCTAssertEqual(groups.cachedFrameworks.flattenedChildren, [
"Test.framework",
])

let frameworkElement = subject.compiled[frameworkPath]
XCTAssertNotNil(frameworkElement)
XCTAssertEqual(frameworkElement?.sourceTree, .absolute)
XCTAssertEqual(frameworkElement?.path, frameworkPath.pathString)
XCTAssertEqual(frameworkElement?.name, frameworkPath.basename)
}

func test_generateDependencies_when_cacheCompiledArtifacts_and_sdk() throws {
// Given
let pbxproj = PBXProj()
let sourceRootPath = try AbsolutePath(validating: "/a/project/")
let project = Project.test(
path: sourceRootPath,
sourceRootPath: sourceRootPath,
xcodeProjPath: sourceRootPath.appending(component: "Project.xcodeproj")
)
let groups = ProjectGroups.generate(project: project, pbxproj: pbxproj)

let frameworkPath = try cacheDirectoriesProvider.cacheDirectory().appending(component: "Test.framework")
let binaryPath = frameworkPath.appending(component: "Test")

let frameworkDependency = GraphDependencyReference.framework(
path: frameworkPath,
binaryPath: binaryPath,
dsymPath: nil,
bcsymbolmapPaths: [],
linking: .static,
architectures: [.arm64],
product: .framework,
status: .required
)

let sdkPath = try temporaryPath().appending(component: "ARKit.framework")
let sdkStatus: SDKStatus = .required
let sdkSource: SDKSource = .developer
let sdkDependency = GraphDependencyReference.sdk(
path: sdkPath,
status: sdkStatus,
source: sdkSource
)

// When
try subject.generate(
dependencyReferences: [frameworkDependency, sdkDependency],
groups: groups,
pbxproj: pbxproj,
sourceRootPath: sourceRootPath,
filesGroup: .group(name: "Project")
)

// Then
XCTAssertEqual(groups.cachedFrameworks.flattenedChildren, [
"Test.framework",
])

Expand All @@ -851,6 +906,17 @@ final class ProjectFileElementsTests: TuistUnitTestCase {
XCTAssertEqual(frameworkElement?.sourceTree, .absolute)
XCTAssertEqual(frameworkElement?.path, frameworkPath.pathString)
XCTAssertEqual(frameworkElement?.name, frameworkPath.basename)

// Then
XCTAssertEqual(groups.frameworks.flattenedChildren, [
"ARKit.framework",
])

let sdkElement = subject.compiled[sdkPath]
XCTAssertNotNil(sdkElement)
XCTAssertEqual(sdkElement?.sourceTree, .developerDir)
XCTAssertEqual(sdkElement?.path, sdkPath.relative(to: "/").pathString)
XCTAssertEqual(sdkElement?.name, sdkPath.basename)
}

func test_generateDependencies_remoteSwiftPackage_doNotGenerateElements() throws {
Expand Down
8 changes: 7 additions & 1 deletion Tests/TuistGeneratorTests/Generator/ProjectGroupsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class ProjectGroupsTests: XCTestCase {
let main = subject.sortedMain
XCTAssertNil(main.path)
XCTAssertEqual(main.sourceTree, .group)
XCTAssertEqual(main.children.count, 4)
XCTAssertEqual(main.children.count, 5)

XCTAssertNotNil(main.group(named: "Project"))
XCTAssertNil(main.group(named: "Project")?.path)
Expand All @@ -79,6 +79,11 @@ final class ProjectGroupsTests: XCTestCase {
XCTAssertNil(subject.frameworks.path)
XCTAssertEqual(subject.frameworks.sourceTree, .group)

XCTAssertTrue(main.children.contains(subject.cachedFrameworks))
XCTAssertEqual(subject.cachedFrameworks.name, "Cache")
XCTAssertNil(subject.cachedFrameworks.path)
XCTAssertEqual(subject.cachedFrameworks.sourceTree, .group)

XCTAssertTrue(main.children.contains(subject.products))
XCTAssertEqual(subject.products.name, "Products")
XCTAssertNil(subject.products.path)
Expand Down Expand Up @@ -110,6 +115,7 @@ final class ProjectGroupsTests: XCTestCase {
"C",
"A",
"Frameworks",
"Cache",
"Products",
])
}
Expand Down

0 comments on commit dd86e1f

Please sign in to comment.