mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
TS: Make AutoBuild aware of CodeQL env vars
This commit is contained in:
@@ -205,7 +205,7 @@ public class AutoBuild {
|
||||
|
||||
public AutoBuild() {
|
||||
this.LGTM_SRC = toRealPath(getPathFromEnvVar("LGTM_SRC"));
|
||||
this.SEMMLE_DIST = getPathFromEnvVar(Env.Var.SEMMLE_DIST.toString());
|
||||
this.SEMMLE_DIST = Paths.get(EnvironmentVariables.getExtractorRoot());
|
||||
this.outputConfig = new ExtractorOutputConfig(LegacyLanguage.JAVASCRIPT);
|
||||
this.trapCache = mkTrapCache();
|
||||
this.typeScriptMode =
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.semmle.js.extractor;
|
||||
|
||||
import com.semmle.util.exception.UserError;
|
||||
import com.semmle.util.process.Env;
|
||||
import com.semmle.util.process.Env.Var;
|
||||
|
||||
public class EnvironmentVariables {
|
||||
public static final String CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR =
|
||||
"CODEQL_EXTRACTOR_JAVASCRIPT_ROOT";
|
||||
|
||||
/**
|
||||
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
|
||||
* SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
|
||||
*/
|
||||
public static String tryGetExtractorRoot() {
|
||||
String env = Env.systemEnv().get(CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR);
|
||||
if (env != null && !env.isEmpty()) return env;
|
||||
env = Env.systemEnv().get(Var.SEMMLE_DIST);
|
||||
if (env != null && !env.isEmpty()) return env;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
|
||||
* SEMMLE_DIST</code> or environment variable, or throws a UserError if neither is set.
|
||||
*/
|
||||
public static String getExtractorRoot() {
|
||||
String env = tryGetExtractorRoot();
|
||||
if (env == null) {
|
||||
throw new UserError("SEMMLE_DIST or CODEQL_EXTRACTOR_JAVASCRIPT_ROOT must be set");
|
||||
}
|
||||
return env;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.semmle.js.extractor.EnvironmentVariables;
|
||||
import com.semmle.js.extractor.ExtractionMetrics;
|
||||
import com.semmle.js.parser.JSParser.Result;
|
||||
import com.semmle.ts.extractor.TypeTable;
|
||||
@@ -290,14 +291,12 @@ public class TypeScriptParser {
|
||||
File parserWrapper;
|
||||
LogbackUtils.getLogger(AbstractProcessBuilder.class).setLevel(Level.INFO);
|
||||
String explicitPath = Env.systemEnv().get(PARSER_WRAPPER_PATH_ENV_VAR);
|
||||
String semmleDistVar = Env.systemEnv().get(Env.Var.SEMMLE_DIST.name());
|
||||
if (explicitPath != null) {
|
||||
parserWrapper = new File(explicitPath);
|
||||
} else if (semmleDistVar != null && !semmleDistVar.isEmpty()) {
|
||||
parserWrapper = new File(semmleDistVar, "tools/typescript-parser-wrapper/main.js");
|
||||
} else {
|
||||
throw new CatastrophicError(
|
||||
"Could not find TypeScript parser: " + Env.Var.SEMMLE_DIST.name() + " is not set.");
|
||||
parserWrapper =
|
||||
new File(
|
||||
EnvironmentVariables.getExtractorRoot(), "tools/typescript-parser-wrapper/main.js");
|
||||
}
|
||||
if (!parserWrapper.isFile())
|
||||
throw new ResourceError(
|
||||
|
||||
Reference in New Issue
Block a user