From b774ebe57c42b80f48773093488208b9d521c865 Mon Sep 17 00:00:00 2001 From: Dima Hutsuliak Date: Thu, 27 Jun 2024 21:02:18 +0200 Subject: [PATCH 1/3] Fix DescriptionPackage resolves only exported targets --- Sources/ScipioKit/DescriptionPackage.swift | 3 ++- Tests/ScipioKitTests/DescriptionPackageTests.swift | 9 ++++++--- .../Resources/Fixtures/TestingPackage/Package.swift | 12 +++++++++++- .../InternalExecutableTarget.swift | 4 ++++ .../InternalRegularTarget.swift | 3 +++ .../TestingPackageTests/TestingPackageTests.swift | 4 ++++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalExecutableTarget/InternalExecutableTarget.swift create mode 100644 Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalRegularTarget/InternalRegularTarget.swift create mode 100644 Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Tests/TestingPackageTests/TestingPackageTests.swift diff --git a/Sources/ScipioKit/DescriptionPackage.swift b/Sources/ScipioKit/DescriptionPackage.swift index dbcd609c..74d6ac10 100644 --- a/Sources/ScipioKit/DescriptionPackage.swift +++ b/Sources/ScipioKit/DescriptionPackage.swift @@ -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 diff --git a/Tests/ScipioKitTests/DescriptionPackageTests.swift b/Tests/ScipioKitTests/DescriptionPackageTests.swift index b6764b36..99038673 100644 --- a/Tests/ScipioKitTests/DescriptionPackageTests.swift +++ b/Tests/ScipioKitTests/DescriptionPackageTests.swift @@ -65,17 +65,20 @@ final class DescriptionPackageTests: XCTestCase { } func testBuildProductsInCreateMode() throws { - let rootPath = fixturePath.appendingPathComponent("BinaryPackage") + let rootPath = fixturePath.appendingPathComponent("TestingPackage") let package = try XCTUnwrap(try DescriptionPackage( packageDirectory: rootPath.absolutePath, mode: .createPackage, onlyUseVersionsFromResolvedFile: false )) - XCTAssertEqual(package.name, "BinaryPackage") + XCTAssertEqual(package.name, "TestingPackage") XCTAssertEqual( Set(try package.resolveBuildProducts().map(\.target.name)), - ["SomeBinary"] + [ + "Logging", + "TestingPackage" + ] ) } } diff --git a/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Package.swift b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Package.swift index a07e5d66..67a25eb1 100644 --- a/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Package.swift +++ b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Package.swift @@ -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"] + ) ] ) diff --git a/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalExecutableTarget/InternalExecutableTarget.swift b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalExecutableTarget/InternalExecutableTarget.swift new file mode 100644 index 00000000..fbbc5d56 --- /dev/null +++ b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalExecutableTarget/InternalExecutableTarget.swift @@ -0,0 +1,4 @@ +@main +public struct InternalExecutableTarget { + static func main() {} +} diff --git a/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalRegularTarget/InternalRegularTarget.swift b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalRegularTarget/InternalRegularTarget.swift new file mode 100644 index 00000000..0f35f670 --- /dev/null +++ b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Sources/InternalRegularTarget/InternalRegularTarget.swift @@ -0,0 +1,3 @@ +public struct InternalRegularTarget { + public init() {} +} diff --git a/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Tests/TestingPackageTests/TestingPackageTests.swift b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Tests/TestingPackageTests/TestingPackageTests.swift new file mode 100644 index 00000000..0da6770e --- /dev/null +++ b/Tests/ScipioKitTests/Resources/Fixtures/TestingPackage/Tests/TestingPackageTests/TestingPackageTests.swift @@ -0,0 +1,4 @@ +import XCTest +import InternalRegularTarget + +class TestingPackageTests: XCTest {} From 648b055e86642ac6911a10fd6155f9f7acb7c2ed Mon Sep 17 00:00:00 2001 From: Dima Hutsuliak Date: Sun, 30 Jun 2024 09:54:08 +0200 Subject: [PATCH 2/3] Get back previous test against BinaryPackage --- .../DescriptionPackageTests.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Tests/ScipioKitTests/DescriptionPackageTests.swift b/Tests/ScipioKitTests/DescriptionPackageTests.swift index 99038673..a0847d27 100644 --- a/Tests/ScipioKitTests/DescriptionPackageTests.swift +++ b/Tests/ScipioKitTests/DescriptionPackageTests.swift @@ -77,8 +77,23 @@ final class DescriptionPackageTests: XCTestCase { Set(try package.resolveBuildProducts().map(\.target.name)), [ "Logging", - "TestingPackage" + "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"] + ) + } + } From 8000acf35e108f653e48118f0129c7430a3c3a6b Mon Sep 17 00:00:00 2001 From: Dima Hutsuliak Date: Sun, 30 Jun 2024 09:55:06 +0200 Subject: [PATCH 3/3] Remove new line --- Tests/ScipioKitTests/DescriptionPackageTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/ScipioKitTests/DescriptionPackageTests.swift b/Tests/ScipioKitTests/DescriptionPackageTests.swift index a0847d27..1f57a8d5 100644 --- a/Tests/ScipioKitTests/DescriptionPackageTests.swift +++ b/Tests/ScipioKitTests/DescriptionPackageTests.swift @@ -95,5 +95,4 @@ final class DescriptionPackageTests: XCTestCase { ["SomeBinary"] ) } - }