Skip to content

Commit 15bb846

Browse files
committed
Go: add workaround for extractor pack windows installer
1 parent 1f78882 commit 15bb846

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

go/BUILD.bazel

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@gazelle//:def.bzl", "gazelle")
33
load("@rules_go//go:def.bzl", "go_cross_binary")
44
load("@rules_pkg//pkg:install.bzl", "pkg_install")
55
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
6+
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
67
load("//:defs.bzl", "codeql_platform")
78

89
# following is needed for running gazelle on macOS
@@ -92,15 +93,33 @@ pkg_filegroup(
9293
)
9394

9495
pkg_install(
95-
name = "_create_extractor_pack",
96+
name = "_extractor-pack-installer",
9697
srcs = [":extractor-pack"],
9798
)
9899

100+
# rules_pkg installer is currently broken on Windows
101+
# see https://github.com/bazelbuild/rules_pkg/issues/387
102+
# for now, work around it using an archive
103+
pkg_zip(
104+
name = "_extractor-pack-zip",
105+
srcs = [":extractor-pack"],
106+
)
107+
108+
alias(
109+
name = "_create-extractor-pack-arg",
110+
actual = select({
111+
"@platforms//os:windows": ":_extractor-pack-zip",
112+
"//conditions:default": ":_extractor-pack-installer",
113+
}),
114+
)
115+
99116
py_binary(
100117
name = "create-extractor-pack",
101118
srcs = ["create_extractor_pack.py"],
119+
args = ["$(rlocationpath :_create-extractor-pack-arg)"],
120+
data = [":_create-extractor-pack-arg"],
102121
main = "create_extractor_pack.py",
103-
deps = [":_create_extractor_pack"],
122+
deps = ["@rules_python//python/runfiles"],
104123
)
105124

106125
native_binary(

go/create_extractor_pack.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import pathlib
33
import shutil
44
import sys
5-
from go._create_extractor_pack_install_script import main
5+
import subprocess
6+
import zipfile
7+
from python.runfiles import runfiles
68

79
try:
810
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
@@ -11,6 +13,14 @@
1113
sys.exit(1)
1214

1315
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go'
16+
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1]))
17+
1418
shutil.rmtree(dest_dir, ignore_errors=True)
15-
os.environ['DESTDIR'] = str(dest_dir)
16-
main(sys.argv)
19+
20+
if installer_or_zip.suffix == '.zip':
21+
dest_dir.mkdir()
22+
with zipfile.ZipFile(installer_or_zip) as pack:
23+
pack.extractall(dest_dir)
24+
else:
25+
os.environ['DESTDIR'] = str(dest_dir)
26+
subprocess.check_call([installer_or_zip])

0 commit comments

Comments
 (0)