Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: add codeql specific packaging library #16432

Merged
merged 48 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
60cf77b
Bazel: add codeql specific packaging library
redsun82 May 6, 2024
4d93e8a
Bazel: move codeql packaging rules away from some macros
redsun82 May 23, 2024
e8b857b
Bazel/Swift: add zip imports to packs
redsun82 May 24, 2024
1529b58
Swift: add resource dir updater
redsun82 May 24, 2024
8e132e9
Bazel: add executable attribute to `lfs_files`
redsun82 May 24, 2024
94d6fef
Swift: fix module
redsun82 May 24, 2024
175f0db
Swift: remove broken obsolete alias
redsun82 May 24, 2024
e694968
Fix change to `.gitattributes` done by mistake
redsun82 May 24, 2024
dcbf42d
Bazel: reorganize LFS files and add licensing information
redsun82 May 24, 2024
fa2c626
Bazel: add fat macOS ripunzip binary
redsun82 May 24, 2024
ea01ae6
Swift: fix integration test log upload
redsun82 May 24, 2024
e990d75
Bazel: use codeql platform as arch zip filename
redsun82 May 24, 2024
f35f077
Swift: cleanup tools scripts in pack
redsun82 May 24, 2024
b9064c5
Bazel: fail install on `ripunzip` failing
redsun82 May 24, 2024
5d4b61c
Bazel: replace prebuilt ripunzip from workflow
redsun82 May 24, 2024
0b7a425
Bazel: use `{CODEQL_PLATFORM}` as discriminant between arch and gener…
redsun82 May 27, 2024
546d644
Swift: do not use `codeql_pkg_files` needlessly
redsun82 May 27, 2024
2bec696
Merge branch 'main' into redsun82/pkg
redsun82 May 27, 2024
6bbad22
Codegen: make codegen work on windows
redsun82 May 27, 2024
2f53c0e
Bazel: fix `codeql_pack` installation on Windows
redsun82 May 27, 2024
2f95944
Bazel: add documentation to `install.py`
redsun82 May 27, 2024
cde71a9
Bazel: address review comments
redsun82 May 27, 2024
392ef09
Zipmerge: make lib public for internal testing
redsun82 May 27, 2024
fbf3b9a
Merge branch 'main' into redsun82/pkg
redsun82 May 27, 2024
fe9a153
Merge branch 'main' into redsun82/pkg
redsun82 May 28, 2024
f7bfe43
Swift: fix windows build again
redsun82 May 28, 2024
afadc1f
Merge branch 'main' into redsun82/pkg
redsun82 May 28, 2024
a8543d4
Zipmerge: port tests from internal repo
redsun82 May 28, 2024
6d79841
Bazel: add `--no-cleanup` to installer script
redsun82 May 28, 2024
76fbb52
Bazel: use pack name for zip file name
redsun82 May 28, 2024
6b97161
Bazel: rename `_process_path` to `_expand_path`, and make its use cle…
redsun82 May 28, 2024
e2206e6
Bazel: restrict `codeql_pack` `zips` to `.zip` files
redsun82 May 28, 2024
00ed00e
Bazel: avoid unneeded operations if no imported zips are present
redsun82 May 28, 2024
9c1efb9
Bazel: expose `compression_level` in `codeql_pack`
redsun82 May 28, 2024
67d622f
Bazel: actually run the zipmerge tests
redsun82 May 28, 2024
c3ccf4d
Zipmerge: substitute `CPython` archives with dummy ones
redsun82 May 28, 2024
5eb12b8
Zipmerge: substitute stripped down slf4j jars with dummy ones
redsun82 May 28, 2024
2a62455
Merge branch 'main' into redsun82/pkg
redsun82 May 28, 2024
de48477
Zipmerge: print test outputs on CI
redsun82 May 28, 2024
45f1fdf
Bazel: extract pack filtering logic out of `_zipmerge`
redsun82 May 28, 2024
4094db4
Merge branch 'main' into redsun82/pkg
redsun82 May 28, 2024
332d178
Zipmerge: allow test to be run from internal repo
redsun82 May 28, 2024
fbe1b56
Zipmerge: link test statically
redsun82 May 29, 2024
491e3a4
Merge branch 'main' into redsun82/pkg
redsun82 May 29, 2024
5672ddf
Fix bazel formatting
redsun82 May 29, 2024
e8061ec
Bazel: fix `_zipmerge` rule
redsun82 May 29, 2024
336ec08
Bazel: use `extend(...)` instead of `+= list(...)`
redsun82 May 29, 2024
1e6820b
Merge branch 'main' into redsun82/pkg
redsun82 May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ common --override_module=semmle_code=%workspace%/misc/bazel/semmle_code_stub

build --repo_env=CC=clang --repo_env=CXX=clang++

build:linux --cxxopt=-std=c++20
build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
# we currently cannot built the swift extractor for ARM
build:macos --cxxopt=-std=c++20 --copt=-arch --copt=x86_64 --linkopt=-arch --linkopt=x86_64
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 --copt=-arch --copt=x86_64 --linkopt=-arch --linkopt=x86_64
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor --host_cxxopt=/std:c++20 --host_cxxopt=/Zc:preprocessor

# this requires developer mode, but is required to have pack installer functioning
startup --windows_enable_symlinks
common --enable_runfiles

# with the above, we can avoid building python zips which is the default on windows as that's expensive
build --nobuild_python_zip
criemen marked this conversation as resolved.
Show resolved Hide resolved

common --registry=file:///%workspace%/misc/bazel/registry
common --registry=https://bcr.bazel.build

Expand Down
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ csharp/paket.lock linguist-generated=true
csharp/.paket/Paket.Restore.targets linguist-generated=true eol=crlf
csharp/paket.main.bzl linguist-generated=true
csharp/paket.main_extension.bzl linguist-generated=true

# ripunzip tool
/misc/bazel/internal/ripunzip/ripunzip-* filter=lfs diff=lfs merge=lfs -text

# swift prebuilt resources
/swift/third_party/resource-dir/*.zip filter=lfs diff=lfs merge=lfs -text
23 changes: 23 additions & 0 deletions .github/workflows/zipmerge-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Test zipmerge code"

on:
pull_request:
paths:
- "misc/bazel/internal/zipmerge/**"
- "MODULE.bazel"
- ".bazelrc*"
branches:
- main
- "rc/*"

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: |
bazel test //misc/bazel/internal/zipmerge:test --test_output=all
31 changes: 31 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")
bazel_dep(name = "gazelle", version = "0.36.0")
bazel_dep(name = "rules_dotnet", version = "0.15.1")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)

Expand Down Expand Up @@ -67,6 +68,36 @@ use_repo(node, "nodejs", "nodejs_toolchains")
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.2")

lfs_files = use_repo_rule("//misc/bazel:lfs.bzl", "lfs_files")

lfs_files(
name = "ripunzip-linux",
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-linux"],
executable = True,
)

lfs_files(
name = "ripunzip-windows",
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-windows.exe"],
executable = True,
)

lfs_files(
name = "ripunzip-macos",
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-macos"],
executable = True,
)

lfs_files(
name = "swift-resource-dir-linux",
srcs = ["//swift/third_party/resource-dir:resource-dir-linux.zip"],
)

lfs_files(
name = "swift-resource-dir-macos",
srcs = ["//swift/third_party/resource-dir:resource-dir-macos.zip"],
)

register_toolchains(
"@nodejs_toolchains//:all",
)
1 change: 1 addition & 0 deletions misc/bazel/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["install.py"])
55 changes: 55 additions & 0 deletions misc/bazel/internal/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Helper script for installing `codeql_pack` targets.

This mainly wraps around a `pkg_install` script from `rules_pkg` adding:
* resolving destination directory with respect to a provided `--build-file`
* clean-up of target destination directory before a reinstall
* installing imported zip files using a provided `--ripunzip`
"""

import argparse
criemen marked this conversation as resolved.
Show resolved Hide resolved
import pathlib
import shutil
import subprocess
from python.runfiles import runfiles

runfiles = runfiles.Create()
assert runfiles, "Installer should be run with `bazel run`"

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--destdir", type=pathlib.Path, required=True,
help="Desination directory, relative to `--build-file`")
parser.add_argument("--pkg-install-script", required=True,
help="The wrapped `pkg_install` installation script rlocation")
parser.add_argument("--build-file", required=True,
help="BUILD.bazel rlocation relative to which the installation should take place")
parser.add_argument("--ripunzip",
help="ripunzip executable rlocation. Must be provided if `--zip-manifest` is.")
parser.add_argument("--zip-manifest",
help="The rlocation of a file containing newline-separated `prefix:zip_file` entries")
parser.add_argument("--cleanup", action=argparse.BooleanOptionalAction, default=True,
help="Whether to wipe the destination directory before installing (true by default)")
opts = parser.parse_args()
if opts.zip_manifest and not opts.ripunzip:
parser.error("Provide `--ripunzip` when specifying `--zip-manifest`")

build_file = runfiles.Rlocation(opts.build_file)
script = runfiles.Rlocation(opts.pkg_install_script)
destdir = pathlib.Path(build_file).resolve().parent / opts.destdir

if destdir.exists() and opts.cleanup:
shutil.rmtree(destdir)

destdir.mkdir(parents=True, exist_ok=True)
subprocess.run([script, "--destdir", destdir], check=True)

if opts.zip_manifest:
ripunzip = runfiles.Rlocation(opts.ripunzip)
zip_manifest = runfiles.Rlocation(opts.zip_manifest)
with open(zip_manifest) as manifest:
for line in manifest:
prefix, _, zip = line.partition(":")
assert zip, f"missing prefix for {prefix}, you should use prefix:zip format"
dest = destdir / prefix
dest.mkdir(parents=True, exist_ok=True)
subprocess.run([ripunzip, "unzip-file", zip, "-d", dest], check=True)
8 changes: 8 additions & 0 deletions misc/bazel/internal/ripunzip/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

native_binary(
name = "ripunzip",
src = select({"@platforms//os:" + os: "@ripunzip-" + os for os in ("linux", "windows", "macos")}),
out = "ripunzip.exe",
visibility = ["//visibility:public"],
)