Skip to content

Include host triple test modules in ResolvedPackage #7493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1050,13 +1050,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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be ordered.


/// 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