Skip to content

Commit 77128de

Browse files
committed
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.
1 parent 17990da commit 77128de

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ build:linux --cxxopt=-std=c++20
1414
build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64
1515
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
1616

17+
# this requires developer mode, but is required to have pack installer functioning
18+
common:windows --windows_enable_symlinks --enable_runfiles
19+
1720
common --registry=file:///%workspace%/misc/bazel/registry
1821
common --registry=https://bcr.bazel.build
1922

go/BUILD.bazel

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
22
load("@rules_pkg//pkg:install.bzl", "pkg_install")
33
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
4-
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
54
load("//:defs.bzl", "codeql_platform")
65

76
native_binary(
@@ -81,31 +80,14 @@ pkg_filegroup(
8180
)
8281

8382
pkg_install(
84-
name = "_extractor-pack-installer",
83+
name = "_extractor_pack",
8584
srcs = [":extractor-pack"],
8685
)
8786

88-
# rules_pkg installer is currently broken on Windows
89-
# see https://github.com/bazelbuild/rules_pkg/issues/387
90-
# for now, work around it using an archive
91-
pkg_zip(
92-
name = "_extractor-pack-zip",
93-
srcs = [":extractor-pack"],
94-
)
95-
96-
alias(
97-
name = "_create-extractor-pack-arg",
98-
actual = select({
99-
"@platforms//os:windows": ":_extractor-pack-zip",
100-
"//conditions:default": ":_extractor-pack-installer",
101-
}),
102-
)
103-
10487
py_binary(
10588
name = "create-extractor-pack",
10689
srcs = ["create_extractor_pack.py"],
107-
args = ["$(rlocationpath :_create-extractor-pack-arg)"],
108-
data = [":_create-extractor-pack-arg"],
90+
env = {"REPO_NAME": repo_name()},
10991
main = "create_extractor_pack.py",
110-
deps = ["@rules_python//python/runfiles"],
92+
deps = ["_extractor_pack"],
11193
)

go/create_extractor_pack.py

100644100755
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1+
#!/usr/bin/env python3
12
import os
23
import pathlib
34
import shutil
45
import sys
56
import subprocess
6-
import zipfile
7-
from python.runfiles import runfiles
87

98
try:
109
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
1110
except KeyError:
12-
print("this should be run with bazel run", file=sys.stderr)
13-
sys.exit(1)
11+
res = subprocess.run(["bazel", "run", ":create-extractor-pack"], cwd=pathlib.Path(__file__).parent)
12+
sys.exit(res.returncode)
1413

15-
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go'
16-
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1]))
14+
from go._extractor_pack_install_script import main
1715

18-
shutil.rmtree(dest_dir, ignore_errors=True)
16+
if os.environ['REPO_NAME'] == 'codeql~':
17+
workspace_dir /= 'ql'
1918

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])
19+
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-pack'
20+
shutil.rmtree(dest_dir, ignore_errors=True)
21+
os.environ['DESTDIR'] = str(dest_dir)
22+
main(sys.argv)

0 commit comments

Comments
 (0)