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 typealias ValueType = LLBDataID 13 14 let sourceTreeId: LLBDataID 15 let unitName: UnitName 16 17 static let versionDependencies: [any FXVersioning.Type] = [TransitiveDependencies.self, UnitMapOfSourceTree.self] 18 19 func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType { 20 let dependencies = try await ctx.request(TransitiveDependencies(sourceTreeId: sourceTreeId, unitName: unitName)) 21 let unitMap = try await ctx.request(UnitMapOfSourceTree(sourceTreeId: sourceTreeId)) 22 23 var sourceTree = try await LLBCASFileTree.load(id: sourceTreeId, in: ctx) 24 for (unitName, unitInfo) in unitMap.units { 25 if !dependencies.contains(unitName) { 26 sourceTree = try await sourceTree.remove(path: unitInfo.path, in: ctx) 27 } 28 } 29 30 return sourceTree.id 31 } 32 } 33}