From 45e14ba9c0d0aa9b0bc3c173917130191b803b23 Mon Sep 17 00:00:00 2001 From: Juri Pakaste Date: Sun, 25 Aug 2024 09:27:09 +0300 Subject: [PATCH 1/2] Respect relativePaths in local package paths Before this a local package defined in an included file would not respect relativePaths: true. This fixes #1497. --- Sources/ProjectSpec/Project.swift | 1 + Sources/ProjectSpec/SwiftPackage.swift | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index aa873bcfe..63c0ef313 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -241,6 +241,7 @@ extension Project: PathContainer { .object("aggregateTargets", AggregateTarget.pathProperties), .object("schemes", Scheme.pathProperties), .object("projectReferences", ProjectReference.pathProperties), + .object("packages", SwiftPackage.pathProperties) ] } } diff --git a/Sources/ProjectSpec/SwiftPackage.swift b/Sources/ProjectSpec/SwiftPackage.swift index 216a60617..f43294a78 100644 --- a/Sources/ProjectSpec/SwiftPackage.swift +++ b/Sources/ProjectSpec/SwiftPackage.swift @@ -127,3 +127,13 @@ extension SwiftPackage.VersionRequirement: JSONObjectConvertible { } } } + +extension SwiftPackage: PathContainer { + static var pathProperties: [PathProperty] { + [ + .dictionary([ + .string("path"), + ]), + ] + } +} From acddfc1af01b04aed5a70530045ca78911d93ed5 Mon Sep 17 00:00:00 2001 From: Juri Pakaste Date: Tue, 27 Aug 2024 18:09:54 +0300 Subject: [PATCH 2/2] Test local package with relative path --- .../paths_test/included_paths_test.yml | 2 ++ .../LocalPackage/.gitignore | 8 ++++++++ .../LocalPackage/Package.swift | 20 +++++++++++++++++++ .../Sources/LocalPackage/LocalPackage.swift | 2 ++ .../paths_test/relative_local_package/inc.yml | 3 +++ Tests/ProjectSpecTests/SpecLoadingTests.swift | 4 ++++ 6 files changed, 39 insertions(+) create mode 100644 Tests/Fixtures/paths_test/relative_local_package/LocalPackage/.gitignore create mode 100644 Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Package.swift create mode 100644 Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Sources/LocalPackage/LocalPackage.swift create mode 100644 Tests/Fixtures/paths_test/relative_local_package/inc.yml diff --git a/Tests/Fixtures/paths_test/included_paths_test.yml b/Tests/Fixtures/paths_test/included_paths_test.yml index a8d4fbb0e..2fe651969 100644 --- a/Tests/Fixtures/paths_test/included_paths_test.yml +++ b/Tests/Fixtures/paths_test/included_paths_test.yml @@ -1,6 +1,8 @@ include: - recursive_test/recursive_test.yml - same_relative_path_test/same_relative_path_test.yml + - path: relative_local_package/inc.yml + relativePaths: true configFiles: IncludedConfig: config projectReferences: diff --git a/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/.gitignore b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/.gitignore new file mode 100644 index 000000000..0023a5340 --- /dev/null +++ b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Package.swift b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Package.swift new file mode 100644 index 000000000..84af3c9f8 --- /dev/null +++ b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Package.swift @@ -0,0 +1,20 @@ +// swift-tools-version: 5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "LocalPackage", + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "LocalPackage", + targets: ["LocalPackage"] + ) + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target(name: "LocalPackage") + ] +) diff --git a/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Sources/LocalPackage/LocalPackage.swift b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Sources/LocalPackage/LocalPackage.swift new file mode 100644 index 000000000..08b22b80f --- /dev/null +++ b/Tests/Fixtures/paths_test/relative_local_package/LocalPackage/Sources/LocalPackage/LocalPackage.swift @@ -0,0 +1,2 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book diff --git a/Tests/Fixtures/paths_test/relative_local_package/inc.yml b/Tests/Fixtures/paths_test/relative_local_package/inc.yml new file mode 100644 index 000000000..5f3bd94be --- /dev/null +++ b/Tests/Fixtures/paths_test/relative_local_package/inc.yml @@ -0,0 +1,3 @@ +packages: + LocalPackage: + path: LocalPackage diff --git a/Tests/ProjectSpecTests/SpecLoadingTests.swift b/Tests/ProjectSpecTests/SpecLoadingTests.swift index 6a81c0907..055088f9d 100644 --- a/Tests/ProjectSpecTests/SpecLoadingTests.swift +++ b/Tests/ProjectSpecTests/SpecLoadingTests.swift @@ -193,6 +193,10 @@ class SpecLoadingTests: XCTestCase { test: .init(testPlans: [.init(path: "paths_test/TestPlan.xctestplan")]) ) ] + + try expect(project.packages) == [ + "LocalPackage": .local(path: "paths_test/relative_local_package/LocalPackage", group: nil), + ] } $0.it("respects directory expansion preference") {