From 1529b58089679564dcbaa7cc3cba952f174ea5c8 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 24 May 2024 12:19:06 +0200 Subject: [PATCH] Swift: add resource dir updater --- .../BUILD.swift-toolchain-linux.bazel | 12 ++++++--- .../BUILD.swift-toolchain-macos.bazel | 13 ++++++++- swift/third_party/resource-dir/BUILD.bazel | 27 ++++++++++++++++--- swift/third_party/resource-dir/update.sh | 12 +++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) mode change 100644 => 100755 swift/third_party/resource-dir/update.sh diff --git a/swift/third_party/BUILD.swift-toolchain-linux.bazel b/swift/third_party/BUILD.swift-toolchain-linux.bazel index be2c2e12a971..ef6d4d44be18 100644 --- a/swift/third_party/BUILD.swift-toolchain-linux.bazel +++ b/swift/third_party/BUILD.swift-toolchain-linux.bazel @@ -1,4 +1,5 @@ -load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files") +load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +load("@rules_pkg//pkg:pkg.bzl", "pkg_zip") _strip_prefix = "usr/lib/swift" @@ -42,8 +43,13 @@ _pm_interface_files = [ for dir, interface, module in _pm_interface_files ] -pkg_filegroup( - name = "resource-dir", +pkg_zip( + name = "resource-dir-linux", srcs = [":resource-dir-original"] + [":pkg-%s" % module for _, _, module in _pm_interface_files], +) + +alias( + name = "swift_toolchain_linux", + actual = ":resource-dir-linux", visibility = ["//visibility:public"], ) diff --git a/swift/third_party/BUILD.swift-toolchain-macos.bazel b/swift/third_party/BUILD.swift-toolchain-macos.bazel index 38250f1d2104..461b292ddbf3 100644 --- a/swift/third_party/BUILD.swift-toolchain-macos.bazel +++ b/swift/third_party/BUILD.swift-toolchain-macos.bazel @@ -1,12 +1,23 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +load("@rules_pkg//pkg:pkg.bzl", "pkg_zip") _strip_prefix = "usr/lib/swift" pkg_files( - name = "resource-dir", + name = "resource-dir-files", srcs = glob( ["usr/lib/swift/**/*"], ), strip_prefix = _strip_prefix, +) + +pkg_zip( + name = "resource-dir-macos", + srcs = [":resource-dir-files"], +) + +alias( + name = "swift_toolchain_macos", + actual = ":resource-dir-macos", visibility = ["//visibility:public"], ) diff --git a/swift/third_party/resource-dir/BUILD.bazel b/swift/third_party/resource-dir/BUILD.bazel index 8474e13159bc..5c8761fd72e7 100644 --- a/swift/third_party/resource-dir/BUILD.bazel +++ b/swift/third_party/resource-dir/BUILD.bazel @@ -1,9 +1,30 @@ -load("//misc/bazel:pkg.bzl", "codeql_pkg_zip") +load("//misc/bazel:pkg.bzl", "codeql_pkg_zip_import") -codeql_pkg_zip( +codeql_pkg_zip_import( name = "resource-dir", src = select({"@platforms//os:" + os: "@swift-resource-dir-" + os for os in ("linux", "macos")}), arch_specific = True, - target_compatible_with = select({"@platforms//os:windows": ["@platforms//:incompatible"]}), + target_compatible_with = select({ + "@platforms//os:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), visibility = ["//swift:__pkg__"], ) + +[ + sh_binary( + name = "update-" + os, + srcs = ["update.sh"], + args = [ + "$(rlocationpath @swift_toolchain_%s)" % os, + "$(rlocationpath resource-dir-%s.zip)" % os, + ], + data = [ + "resource-dir-%s.zip" % os, + "@swift_toolchain_" + os, + ], + target_compatible_with = ["@platforms//os:" + os], + deps = ["@bazel_tools//tools/bash/runfiles"], + ) + for os in ("linux", "macos") +] diff --git a/swift/third_party/resource-dir/update.sh b/swift/third_party/resource-dir/update.sh old mode 100644 new mode 100755 index e69de29bb2d1..dee216a61d67 --- a/swift/third_party/resource-dir/update.sh +++ b/swift/third_party/resource-dir/update.sh @@ -0,0 +1,12 @@ +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# --- end runfiles.bash initialization v3 --- + +cp "$(rlocation "$1")" "$(rlocation "$2")"