// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation import llbuild2fx extension Keys.SourceTree { /// Narrows a source tree to just the transitive dependencies of a given unit struct NarrowToUnit: BuildKey { let sourceTreeId: LLBDataID let unitName: UnitName typealias ValueType = LLBDataID static let versionDependencies: [any FXVersioning.Type] = [GetDependencies.self, GetUnitMap.self] func computeValue(_ ctx: BuildContext) async throws -> ValueType { let dependencies = try await ctx.request(GetDependencies(sourceTreeId: sourceTreeId, unitName: unitName)) let unitMap = try await ctx.request(GetUnitMap(sourceTreeId: sourceTreeId)) var sourceTree = try await LLBCASFileTree.load(id: sourceTreeId, in: ctx) for (unitName, unitInfo) in unitMap.units { if !dependencies.contains(unitName) { sourceTree = try await sourceTree.remove(path: unitInfo.path, in: ctx) } } return sourceTree.id } } }