Skip to content

Commit

Permalink
Merge pull request #131 from dmhts/fix-description-package-resolves-o…
Browse files Browse the repository at this point in the history
…nly-exported-targets

Fix DescriptionPackage resolves targets not exported via products
  • Loading branch information
giginet authored Jul 1, 2024
2 parents f332eb4 + 8000acf commit 205cb96
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
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")
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 {}

0 comments on commit 205cb96

Please sign in to comment.