From c73b3c4d7a6542e2c4b378bb7ee3b23da4d48c7c Mon Sep 17 00:00:00 2001 From: Bryan Xavier <5422569+bmxav@users.noreply.github.com> Date: Wed, 10 Jul 2024 08:30:59 -0400 Subject: [PATCH] Cleanup some code and fix lint issues. --- Sources/GenIR/CompilerCommandRunner.swift | 6 ++- Sources/GenIR/GenIR.swift | 2 +- Sources/GenIR/PIFCache.swift | 2 +- Sources/GenIR/Target.swift | 64 +++++++++++------------ 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Sources/GenIR/CompilerCommandRunner.swift b/Sources/GenIR/CompilerCommandRunner.swift index ae304ba..6e25247 100644 --- a/Sources/GenIR/CompilerCommandRunner.swift +++ b/Sources/GenIR/CompilerCommandRunner.swift @@ -51,12 +51,14 @@ struct CompilerCommandRunner { // Quick, do a hack! try buildCacheManipulator.manipulate() - let totalCommands = commands.reduce(0) { $0 + $1.value.count } + let totalCommands = commands + .map { $0.value.count } + .reduce(0, +) logger.info("Total commands to run: \(totalCommands)") var totalModulesRun = 0 - for target in targets.filter({ $0.containsBitcode }) { + for target in targets.filter({ $0.isBuildable }) { guard let targetCommands = commands[target.name] else { continue } diff --git a/Sources/GenIR/GenIR.swift b/Sources/GenIR/GenIR.swift index 0c2d6af..d996497 100644 --- a/Sources/GenIR/GenIR.swift +++ b/Sources/GenIR/GenIR.swift @@ -152,7 +152,7 @@ let programName = CommandLine.arguments.first! let postprocessor = try OutputPostprocessor( archive: archive, - output:tempDirectory, + output: tempDirectory, graph: graph ) diff --git a/Sources/GenIR/PIFCache.swift b/Sources/GenIR/PIFCache.swift index 1b84f7d..ad6500b 100644 --- a/Sources/GenIR/PIFCache.swift +++ b/Sources/GenIR/PIFCache.swift @@ -231,7 +231,7 @@ struct PIFDependencyProvider: DependencyProviding { // Framework build phase dependencies // NOTE: Previously we just cast this - all of a sudden with pods this is broken // Not the end of the world - just as quick to do a dictionary lookup - let frameworkGUIDs = cache.target(guid: value.guid)? + let frameworkGUIDs = cache.target(guid: value.guid)? .buildPhases .flatMap { $0.buildFiles } .compactMap { diff --git a/Sources/GenIR/Target.swift b/Sources/GenIR/Target.swift index e9ce651..e609d46 100644 --- a/Sources/GenIR/Target.swift +++ b/Sources/GenIR/Target.swift @@ -14,48 +14,44 @@ import DependencyGraph /// `PIF` package will likely be modified so that it is usable within the context of Gen-IR /// directly. class Target { - /// Target identifier. - let guid: String - /// Name of the target. - let name: String - /// The product name refers to the output of this target when it is built or copied into an archive. - let productName: String + /// Target identifier. + let guid: String + /// Name of the target. + let name: String + /// The product name refers to the output of this target when it is built or copied into an archive. + let productName: String - /// Returns true if this target produces bitcode. This is used to determine if this target is buildable. - /// For packages we only use the `PACKAGE-TARGET` for the object file, since this is used by the - /// other targets. - var containsBitcode: Bool { - get { guid == "PACKAGE-TARGET:\(name)" || !guid.hasPrefix("PACKAGE-") } - } + /// Returns true if this target is buildable. For packages we only use the `PACKAGE-TARGET` + /// for the object file, since this is used by the other targets. + let isBuildable: Bool /// Returns true if this target produces a package product that will be included in the archive. /// For simplicity we say this can be anything that is not a `PACKAGE-TARGET`, which will just be /// an object file. The `dynamicTargetVariantGuid` of a `PACKAGE-TARGET` is technically a framework, /// but we are using the `PACKAGE-PRODUCT` for that, which depends on it. - var isPackageProduct: Bool { - get { !guid.hasPrefix("PACKAGE-TARGET:") } - } + let isPackageProduct: Bool - var isSwiftPackage: Bool { - get { guid.hasPrefix("PACKAGE-") } - } + let isSwiftPackage: Bool - init(from baseTarget: PIF.BaseTarget) { - guid = baseTarget.guid - name = baseTarget.name - productName = if let target = baseTarget as? PIF.Target, !target.productName.isEmpty { - target.productName - } else if baseTarget.guid == "PACKAGE-PRODUCT:\(baseTarget.name)" { - // The `PACKAGE-PRODUCT` for a package does not have a product reference name so - // we do not have a proper extension. For now we assume it is a framework and add - // the extension. A better way may be to follow the `dynamicTargetVariantGuid` of - // the `PACKAGE-TARGET` as this appears to provide the correct name if available. - baseTarget.name.appending(".framework") - } else { - // Fallback to the target's name if we are unable to determine a proper product name. - baseTarget.name - } - } + init(from baseTarget: PIF.BaseTarget) { + guid = baseTarget.guid + name = baseTarget.name + productName = if let target = baseTarget as? PIF.Target, !target.productName.isEmpty { + target.productName + } else if baseTarget.guid == "PACKAGE-PRODUCT:\(baseTarget.name)" { + // The `PACKAGE-PRODUCT` for a package does not have a product reference name so + // we do not have a proper extension. For now we assume it is a framework and add + // the extension. A better way may be to follow the `dynamicTargetVariantGuid` of + // the `PACKAGE-TARGET` as this appears to provide the correct name if available. + baseTarget.name.appending(".framework") + } else { + // Fallback to the target's name if we are unable to determine a proper product name. + baseTarget.name + } + isBuildable = guid == "PACKAGE-TARGET:\(name)" || !guid.hasPrefix("PACKAGE-") + isPackageProduct = !guid.hasPrefix("PACKAGE-TARGET:") + isSwiftPackage = guid.hasPrefix("PACKAGE-") + } } extension Target: NodeValue {