Skip to content

Commit

Permalink
Cleanup some code and fix lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmxav committed Jul 10, 2024
1 parent 2f9ab53 commit c73b3c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
6 changes: 4 additions & 2 deletions Sources/GenIR/CompilerCommandRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/GenIR/GenIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ let programName = CommandLine.arguments.first!

let postprocessor = try OutputPostprocessor(
archive: archive,
output:tempDirectory,
output: tempDirectory,
graph: graph
)

Expand Down
2 changes: 1 addition & 1 deletion Sources/GenIR/PIFCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
64 changes: 30 additions & 34 deletions Sources/GenIR/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c73b3c4

Please sign in to comment.