mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Bazel/Go: make installer work from internal repo and on windows
It turns out everything that is needed for the installer to work on windows is enabling runfiles. This also requires symlinks to avoid excessive copying of files.
This commit is contained in:
3
.bazelrc
3
.bazelrc
@@ -14,6 +14,9 @@ build:linux --cxxopt=-std=c++20
|
||||
build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64
|
||||
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
|
||||
|
||||
# this requires developer mode, but is required to have pack installer functioning
|
||||
common:windows --windows_enable_symlinks --enable_runfiles
|
||||
|
||||
common --registry=file:///%workspace%/misc/bazel/registry
|
||||
common --registry=https://bcr.bazel.build
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
|
||||
load("@rules_pkg//pkg:install.bzl", "pkg_install")
|
||||
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
|
||||
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
|
||||
load("//:defs.bzl", "codeql_platform")
|
||||
|
||||
native_binary(
|
||||
@@ -81,31 +80,14 @@ pkg_filegroup(
|
||||
)
|
||||
|
||||
pkg_install(
|
||||
name = "_extractor-pack-installer",
|
||||
name = "_extractor_pack",
|
||||
srcs = [":extractor-pack"],
|
||||
)
|
||||
|
||||
# rules_pkg installer is currently broken on Windows
|
||||
# see https://github.com/bazelbuild/rules_pkg/issues/387
|
||||
# for now, work around it using an archive
|
||||
pkg_zip(
|
||||
name = "_extractor-pack-zip",
|
||||
srcs = [":extractor-pack"],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "_create-extractor-pack-arg",
|
||||
actual = select({
|
||||
"@platforms//os:windows": ":_extractor-pack-zip",
|
||||
"//conditions:default": ":_extractor-pack-installer",
|
||||
}),
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "create-extractor-pack",
|
||||
srcs = ["create_extractor_pack.py"],
|
||||
args = ["$(rlocationpath :_create-extractor-pack-arg)"],
|
||||
data = [":_create-extractor-pack-arg"],
|
||||
env = {"REPO_NAME": repo_name()},
|
||||
main = "create_extractor_pack.py",
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
deps = ["_extractor_pack"],
|
||||
)
|
||||
|
||||
24
go/create_extractor_pack.py
Normal file → Executable file
24
go/create_extractor_pack.py
Normal file → Executable file
@@ -1,26 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import zipfile
|
||||
from python.runfiles import runfiles
|
||||
|
||||
try:
|
||||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
|
||||
except KeyError:
|
||||
print("this should be run with bazel run", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
res = subprocess.run(["bazel", "run", ":create-extractor-pack"], cwd=pathlib.Path(__file__).parent)
|
||||
sys.exit(res.returncode)
|
||||
|
||||
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go'
|
||||
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1]))
|
||||
from go._extractor_pack_install_script import main
|
||||
|
||||
if os.environ['REPO_NAME'] == 'codeql~':
|
||||
workspace_dir /= 'ql'
|
||||
|
||||
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-pack'
|
||||
shutil.rmtree(dest_dir, ignore_errors=True)
|
||||
|
||||
if installer_or_zip.suffix == '.zip':
|
||||
dest_dir.mkdir()
|
||||
with zipfile.ZipFile(installer_or_zip) as pack:
|
||||
pack.extractall(dest_dir)
|
||||
else:
|
||||
os.environ['DESTDIR'] = str(dest_dir)
|
||||
subprocess.check_call([installer_or_zip])
|
||||
os.environ['DESTDIR'] = str(dest_dir)
|
||||
main(sys.argv)
|
||||
|
||||
Reference in New Issue
Block a user