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