From e634ab39e29a118dceb470df17e117721c0cf5fb Mon Sep 17 00:00:00 2001 From: Andrew Watt Date: Thu, 9 May 2024 19:16:56 -0700 Subject: [PATCH 1/4] Use prefixed repo name as package name --- swiftpkg/internal/swiftpkg_build_files.bzl | 1 + swiftpkg/tests/swiftpkg_build_files_tests.bzl | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index 3696caf63..560e1b74f 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -49,6 +49,7 @@ def _swift_target_build_file(pkg_ctx, target): attrs = { "deps": bzl_selects.to_starlark(deps), "module_name": target.c99name, + "package_name": "rspm." + target.label.repository_name, "srcs": pkginfo_targets.srcs(target), "visibility": ["//:__subpackages__"], } diff --git a/swiftpkg/tests/swiftpkg_build_files_tests.bzl b/swiftpkg/tests/swiftpkg_build_files_tests.bzl index 489ba879e..7a0f76f80 100644 --- a/swiftpkg/tests/swiftpkg_build_files_tests.bzl +++ b/swiftpkg/tests/swiftpkg_build_files_tests.bzl @@ -581,6 +581,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "RegularSwiftTargetAsLibrary", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Source/RegularSwiftTargetAsLibrary/RegularSwiftTargetAsLibrary.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -602,6 +603,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularTargetForExec", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Source/RegularTargetForExec/main.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -619,6 +621,7 @@ swift_test( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularSwiftTargetAsLibraryTests", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Tests/RegularSwiftTargetAsLibraryTests/RegularSwiftTargetAsLibraryTests.swift"], visibility = ["//:__subpackages__"], ) @@ -646,6 +649,7 @@ swift_binary( }), deps = [], module_name = "SwiftExecutableTarget", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Source/SwiftExecutableTarget/main.swift"], visibility = ["//:__subpackages__"], ) @@ -819,6 +823,7 @@ swift_library( "//conditions:default": [], }), module_name = "SwiftLibraryWithConditionalDep", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Source/SwiftLibraryWithConditionalDep/SwiftLibraryWithConditionalDep.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -882,6 +887,7 @@ swift_library( ], generates_header = True, module_name = "SwiftForObjcTarget", + package_name = "rspm.@swiftpkg_mypackage", srcs = ["Source/SwiftForObjcTarget/SwiftForObjcTarget.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -921,6 +927,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "SwiftLibraryWithFilePathResource", + package_name = "rspm.@swiftpkg_mypackage", srcs = [ "Source/SwiftLibraryWithFilePathResource/SwiftLibraryWithFilePathResource.swift", ":SwiftLibraryWithFilePathResource.rspm_resource_bundle_accessor", From 7ae98cd5909f9aa3fd56ef10bec6a08fe6ba7127 Mon Sep 17 00:00:00 2001 From: Andrew Watt Date: Tue, 14 May 2024 14:53:12 -0700 Subject: [PATCH 2/4] suffix instead of prefix --- swiftpkg/internal/swiftpkg_build_files.bzl | 2 +- swiftpkg/tests/swiftpkg_build_files_tests.bzl | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index 560e1b74f..984084caf 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -49,7 +49,7 @@ def _swift_target_build_file(pkg_ctx, target): attrs = { "deps": bzl_selects.to_starlark(deps), "module_name": target.c99name, - "package_name": "rspm." + target.label.repository_name, + "package_name": target.label.repository_name + ".rspm", "srcs": pkginfo_targets.srcs(target), "visibility": ["//:__subpackages__"], } diff --git a/swiftpkg/tests/swiftpkg_build_files_tests.bzl b/swiftpkg/tests/swiftpkg_build_files_tests.bzl index 7a0f76f80..29ce1c598 100644 --- a/swiftpkg/tests/swiftpkg_build_files_tests.bzl +++ b/swiftpkg/tests/swiftpkg_build_files_tests.bzl @@ -581,7 +581,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "RegularSwiftTargetAsLibrary", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Source/RegularSwiftTargetAsLibrary/RegularSwiftTargetAsLibrary.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -603,7 +603,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularTargetForExec", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Source/RegularTargetForExec/main.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -621,7 +621,7 @@ swift_test( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularSwiftTargetAsLibraryTests", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Tests/RegularSwiftTargetAsLibraryTests/RegularSwiftTargetAsLibraryTests.swift"], visibility = ["//:__subpackages__"], ) @@ -649,7 +649,7 @@ swift_binary( }), deps = [], module_name = "SwiftExecutableTarget", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Source/SwiftExecutableTarget/main.swift"], visibility = ["//:__subpackages__"], ) @@ -823,7 +823,7 @@ swift_library( "//conditions:default": [], }), module_name = "SwiftLibraryWithConditionalDep", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Source/SwiftLibraryWithConditionalDep/SwiftLibraryWithConditionalDep.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -887,7 +887,7 @@ swift_library( ], generates_header = True, module_name = "SwiftForObjcTarget", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = ["Source/SwiftForObjcTarget/SwiftForObjcTarget.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -927,7 +927,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "SwiftLibraryWithFilePathResource", - package_name = "rspm.@swiftpkg_mypackage", + package_name = "@swiftpkg_mypackage.rspm", srcs = [ "Source/SwiftLibraryWithFilePathResource/SwiftLibraryWithFilePathResource.swift", ":SwiftLibraryWithFilePathResource.rspm_resource_bundle_accessor", From e7407ee8994a591b3790855e93b98a0b9b23eb6c Mon Sep 17 00:00:00 2001 From: Andrew Watt Date: Wed, 15 May 2024 18:33:28 -0700 Subject: [PATCH 3/4] remove leading @ from package name --- swiftpkg/internal/swiftpkg_build_files.bzl | 2 +- swiftpkg/tests/swiftpkg_build_files_tests.bzl | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index 984084caf..98e3cf90e 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -49,7 +49,7 @@ def _swift_target_build_file(pkg_ctx, target): attrs = { "deps": bzl_selects.to_starlark(deps), "module_name": target.c99name, - "package_name": target.label.repository_name + ".rspm", + "package_name": target.label.repository_name.lstrip("@") + ".rspm", "srcs": pkginfo_targets.srcs(target), "visibility": ["//:__subpackages__"], } diff --git a/swiftpkg/tests/swiftpkg_build_files_tests.bzl b/swiftpkg/tests/swiftpkg_build_files_tests.bzl index 29ce1c598..3a31bee03 100644 --- a/swiftpkg/tests/swiftpkg_build_files_tests.bzl +++ b/swiftpkg/tests/swiftpkg_build_files_tests.bzl @@ -581,7 +581,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "RegularSwiftTargetAsLibrary", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Source/RegularSwiftTargetAsLibrary/RegularSwiftTargetAsLibrary.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -603,7 +603,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularTargetForExec", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Source/RegularTargetForExec/main.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -621,7 +621,7 @@ swift_test( defines = ["SWIFT_PACKAGE"], deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"], module_name = "RegularSwiftTargetAsLibraryTests", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Tests/RegularSwiftTargetAsLibraryTests/RegularSwiftTargetAsLibraryTests.swift"], visibility = ["//:__subpackages__"], ) @@ -649,7 +649,7 @@ swift_binary( }), deps = [], module_name = "SwiftExecutableTarget", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Source/SwiftExecutableTarget/main.swift"], visibility = ["//:__subpackages__"], ) @@ -823,7 +823,7 @@ swift_library( "//conditions:default": [], }), module_name = "SwiftLibraryWithConditionalDep", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Source/SwiftLibraryWithConditionalDep/SwiftLibraryWithConditionalDep.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -887,7 +887,7 @@ swift_library( ], generates_header = True, module_name = "SwiftForObjcTarget", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = ["Source/SwiftForObjcTarget/SwiftForObjcTarget.swift"], tags = ["manual"], visibility = ["//:__subpackages__"], @@ -927,7 +927,7 @@ swift_library( defines = ["SWIFT_PACKAGE"], deps = [], module_name = "SwiftLibraryWithFilePathResource", - package_name = "@swiftpkg_mypackage.rspm", + package_name = "swiftpkg_mypackage.rspm", srcs = [ "Source/SwiftLibraryWithFilePathResource/SwiftLibraryWithFilePathResource.swift", ":SwiftLibraryWithFilePathResource.rspm_resource_bundle_accessor", From 0601a4d944305cbe4555108a0000c1c1763b678c Mon Sep 17 00:00:00 2001 From: Andrew Watt Date: Fri, 31 May 2024 18:25:19 -0700 Subject: [PATCH 4/4] gate package_name behind tools version 5.9 --- swiftpkg/internal/swiftpkg_build_files.bzl | 10 +++++++++- swiftpkg/tests/swiftpkg_build_files_tests.bzl | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index 98e3cf90e..d0297efe9 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -49,11 +49,19 @@ def _swift_target_build_file(pkg_ctx, target): attrs = { "deps": bzl_selects.to_starlark(deps), "module_name": target.c99name, - "package_name": target.label.repository_name.lstrip("@") + ".rspm", "srcs": pkginfo_targets.srcs(target), "visibility": ["//:__subpackages__"], } + # Naively parse the tools semver. + tools_version = pkg_ctx.pkg_info.tools_version or "0.0.0" + tools_version_components = tools_version.split(".") + ["0", "0"] + tools_version_major, tools_version_minor = [int(x if x.isdigit() else "0") for x in tools_version_components[0:2]] + + # Gate package_name behind swift tools version 5.9 + if tools_version_major >= 6 or (tools_version_major == 5 and tools_version_minor >= 9): + attrs["package_name"] = target.label.repository_name.lstrip("@") + ".rspm" + # Add macros as plugins macro_target_labels = [ target.label.repository_name + "//:" + target.label.name diff --git a/swiftpkg/tests/swiftpkg_build_files_tests.bzl b/swiftpkg/tests/swiftpkg_build_files_tests.bzl index 3a31bee03..1651a736f 100644 --- a/swiftpkg/tests/swiftpkg_build_files_tests.bzl +++ b/swiftpkg/tests/swiftpkg_build_files_tests.bzl @@ -34,6 +34,7 @@ _repo_name = "@swiftpkg_mypackage" _pkg_info = pkginfos.new( name = "MyPackage", path = "/path/to/my-package", + tools_version = "5.9", dependencies = [ pkginfos.new_dependency( identity = "swift-argument-parser",