Skip to content
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

Fix DescriptionPackage resolves targets not exported via products #131

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: 2 additions & 1 deletion Sources/ScipioKit/DescriptionPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ extension DescriptionPackage {
// In create mode, all products should be built
// In future update, users will be enable to specify products want to build
let rootPackage = try fetchRootPackage()
let productsToBuild = rootPackage.products
let productNamesToBuild = rootPackage.manifest.products.map { $0.name }
let productsToBuild = rootPackage.products.filter { productNamesToBuild.contains($0.name) }
return Set(productsToBuild.flatMap(\.targets))
case .prepareDependencies:
// In prepare mode, all targets should be built
Expand Down
19 changes: 18 additions & 1 deletion Tests/ScipioKitTests/DescriptionPackageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,31 @@ final class DescriptionPackageTests: XCTestCase {
}

func testBuildProductsInCreateMode() throws {
let rootPath = fixturePath.appendingPathComponent("TestingPackage")
let package = try XCTUnwrap(try DescriptionPackage(
packageDirectory: rootPath.absolutePath,
mode: .createPackage,
onlyUseVersionsFromResolvedFile: false
))
XCTAssertEqual(package.name, "TestingPackage")

XCTAssertEqual(
Set(try package.resolveBuildProducts().map(\.target.name)),
[
"Logging",
"TestingPackage",
]
)
}

func testBinaryBuildProductsInCreateMode() throws {
let rootPath = fixturePath.appendingPathComponent("BinaryPackage")
Copy link
Owner

Choose a reason for hiding this comment

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

The existing test might aim to test whether it can extract binary targets correctly so it's better to remain the existing tests.

Could you make a new test case for this change and rename the existing tests to testBuildProductsForBinaryPackage or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, my reasoning was that BinaryPackage was already involved in the integration tests, unlike TestingPackage, so I felt safer replacing the former. Of course, keeping the previous test in place makes sense for extra peace of mind. Just fixed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you'd like to change the test name. I thought a package couldn't really be binary, unlike its targets (or wrapping them build products).

let package = try XCTUnwrap(try DescriptionPackage(
packageDirectory: rootPath.absolutePath,
mode: .createPackage,
onlyUseVersionsFromResolvedFile: false
))
XCTAssertEqual(package.name, "BinaryPackage")

XCTAssertEqual(
Set(try package.resolveBuildProducts().map(\.target.name)),
["SomeBinary"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ let package = Package(
name: "TestingPackage",
dependencies: [
.product(name: "Logging", package: "swift-log"),
]),
]
),
.executableTarget(
name: "InternalExecutableTarget",
dependencies: ["InternalRegularTarget"]
),
.target(name: "InternalRegularTarget"),
.testTarget(
name: "TestingPackageTests",
dependencies: ["InternalRegularTarget"]
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@main
public struct InternalExecutableTarget {
static func main() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct InternalRegularTarget {
public init() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import XCTest
import InternalRegularTarget

class TestingPackageTests: XCTest {}
Loading