Skip to content

Commit

Permalink
feat: use suffixed repo name as package name (#1072)
Browse files Browse the repository at this point in the history
Resolves #1057.

Following the recommendation from the discussion there, this uses the
repo name suffixed with `.rspm` as the package name.

---------

Co-authored-by: Chuck Grindel <[email protected]>
  • Loading branch information
watt and cgrindel committed Jun 2, 2024
1 parent 6501fcc commit a426a08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions swiftpkg/internal/swiftpkg_build_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def _swift_target_build_file(pkg_ctx, 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
Expand Down
8 changes: 8 additions & 0 deletions swiftpkg/tests/swiftpkg_build_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -581,6 +582,7 @@ swift_library(
copts = ["-DSWIFT_PACKAGE"],
deps = [],
module_name = "RegularSwiftTargetAsLibrary",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Source/RegularSwiftTargetAsLibrary/RegularSwiftTargetAsLibrary.swift"],
tags = ["manual"],
visibility = ["//:__subpackages__"],
Expand All @@ -602,6 +604,7 @@ swift_library(
copts = ["-DSWIFT_PACKAGE"],
deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
module_name = "RegularTargetForExec",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Source/RegularTargetForExec/main.swift"],
tags = ["manual"],
visibility = ["//:__subpackages__"],
Expand All @@ -619,6 +622,7 @@ swift_test(
copts = ["-DSWIFT_PACKAGE"],
deps = ["@swiftpkg_mypackage//:RegularSwiftTargetAsLibrary.rspm"],
module_name = "RegularSwiftTargetAsLibraryTests",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Tests/RegularSwiftTargetAsLibraryTests/RegularSwiftTargetAsLibraryTests.swift"],
visibility = ["//:__subpackages__"],
)
Expand Down Expand Up @@ -646,6 +650,7 @@ swift_binary(
}),
deps = [],
module_name = "SwiftExecutableTarget",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Source/SwiftExecutableTarget/main.swift"],
visibility = ["//:__subpackages__"],
)
Expand Down Expand Up @@ -817,6 +822,7 @@ swift_library(
"//conditions:default": [],
}),
module_name = "SwiftLibraryWithConditionalDep",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Source/SwiftLibraryWithConditionalDep/SwiftLibraryWithConditionalDep.swift"],
tags = ["manual"],
visibility = ["//:__subpackages__"],
Expand Down Expand Up @@ -880,6 +886,7 @@ swift_library(
],
generates_header = True,
module_name = "SwiftForObjcTarget",
package_name = "swiftpkg_mypackage.rspm",
srcs = ["Source/SwiftForObjcTarget/SwiftForObjcTarget.swift"],
tags = ["manual"],
visibility = ["//:__subpackages__"],
Expand Down Expand Up @@ -919,6 +926,7 @@ swift_library(
data = [":SwiftLibraryWithFilePathResource.rspm_resource_bundle"],
deps = [],
module_name = "SwiftLibraryWithFilePathResource",
package_name = "swiftpkg_mypackage.rspm",
srcs = [
"Source/SwiftLibraryWithFilePathResource/SwiftLibraryWithFilePathResource.swift",
":SwiftLibraryWithFilePathResource.rspm_resource_bundle_accessor",
Expand Down

0 comments on commit a426a08

Please sign in to comment.