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 struct DependencyGraphOfSourceTree: BuildKey { 11 typealias ValueType = Graph<UnitName> 12 13 let sourceTreeId: LLBDataID 14 static let versionDependencies: [any FXVersioning.Type] = [Keys.UnitMapOfSourceTree.self, Keys.BlobImports.self] 15 16 func computeValue(_ ctx: BuildContext<Self>) async throws -> Graph<UnitName> { 17 let unitMap = try await ctx.request(Keys.UnitMapOfSourceTree(sourceTreeId: sourceTreeId)) 18 var edges: [UnitName: Set<UnitName>] = [:] 19 20 for (unitName, unitInfo) in unitMap.units { 21 if edges[unitName] == nil { edges[unitName] = [] } 22 let imports = try await ctx.request(Keys.BlobImports(blobId: unitInfo.blobId)) 23 for importedUnitName in imports { 24 edges[unitName]!.insert(importedUnitName) 25 } 26 } 27 28 return Graph(edges: edges) 29 } 30 } 31}