Skip to content

Commit

Permalink
Go: add workaround for extractor pack windows installer
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed Apr 29, 2024
1 parent 1f78882 commit 15bb846
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
23 changes: 21 additions & 2 deletions go/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 13 additions & 3 deletions go/create_extractor_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
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'])
Expand All @@ -11,6 +13,14 @@
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])

0 comments on commit 15bb846

Please sign in to comment.