diff --git a/PIF/Sources/PIFSupport/PIF.swift b/PIF/Sources/PIFSupport/PIF.swift index db57d0b..48d8145 100644 --- a/PIF/Sources/PIFSupport/PIF.swift +++ b/PIF/Sources/PIFSupport/PIF.swift @@ -306,8 +306,7 @@ public enum PIF { case FileReference.type: return try childrenContainer.decode(FileReference.self) default: - // TODO: use logger here - print("unknown reference type: \(child.type ?? "")") + logger.debug("unknown reference type: \(child.type ?? "")") return nil } } @@ -508,8 +507,7 @@ public enum PIF { case ResourcesBuildPhase.type: return try container.decode(ResourcesBuildPhase.self) default: - // TODO: replace with logger - print("unknown build phase: \(type)") + logger.debug("unknown build phase: \(type)") return nil // TODO: we should probably handle these: /* diff --git a/PIF/Sources/PIFSupport/PIFSupport.swift b/PIF/Sources/PIFSupport/PIFSupport.swift index 2b8665a..46b1857 100644 --- a/PIF/Sources/PIFSupport/PIFSupport.swift +++ b/PIF/Sources/PIFSupport/PIFSupport.swift @@ -1,4 +1,7 @@ import Foundation +import Logging + +var logger: Logger! public class PIFParser { private let cachePath: URL @@ -8,7 +11,8 @@ public class PIFParser { case workspaceNotFound } - public init(cachePath: URL) throws { + public init(cachePath: URL, logger log: Logger) throws { + logger = log self.cachePath = cachePath let data = try Data(contentsOf: try Self.workspacePath(in: cachePath)) diff --git a/Sources/GenIR/Dependency Graph/DependencyGraph.swift b/Sources/GenIR/Dependency Graph/DependencyGraph.swift index 7552665..e1cd9e6 100644 --- a/Sources/GenIR/Dependency Graph/DependencyGraph.swift +++ b/Sources/GenIR/Dependency Graph/DependencyGraph.swift @@ -44,24 +44,6 @@ class DependencyGraph { return depthFirstSearch(startingAt: node) } - func toDot(_ path: String) throws { - var contents = "digraph DependencyGraph {\n" - - for node in nodes.values { - for edge in node.edges.filter({ $0.relationship == .dependency }) { - func dotSanitized(for name: String) -> String { - name - .replacingOccurrences(of: "-", with: "_") - .replacingOccurrences(of: ".", with: "_") - } - contents.append("\(dotSanitized(for: node.valueName)) -> \(dotSanitized(for: edge.to.valueName))\n") - } - } - - contents.append("}") - try contents.write(toFile: path, atomically: true, encoding: .utf8) - } - /// Perform a depth-first search starting at the provided node /// - Parameter node: the node whose children to search through /// - Returns: an array of nodes ordered by a depth-first search approach @@ -76,9 +58,8 @@ class DependencyGraph { logger.debug("visited: \(visited)") for edge in node.edges where edge.relationship == .dependency { - logger.debug("edge to: \(edge.to)") if visited.insert(edge.to).inserted { - logger.debug("inserted, recursing") + logger.debug("edge to: \(edge.to)") depthFirst(node: edge.to) } else { logger.debug("edge already in visited: \(visited)") @@ -92,6 +73,19 @@ class DependencyGraph { depthFirst(node: node) return chain } + + func toDot(_ path: String) throws { + var contents = "digraph DependencyGraph {\n" + + for node in nodes.values { + for edge in node.edges.filter({ $0.relationship == .dependency }) { + contents.append("\"\(node.valueName)\" -> \"\(edge.to.valueName)\"\n") + } + } + + contents.append("}") + try contents.write(toFile: path, atomically: true, encoding: .utf8) + } } extension DependencyGraph: CustomStringConvertible { diff --git a/Sources/GenIR/PIFCache.swift b/Sources/GenIR/PIFCache.swift index d8e22b3..6737d8a 100644 --- a/Sources/GenIR/PIFCache.swift +++ b/Sources/GenIR/PIFCache.swift @@ -16,7 +16,7 @@ class PIFCache { self.pifCachePath = try Self.pifCachePath(in: buildCache) do { - let cache = try PIFParser(cachePath: pifCachePath) + let cache = try PIFParser(cachePath: pifCachePath, logger: logger) workspace = cache.workspace } catch { throw Error.pifError(error) diff --git a/Sources/GenIR/Target.swift b/Sources/GenIR/Target.swift index d32fcf6..0f26a8a 100644 --- a/Sources/GenIR/Target.swift +++ b/Sources/GenIR/Target.swift @@ -39,7 +39,7 @@ extension Target { extension Target: NodeValue { var value: Self { self } - var valueName: String { name } + var valueName: String { productName } } extension Target: Hashable {