Merge branch 'main' into ts-54

This commit is contained in:
erik-krogh
2024-02-25 21:20:43 +01:00
1315 changed files with 80439 additions and 48696 deletions

View File

@@ -1,21 +1,21 @@
load("@//:common.bzl", "codeql_fat_jar", "codeql_java_project")
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
java_library(
name = "deps",
visibility = [":__subpackages__"],
exports = [
"@//extractor:html",
"@//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",
"@semmle_code//extractor:html",
"@semmle_code//extractor:yaml",
"@semmle_code//resources/lib/java:commons-compress",
"@semmle_code//resources/lib/java:gson",
"@semmle_code//resources/lib/java:jericho-html",
"@semmle_code//resources/lib/java:slf4j-api",
"@semmle_code//resources/lib/java:snakeyaml",
"@semmle_code//third_party:jackson",
"@semmle_code//third_party:logback",
"@semmle_code//util-java7",
"@semmle_code//util-java8",
],
)
@@ -36,18 +36,18 @@ 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",
"@semmle_code//extractor:html",
"@semmle_code//extractor:xml-trap-writer",
"@semmle_code//extractor:yaml",
"@semmle_code//resources/lib/java:commons-compress",
"@semmle_code//resources/lib/java:gson",
"@semmle_code//resources/lib/java:jericho-html",
"@semmle_code//resources/lib/java:slf4j-api",
"@semmle_code//resources/lib/java:snakeyaml",
"@semmle_code//third_party:jackson",
"@semmle_code//third_party:logback",
"@semmle_code//util-java7",
"@semmle_code//util-java8",
],
files = [":javascript-extractor-resources"],
main_class = "com.semmle.js.extractor.Main",

View File

@@ -1,4 +1,4 @@
load("@//:common.bzl", "on_windows")
load("@semmle_code//:common.bzl", "on_windows")
# Builds a zip file of the compiled typscript-parser-wrapper and its dependencies.
genrule(

View File

@@ -1,5 +1,15 @@
package com.semmle.js.extractor.test;
import com.google.devtools.build.runfiles.Runfiles;
import com.semmle.util.process.Env;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -18,4 +28,35 @@ import org.junit.runners.Suite.SuiteClasses;
RobustnessTests.class,
NumericSeparatorTests.class
})
public class AllTests {}
public class AllTests {
@BeforeClass
public static void setUp() throws Exception {
Runfiles.Preloaded runfiles = Runfiles.preload();
String nodePath = runfiles.unmapped().rlocation(System.getenv("NODE_BIN"));
String tsWrapperZip = runfiles.unmapped().rlocation(System.getenv("TS_WRAPPER_ZIP"));
Path tempDir = Files.createTempDirectory("ts-wrapper");
// extract the ts-wrapper.zip to tempDir:
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(tsWrapperZip))) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
Path entryPath = tempDir.resolve(entry.getName());
if (entry.isDirectory()) {
Files.createDirectories(entryPath);
} else {
Files.copy(zis, entryPath);
}
entry = zis.getNextEntry();
}
}
Path tsWrapper = tempDir.resolve("javascript/tools/typescript-parser-wrapper/main.js");
if (!Files.exists(tsWrapper)) {
throw new RuntimeException("Could not find ts-wrapper at " + tsWrapper);
}
Map<String, String> envUpdate = new HashMap<>();
envUpdate.put("SEMMLE_TYPESCRIPT_NODE_RUNTIME", nodePath);
envUpdate.put("SEMMLE_TYPESCRIPT_PARSER_WRAPPER", tsWrapper.toString());
Env.systemEnv().pushEnvironmentContext(envUpdate);
}
}

View File

@@ -1,33 +1,21 @@
java_test(
name = "test_jar",
name = "test",
srcs = glob(["**/*.java"]),
data = [
"//javascript/extractor/lib/typescript",
"//javascript/extractor/parser-tests",
"//javascript/extractor/tests",
"@nodejs//:node_bin",
],
env = {
"NODE_BIN": "$(rlocationpath @nodejs//:node_bin)",
"TS_WRAPPER_ZIP": "$(rlocationpath //javascript/extractor/lib/typescript)",
},
test_class = "com.semmle.js.extractor.test.AllTests",
deps = [
"//javascript/extractor",
"//javascript/extractor:deps",
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
"@bazel_tools//tools/java/runfiles",
"@semmle_code//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
],
)
# We need to unzip the typescript wrapper, and provide node on the path.
# Therefore, we're wrapping the java_test inside a sh_test.
sh_test(
name = "test",
size = "small",
srcs = ["run_tests.sh"],
args = [
"$(execpath @nodejs//:node_bin)",
"$(JAVABASE)/bin/java",
"$(rootpath //javascript/extractor/lib/typescript)",
"$(rootpath test_jar_deploy.jar)",
],
data = [
":test_jar_deploy.jar",
"//javascript/extractor/lib/typescript",
"//javascript/extractor/parser-tests",
"//javascript/extractor/tests",
"@bazel_tools//tools/jdk:current_java_runtime",
"@nodejs//:node_bin",
],
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
)

View File

@@ -1,31 +0,0 @@
NODE=$1
JAVA=$2
PARSER_WRAPPER=$3
TEST_JAR=$4
TEMP=$(mktemp -d)
UNAME=$(uname -s)
echo $UNAME
# On Windows, the symlink set up by bazel that points at the test jar is a msys2/linux-style path
# The JVM can't resolve that, therefore copy the jar to the temp directory, and then set the
# windows path to it
if [[ "$UNAME" =~ _NT ]]; then
cp $TEST_JAR $TEMP/test.jar
TEST_JAR=$(cygpath -w $TEMP/test.jar)
echo "On Windows, new test jar: $TEST_JAR"
fi
# unpack parser wrapper
unzip -q $PARSER_WRAPPER -d $TEMP/parser_wrapper
export SEMMLE_TYPESCRIPT_PARSER_WRAPPER=$TEMP/parser_wrapper/javascript/tools/typescript-parser-wrapper/main.js
# setup node on path
NODE=$(realpath $NODE)
export PATH="$PATH:$(dirname $NODE)"
$JAVA -Dbazel.test_suite=com.semmle.js.extractor.test.AllTests -jar $TEST_JAR
EXIT_CODE=$?
rm -rf $TEMP
exit $EXIT_CODE

View File

@@ -1 +1 @@
**/ql/javascript/extractor/tests/*/input//
**/*ql*/javascript/extractor/tests/*/input//