Skip to content

Commit

Permalink
Include host triple test modules in ResolvedPackage (swiftlang#7493)
Browse files Browse the repository at this point in the history
Modified `ResolvedModule` build triples were not reflected in
`ResolvedPackage`, which excluded those modules from the build graph.

Verified manually with `swift-foundation` and `swift-testing` packages.
More comprehensive automated tests will be included in a future PR.

Resolves swiftlang#7479.
  • Loading branch information
MaxDesiatov authored and furby-tm committed May 15, 2024
1 parent 5b1b550 commit 61eb171
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Sources/Basics/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public struct InternalError: Error {
private let description: String
public init(_ description: String) {
assertionFailure(description)
self
.description =
self.description =
"Internal error. Please file a bug at https://github.com/apple/swift-package-manager/issues with this info. \(description)"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ package final class SwiftTargetBuildDescription {
/// Path to the bundle generated for this module (if any).
var bundlePath: AbsolutePath? {
if let bundleName = target.underlying.potentialBundleName, needsResourceBundle {
return self.defaultBuildParameters.bundlePath(named: bundleName)
let suffix = self.defaultBuildParameters.suffix(triple: self.target.buildTriple)
return self.defaultBuildParameters.bundlePath(named: bundleName + suffix)
} else {
return .none
return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension LLBuildManifestBuilder {
outputs.append(output)
}

let cmdName = target.target.getLLBuildResourcesCmdName(config: target.buildParameters.buildConfig)
let cmdName = target.target.getLLBuildResourcesCmdName(buildParameters: target.buildParameters)
self.manifest.addPhonyCmd(name: cmdName, inputs: outputs, outputs: [.virtual(cmdName)])

return .virtual(cmdName)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ extension ResolvedModule {
"\(self.name)-\(buildParameters.buildConfig)\(buildParameters.suffix(triple: self.buildTriple)).module"
}

package func getLLBuildResourcesCmdName(config: String) -> String {
"\(self.name)-\(config).module-resources"
package func getLLBuildResourcesCmdName(buildParameters: BuildParameters) -> String {
"\(self.name)-\(buildParameters.buildConfig)\(buildParameters.suffix(triple: self.buildTriple)).module-resources"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ extension Basics.Diagnostic {
extension BuildParameters {
/// Returns a named bundle's path inside the build directory.
func bundlePath(named name: String) -> AbsolutePath {
buildPath.appending(component: name + self.triple.nsbundleExtension)
self.buildPath.appending(component: name + self.triple.nsbundleExtension)
}
}

Expand Down
12 changes: 8 additions & 4 deletions Sources/PackageGraph/ModulesGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1066,13 +1066,17 @@ private final class ResolvedPackageBuilder: ResolvedBuilder<ResolvedPackage> {
}

override func constructImpl() throws -> ResolvedPackage {
return ResolvedPackage(
let products = try self.products.map { try $0.construct() }
var targets = products.reduce(into: IdentifiableSet()) { $0.formUnion($1.targets) }
try targets.formUnion(self.targets.map { try $0.construct() })

return try ResolvedPackage(
underlying: self.package,
defaultLocalization: self.defaultLocalization,
supportedPlatforms: self.supportedPlatforms,
dependencies: try self.dependencies.map{ try $0.construct() },
targets: try self.targets.map{ try $0.construct() },
products: try self.products.map{ try $0.construct() },
dependencies: self.dependencies.map{ try $0.construct() },
targets: targets,
products: products,
registryMetadata: self.registryMetadata,
platformVersionProvider: self.platformVersionProvider
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageGraph/Resolution/ResolvedPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct ResolvedPackage {
public let underlying: Package

/// The targets contained in the package.
public let targets: [ResolvedModule]
public let targets: IdentifiableSet<ResolvedModule>

/// The products produced by the package.
public let products: [ResolvedProduct]
Expand All @@ -58,7 +58,7 @@ public struct ResolvedPackage {
defaultLocalization: String?,
supportedPlatforms: [SupportedPlatform],
dependencies: [ResolvedPackage],
targets: [ResolvedModule],
targets: IdentifiableSet<ResolvedModule>,
products: [ResolvedProduct],
registryMetadata: RegistryReleaseMetadata?,
platformVersionProvider: PlatformVersionProvider
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/ClangTargetBuildDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class ClangTargetBuildDescriptionTests: XCTestCase {
defaultLocalization: nil,
supportedPlatforms: [],
dependencies: [],
targets: [target],
targets: .init([target]),
products: [],
registryMetadata: nil,
platformVersionProvider: .init(implementation: .minimumDeploymentTargetDefault)),
Expand Down
8 changes: 4 additions & 4 deletions Tests/CommandsTests/PackageCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3054,9 +3054,9 @@ final class PackageCommandTests: CommandsTestCase {
let execProducts = context.package.products(ofType: ExecutableProduct.self)
print("execProducts: \\(execProducts.map{ $0.name })")
let swiftTargets = context.package.targets(ofType: SwiftSourceModuleTarget.self)
print("swiftTargets: \\(swiftTargets.map{ $0.name })")
print("swiftTargets: \\(swiftTargets.map{ $0.name }.sorted())")
let swiftSources = swiftTargets.flatMap{ $0.sourceFiles(withSuffix: ".swift") }
print("swiftSources: \\(swiftSources.map{ $0.path.lastComponent })")
print("swiftSources: \\(swiftSources.map{ $0.path.lastComponent }.sorted())")
if let target = target.sourceModule {
print("Module kind of '\\(target.name)': \\(target.kind)")
Expand Down Expand Up @@ -3120,8 +3120,8 @@ final class PackageCommandTests: CommandsTestCase {
do {
let (stdout, _) = try SwiftPM.Package.execute(["print-target-dependencies", "--target", "FifthTarget"], packagePath: packageDir)
XCTAssertMatch(stdout, .contains("execProducts: [\"FifthTarget\"]"))
XCTAssertMatch(stdout, .contains("swiftTargets: [\"ThirdTarget\", \"TestTarget\", \"SecondTarget\", \"FourthTarget\", \"FirstTarget\", \"FifthTarget\"]"))
XCTAssertMatch(stdout, .contains("swiftSources: [\"library.swift\", \"tests.swift\", \"library.swift\", \"library.swift\", \"library.swift\", \"main.swift\"]"))
XCTAssertMatch(stdout, .contains("swiftTargets: [\"FifthTarget\", \"FirstTarget\", \"FourthTarget\", \"SecondTarget\", \"TestTarget\", \"ThirdTarget\"]"))
XCTAssertMatch(stdout, .contains("swiftSources: [\"library.swift\", \"library.swift\", \"library.swift\", \"library.swift\", \"main.swift\", \"tests.swift\"]"))
XCTAssertMatch(stdout, .contains("Module kind of 'FifthTarget': executable"))
}

Expand Down

0 comments on commit 61eb171

Please sign in to comment.