Skip to content

Commit 6c7ea86

Browse files
committed
Introduce a bazel-based build for the entire JS pack.
1 parent 465eb00 commit 6c7ea86

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

javascript/BUILD.bazel

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
load("@//:dist.bzl", "dist")
2+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
3+
load("@//buildutils-internal:zipmerge.bzl", "zipmerge")
4+
15
package(default_visibility = ["//visibility:public"])
26

37
alias(
@@ -9,3 +13,36 @@ alias(
913
name = "dbscheme-stats",
1014
actual = "//javascript/ql/lib:dbscheme-stats",
1115
)
16+
17+
pkg_files(
18+
name = "dbscheme-group",
19+
srcs = [
20+
":dbscheme",
21+
":dbscheme-stats",
22+
],
23+
strip_prefix = None,
24+
)
25+
26+
dist(
27+
name = "javascript-extractor-pack",
28+
srcs = [
29+
":dbscheme-group",
30+
"//javascript/downgrades",
31+
"//javascript/externs",
32+
"//javascript/extractor:tools-extractor",
33+
"@//language-packs/javascript:resources",
34+
],
35+
prefix = "javascript",
36+
)
37+
38+
# We have to zipmerge in the typescript parser wrapper, as it's generated by a genrule
39+
# and we don't know a list of its output files. Therefore, we sidestep the
40+
# rules_pkg tooling here, and generate the zip for the language pack manually.
41+
zipmerge(
42+
name = "javascript",
43+
srcs = [
44+
":javascript-extractor-pack.zip",
45+
"//javascript/extractor/lib/typescript",
46+
],
47+
out = "javascript.zip",
48+
)

javascript/downgrades/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@//:dist.bzl", "pack_zip")
2+
3+
pack_zip(
4+
name = "downgrades",
5+
srcs = glob(
6+
["**/*"],
7+
exclude = ["BUILD.bazel"],
8+
),
9+
prefix = "downgrades",
10+
visibility = ["//visibility:public"],
11+
)

javascript/externs/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@//:dist.bzl", "pack_zip")
2+
3+
pack_zip(
4+
name = "externs",
5+
srcs = glob(
6+
["**/*"],
7+
exclude = ["BUILD.bazel"],
8+
),
9+
prefix = "tools/data/externs",
10+
visibility = ["//visibility:public"],
11+
)

javascript/extractor/BUILD.bazel

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
load("@//:common.bzl", "codeql_java_project")
1+
load("@//:common.bzl", "codeql_fat_jar", "codeql_java_project")
2+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
23

34
codeql_java_project(
45
name = "extractor",
@@ -17,3 +18,39 @@ codeql_java_project(
1718
"@//util-java8",
1819
],
1920
)
21+
22+
pkg_files(
23+
name = "javascript-extractor-resources",
24+
srcs = glob(["resources/**"]),
25+
strip_prefix = "resources",
26+
)
27+
28+
codeql_fat_jar(
29+
name = "extractor-javascript",
30+
srcs = [
31+
":extractor",
32+
"@//extractor:html",
33+
"@//extractor:xml-trap-writer",
34+
"@//extractor:yaml",
35+
"@//resources/lib/java:commons-compress",
36+
"@//resources/lib/java:gson",
37+
"@//resources/lib/java:jericho-html",
38+
"@//resources/lib/java:slf4j-api",
39+
"@//resources/lib/java:snakeyaml",
40+
"@//third_party:jackson",
41+
"@//third_party:logback",
42+
"@//util-java7",
43+
"@//util-java8",
44+
],
45+
files = [":javascript-extractor-resources"],
46+
main_class = "com.semmle.js.extractor.Main",
47+
)
48+
49+
pkg_files(
50+
name = "tools-extractor",
51+
srcs = [
52+
":extractor-javascript",
53+
],
54+
prefix = "tools",
55+
visibility = ["//visibility:public"],
56+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
load("@//:common.bzl", "on_windows")
2+
3+
# Builds a zip file of the compiled typscript-parser-wrapper and its dependencies.
4+
genrule(
5+
name = "typescript",
6+
srcs = [
7+
"tsconfig.json",
8+
"package.json",
9+
"package-lock.json",
10+
] + glob(["src/**"]),
11+
outs = ["javascript.zip"],
12+
cmd = " && ".join([
13+
# the original working directory is not preserved anywhere, but needs to be accessible, as
14+
# all paths are relative to this
15+
# unfortunately, we need to change the working directory to run npm.
16+
"export BAZEL_ROOT=$$(pwd)",
17+
# we need a temp dir, and unfortunately, $TMPDIR is not set on Windows
18+
"export TEMP=$$(mktemp -d)",
19+
# Add node to the path so that npm run can find it - it's calling env node
20+
"export PATH=$$PATH:$$BAZEL_ROOT/$$(dirname $(execpath @nodejs//:node_bin))",
21+
"export NPM=$$BAZEL_ROOT/$(execpath @nodejs//:npm_bin)",
22+
# npm has a global cache which doesn't work on macos, where absolute paths aren't filtered out by the sandbox.
23+
# Therefore, set a temporary cache directory.
24+
"export NPM_CONFIG_USERCONFIG=$$TEMP/npmrc",
25+
"$$NPM config set cache $$TEMP/npm",
26+
"$$NPM config set update-notifier false",
27+
"rm -rf $(RULEDIR)/inputs",
28+
"cp -L -R $$(dirname $(execpath package.json)) $(RULEDIR)/inputs",
29+
"cd $(RULEDIR)/inputs",
30+
"$$NPM install",
31+
"$$NPM run build",
32+
"rm -rf node_modules",
33+
# Install again with only runtime deps
34+
"$$NPM install --prod",
35+
"mv node_modules build/",
36+
"mkdir -p javascript/tools/typescript-parser-wrapper",
37+
"mv build/* javascript/tools/typescript-parser-wrapper",
38+
"",
39+
]) + on_windows(
40+
" && ".join([
41+
"$$BAZEL_ROOT/$(execpath @bazel_tools//tools/zip:zipper) cC $$(cygpath -w $$BAZEL_ROOT/$@) $$(find javascript -name '*' -print)",
42+
"rm -rf $$TEMP",
43+
]),
44+
" && ".join([
45+
"$$BAZEL_ROOT/$(execpath @bazel_tools//tools/zip:zipper) cC $$BAZEL_ROOT/$@ $$(find javascript -name '*' -print)",
46+
"rm -rf $$TEMP",
47+
]),
48+
),
49+
tools = [
50+
"@bazel_tools//tools/zip:zipper",
51+
"@nodejs//:node_bin",
52+
"@nodejs//:npm_bin",
53+
],
54+
visibility = ["//visibility:public"],
55+
)

0 commit comments

Comments
 (0)