mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Go: add workaround for extractor pack windows installer
This commit is contained in:
@@ -3,6 +3,7 @@ load("@gazelle//:def.bzl", "gazelle")
|
||||
load("@rules_go//go:def.bzl", "go_cross_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")
|
||||
|
||||
# following is needed for running gazelle on macOS
|
||||
@@ -92,15 +93,33 @@ pkg_filegroup(
|
||||
)
|
||||
|
||||
pkg_install(
|
||||
name = "_create_extractor_pack",
|
||||
name = "_extractor-pack-installer",
|
||||
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"],
|
||||
main = "create_extractor_pack.py",
|
||||
deps = [":_create_extractor_pack"],
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
)
|
||||
|
||||
native_binary(
|
||||
|
||||
@@ -2,7 +2,9 @@ import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
from go._create_extractor_pack_install_script import main
|
||||
import subprocess
|
||||
import zipfile
|
||||
from python.runfiles import runfiles
|
||||
|
||||
try:
|
||||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
|
||||
@@ -11,6 +13,14 @@ except KeyError:
|
||||
sys.exit(1)
|
||||
|
||||
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go'
|
||||
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1]))
|
||||
|
||||
shutil.rmtree(dest_dir, ignore_errors=True)
|
||||
os.environ['DESTDIR'] = str(dest_dir)
|
||||
main(sys.argv)
|
||||
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user