-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16432 from github/redsun82/pkg
Bazel: add codeql specific packaging library
- Loading branch information
Showing
43 changed files
with
1,949 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports_files(["install.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
Oops, something went wrong.