Skip to content

Commit d325b8e

Browse files
author
Paolo Tranquilli
committed
Swift: update load.bzl and resources
1 parent 91f683d commit d325b8e

File tree

3 files changed

+69
-26
lines changed

3 files changed

+69
-26
lines changed

swift/third_party/load.bzl

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,24 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"
33
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
44
load("//misc/bazel:lfs.bzl", "lfs_archive", "lfs_files")
55

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

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

1816
def _load_resource_dir(plat):
1917
name = "swift-resource-dir-%s" % plat.lower()
2018
file = "resource-dir-%s.zip" % plat
21-
override = _override_resource_dir[plat]
22-
if override:
19+
if file in _override:
2320
http_file(
2421
name = name,
2522
url = _staging_url.format(file = file),
26-
sha256 = override,
23+
sha256 = _override[file],
2724
downloaded_file_path = file,
2825
)
2926
else:
@@ -36,12 +33,11 @@ def _load_prebuilt(plat):
3633
name = "swift-prebuilt-%s" % plat.lower()
3734
file = "swift-prebuilt-%s.tar.zst" % plat
3835
build = _build % "swift-llvm-support"
39-
override = _override_prebuilt[plat]
40-
if override:
36+
if file in _override:
4137
http_archive(
4238
name = name,
4339
url = _staging_url.format(file = file),
44-
sha256 = override,
40+
sha256 = _override[file],
4541
build_file = build,
4642
)
4743
else:
@@ -93,18 +89,13 @@ def load_dependencies(module_ctx):
9389
swift_deps = module_extension(load_dependencies)
9490

9591
def test_no_override():
96-
test_body = ["#!/bin/bash", "", "RET=0"]
97-
for name, definition in (
98-
("_override_prebuilt", _override_prebuilt),
99-
("_override_resource_dir", _override_resource_dir),
100-
):
101-
for plat in ("macOS", "Linux"):
102-
if definition[plat]:
103-
test_body += [
104-
'echo %s[\\"%s\\"] overridden in swift/third/party/load.bzl' % (name, plat),
105-
"RET=1",
106-
]
107-
test_body += ["", "exit $RET"]
92+
test_body = ["#!/bin/bash", ""]
93+
test_body += [
94+
'echo \\"%s\\" overridden in swift/third/party/load.bzl' % key
95+
for key in _override
96+
]
97+
if _override:
98+
test_body.append("exit 1")
10899
write_file(
109100
name = "test-no-override-gen",
110101
out = "test-no-override.sh",

swift/third_party/resources/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,30 @@ alias(
1919
}),
2020
visibility = ["//visibility:public"],
2121
)
22+
23+
[
24+
sh_binary(
25+
name = "update-%s-%s" % (what, os),
26+
srcs = ["update.sh"],
27+
args = [
28+
"$(rlocationpath %s)" % what,
29+
"$(rlocationpath %s)" % target,
30+
],
31+
data = [
32+
what,
33+
target,
34+
],
35+
deps = ["//misc/bazel:sh_runfiles"],
36+
)
37+
for os in _oses
38+
for what, target in (
39+
(
40+
"prebuilt",
41+
"swift-prebuilt-%s.tar.zst" % os,
42+
),
43+
(
44+
"dir",
45+
"resource-dir-%s.zip" % os,
46+
),
47+
)
48+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
These files can only be updated having access for the internal repository at the moment.
2+
3+
In order to perform a Swift update:
4+
5+
1. Dispatch the https://github.com/github/semmle-code/actions/workflows/__swift-prebuild.yml with the appropriate swift
6+
tag.
7+
2. Dispatch the https://github.com/github/semmle-code/actions/workflows/__swift-prepare-resource-dir.yml with the
8+
appropriate swift tag.
9+
3. Once the jobs finish, staged artifacts are available
10+
at https://github.com/dsp-testing/codeql-swift-artifacts/releases. Copy and paste the sha256 within the `_override`
11+
definition in [`load.bzl`](../load.bzl).
12+
4. Compile and run test locally. Adjust the code if needed. New AST entities have to be dealt with in [
13+
`SwiftTagTraits.h`](../../extractor/infra/SwiftTagTraits.h).
14+
5. Open a draft PR with the overridden artifacts. Make sure CI passes, go back to 4. otherwise.
15+
6. Run DCA, got back to 4. in case of problems.
16+
7. Once you are happy, do
17+
```bash
18+
bazel run //swift/third_party/resources:update-dir-macos
19+
bazel run //swift/third_party/resources:update-dir-linux
20+
bazel run //swift/third_party/resources:update-prebuilt-macos
21+
bazel run //swift/third_party/resources:update-prebuilt-linux
22+
```
23+
(or whatever you have overridden). This will pull the staged archives in the repository for git LFS.
24+
8. Clear `_override` in [`load.bzl`](../load.bzl).
25+
9. Push and your PR will be ready for `main`.

0 commit comments

Comments
 (0)