Skip to content

Commit

Permalink
Swift: update load.bzl and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Tranquilli committed Oct 30, 2024
1 parent 91f683d commit d325b8e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
43 changes: 17 additions & 26 deletions swift/third_party/load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//misc/bazel:lfs.bzl", "lfs_archive", "lfs_files")

# these are used to test new artifacts. They must not be merged to main as different from None
_override_resource_dir = {
"macOS": "ad533e614c3565db17186fa93684bd404d1bd66120b563957a44afc997a82b5e",
"Linux": "d6f1abbe9c0662ec2418b9a8c0136b1d8399601f556631a7b0910115cef3a38a",
}
_override_prebuilt = {
"macOS": "8f3c775aa7a62e97046f4dcfbc5b51c317712250396c7a07f7d0f4bd666a59d4",
"Linux": "5658fe92fe60b01b897757495d455c9fe435037a0973cb5b642e04be00a77ed3",
_override = {
# these are used to test new artifacts. Must be empty before merging to main
"swift-prebuilt-macOS.tar.zst": "a016ed60ee1a534439ed4d55100ecf6b9fc739f629be20942345ac5156cb6296",
"swift-prebuilt-Linux.tar.zst": "54240eb2da948207862ea8eb9bcbfe4447016534b9a8e6d8ee1af67db2a3e73f",
"resource-dir-macOS.zip": "fc7ed103d79f9dc61e716a58f221757c33ac2a4358de771d4889e1050f2a5b7a",
"resource-dir-Linux.zip": "e5323f44e72f446e26e7b1fc4920ca9b924e6b5ef8b22e9cb18a0f2f03732913",
}

_staging_url = "https://github.com/dsp-testing/codeql-swift-artifacts/releases/download/staging-{file}/{file}"

def _load_resource_dir(plat):
name = "swift-resource-dir-%s" % plat.lower()
file = "resource-dir-%s.zip" % plat
override = _override_resource_dir[plat]
if override:
if file in _override:
http_file(
name = name,
url = _staging_url.format(file = file),
sha256 = override,
sha256 = _override[file],
downloaded_file_path = file,
)
else:
Expand All @@ -36,12 +33,11 @@ def _load_prebuilt(plat):
name = "swift-prebuilt-%s" % plat.lower()
file = "swift-prebuilt-%s.tar.zst" % plat
build = _build % "swift-llvm-support"
override = _override_prebuilt[plat]
if override:
if file in _override:
http_archive(
name = name,
url = _staging_url.format(file = file),
sha256 = override,
sha256 = _override[file],
build_file = build,
)
else:
Expand Down Expand Up @@ -93,18 +89,13 @@ def load_dependencies(module_ctx):
swift_deps = module_extension(load_dependencies)

def test_no_override():
test_body = ["#!/bin/bash", "", "RET=0"]
for name, definition in (
("_override_prebuilt", _override_prebuilt),
("_override_resource_dir", _override_resource_dir),
):
for plat in ("macOS", "Linux"):
if definition[plat]:
test_body += [
'echo %s[\\"%s\\"] overridden in swift/third/party/load.bzl' % (name, plat),
"RET=1",
]
test_body += ["", "exit $RET"]
test_body = ["#!/bin/bash", ""]
test_body += [
'echo \\"%s\\" overridden in swift/third/party/load.bzl' % key
for key in _override
]
if _override:
test_body.append("exit 1")
write_file(
name = "test-no-override-gen",
out = "test-no-override.sh",
Expand Down
27 changes: 27 additions & 0 deletions swift/third_party/resources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,30 @@ alias(
}),
visibility = ["//visibility:public"],
)

[
sh_binary(
name = "update-%s-%s" % (what, os),
srcs = ["update.sh"],
args = [
"$(rlocationpath %s)" % what,
"$(rlocationpath %s)" % target,
],
data = [
what,
target,
],
deps = ["//misc/bazel:sh_runfiles"],
)
for os in _oses
for what, target in (
(
"prebuilt",
"swift-prebuilt-%s.tar.zst" % os,
),
(
"dir",
"resource-dir-%s.zip" % os,
),
)
]
25 changes: 25 additions & 0 deletions swift/third_party/resources/updating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
These files can only be updated having access for the internal repository at the moment.

In order to perform a Swift update:

1. Dispatch the https://github.com/github/semmle-code/actions/workflows/__swift-prebuild.yml with the appropriate swift
tag.
2. Dispatch the https://github.com/github/semmle-code/actions/workflows/__swift-prepare-resource-dir.yml with the
appropriate swift tag.
3. Once the jobs finish, staged artifacts are available
at https://github.com/dsp-testing/codeql-swift-artifacts/releases. Copy and paste the sha256 within the `_override`
definition in [`load.bzl`](../load.bzl).
4. Compile and run test locally. Adjust the code if needed. New AST entities have to be dealt with in [
`SwiftTagTraits.h`](../../extractor/infra/SwiftTagTraits.h).
5. Open a draft PR with the overridden artifacts. Make sure CI passes, go back to 4. otherwise.
6. Run DCA, got back to 4. in case of problems.
7. Once you are happy, do
```bash
bazel run //swift/third_party/resources:update-dir-macos
bazel run //swift/third_party/resources:update-dir-linux
bazel run //swift/third_party/resources:update-prebuilt-macos
bazel run //swift/third_party/resources:update-prebuilt-linux
```
(or whatever you have overridden). This will pull the staged archives in the repository for git LFS.
8. Clear `_override` in [`load.bzl`](../load.bzl).
9. Push and your PR will be ready for `main`.

0 comments on commit d325b8e

Please sign in to comment.