Introduce a bazel-based build for the entire JS pack.

This commit is contained in:
Cornelius Riemenschneider
2023-11-03 11:14:22 +01:00
parent 465eb00228
commit 6c7ea86a12
5 changed files with 152 additions and 1 deletions

View File

@@ -1,3 +1,7 @@
load("@//:dist.bzl", "dist")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("@//buildutils-internal:zipmerge.bzl", "zipmerge")
package(default_visibility = ["//visibility:public"])
alias(
@@ -9,3 +13,36 @@ alias(
name = "dbscheme-stats",
actual = "//javascript/ql/lib:dbscheme-stats",
)
pkg_files(
name = "dbscheme-group",
srcs = [
":dbscheme",
":dbscheme-stats",
],
strip_prefix = None,
)
dist(
name = "javascript-extractor-pack",
srcs = [
":dbscheme-group",
"//javascript/downgrades",
"//javascript/externs",
"//javascript/extractor:tools-extractor",
"@//language-packs/javascript:resources",
],
prefix = "javascript",
)
# We have to zipmerge in the typescript parser wrapper, as it's generated by a genrule
# and we don't know a list of its output files. Therefore, we sidestep the
# rules_pkg tooling here, and generate the zip for the language pack manually.
zipmerge(
name = "javascript",
srcs = [
":javascript-extractor-pack.zip",
"//javascript/extractor/lib/typescript",
],
out = "javascript.zip",
)

View File

@@ -0,0 +1,11 @@
load("@//:dist.bzl", "pack_zip")
pack_zip(
name = "downgrades",
srcs = glob(
["**/*"],
exclude = ["BUILD.bazel"],
),
prefix = "downgrades",
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,11 @@
load("@//:dist.bzl", "pack_zip")
pack_zip(
name = "externs",
srcs = glob(
["**/*"],
exclude = ["BUILD.bazel"],
),
prefix = "tools/data/externs",
visibility = ["//visibility:public"],
)

View File

@@ -1,4 +1,5 @@
load("@//:common.bzl", "codeql_java_project")
load("@//:common.bzl", "codeql_fat_jar", "codeql_java_project")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
codeql_java_project(
name = "extractor",
@@ -17,3 +18,39 @@ codeql_java_project(
"@//util-java8",
],
)
pkg_files(
name = "javascript-extractor-resources",
srcs = glob(["resources/**"]),
strip_prefix = "resources",
)
codeql_fat_jar(
name = "extractor-javascript",
srcs = [
":extractor",
"@//extractor:html",
"@//extractor:xml-trap-writer",
"@//extractor:yaml",
"@//resources/lib/java:commons-compress",
"@//resources/lib/java:gson",
"@//resources/lib/java:jericho-html",
"@//resources/lib/java:slf4j-api",
"@//resources/lib/java:snakeyaml",
"@//third_party:jackson",
"@//third_party:logback",
"@//util-java7",
"@//util-java8",
],
files = [":javascript-extractor-resources"],
main_class = "com.semmle.js.extractor.Main",
)
pkg_files(
name = "tools-extractor",
srcs = [
":extractor-javascript",
],
prefix = "tools",
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,55 @@
load("@//:common.bzl", "on_windows")
# Builds a zip file of the compiled typscript-parser-wrapper and its dependencies.
genrule(
name = "typescript",
srcs = [
"tsconfig.json",
"package.json",
"package-lock.json",
] + glob(["src/**"]),
outs = ["javascript.zip"],
cmd = " && ".join([
# the original working directory is not preserved anywhere, but needs to be accessible, as
# all paths are relative to this
# unfortunately, we need to change the working directory to run npm.
"export BAZEL_ROOT=$$(pwd)",
# we need a temp dir, and unfortunately, $TMPDIR is not set on Windows
"export TEMP=$$(mktemp -d)",
# Add node to the path so that npm run can find it - it's calling env node
"export PATH=$$PATH:$$BAZEL_ROOT/$$(dirname $(execpath @nodejs//:node_bin))",
"export NPM=$$BAZEL_ROOT/$(execpath @nodejs//:npm_bin)",
# npm has a global cache which doesn't work on macos, where absolute paths aren't filtered out by the sandbox.
# Therefore, set a temporary cache directory.
"export NPM_CONFIG_USERCONFIG=$$TEMP/npmrc",
"$$NPM config set cache $$TEMP/npm",
"$$NPM config set update-notifier false",
"rm -rf $(RULEDIR)/inputs",
"cp -L -R $$(dirname $(execpath package.json)) $(RULEDIR)/inputs",
"cd $(RULEDIR)/inputs",
"$$NPM install",
"$$NPM run build",
"rm -rf node_modules",
# Install again with only runtime deps
"$$NPM install --prod",
"mv node_modules build/",
"mkdir -p javascript/tools/typescript-parser-wrapper",
"mv build/* javascript/tools/typescript-parser-wrapper",
"",
]) + on_windows(
" && ".join([
"$$BAZEL_ROOT/$(execpath @bazel_tools//tools/zip:zipper) cC $$(cygpath -w $$BAZEL_ROOT/$@) $$(find javascript -name '*' -print)",
"rm -rf $$TEMP",
]),
" && ".join([
"$$BAZEL_ROOT/$(execpath @bazel_tools//tools/zip:zipper) cC $$BAZEL_ROOT/$@ $$(find javascript -name '*' -print)",
"rm -rf $$TEMP",
]),
),
tools = [
"@bazel_tools//tools/zip:zipper",
"@nodejs//:node_bin",
"@nodejs//:npm_bin",
],
visibility = ["//visibility:public"],
)