1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers 2// 3// SPDX-License-Identifier: MPL-2.0 4 5import Foundation 6import TSCBasic 7import llbuild2fx 8 9extension Keys { 10 /// Narrows a source tree to just the transitive dependencies of a given unit 11 struct NarrowSourceTree: BuildKey { 12 struct ValueType: Codable, FXValue { 13 let sourceTreeId: LLBDataID 14 } 15 16 let sourceTreeId: LLBDataID 17 let unitName: UnitName 18 19 static let versionDependencies: [any FXVersioning.Type] = [TransitiveDependencies.self, UnitMapOfSourceTree.self] 20 21 func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType { 22 let dependencies = try await ctx.request(TransitiveDependencies(sourceTreeId: sourceTreeId, unitName: unitName)).dependencies 23 let unitMap = try await ctx.request(UnitMapOfSourceTree(sourceTreeId: sourceTreeId)) 24 25 var sourceTree = try await LLBCASFileTree.load(id: sourceTreeId, in: ctx) 26 for (unitName, unitInfo) in unitMap.units { 27 if !dependencies.contains(unitName) { 28 sourceTree = try await sourceTree.remove(path: unitInfo.path, in: ctx) 29 } 30 } 31 32 return ValueType(sourceTreeId: sourceTree.id) 33 } 34 } 35}