Skip to content

Commit c931beb

Browse files
committed
TS: Make AutoBuild aware of CodeQL env vars
1 parent f958916 commit c931beb

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public class AutoBuild {
205205

206206
public AutoBuild() {
207207
this.LGTM_SRC = toRealPath(getPathFromEnvVar("LGTM_SRC"));
208-
this.SEMMLE_DIST = getPathFromEnvVar(Env.Var.SEMMLE_DIST.toString());
208+
this.SEMMLE_DIST = Paths.get(EnvironmentVariables.getExtractorRoot());
209209
this.outputConfig = new ExtractorOutputConfig(LegacyLanguage.JAVASCRIPT);
210210
this.trapCache = mkTrapCache();
211211
this.typeScriptMode =
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.semmle.js.extractor;
2+
3+
import com.semmle.util.exception.UserError;
4+
import com.semmle.util.process.Env;
5+
import com.semmle.util.process.Env.Var;
6+
7+
public class EnvironmentVariables {
8+
public static final String CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR =
9+
"CODEQL_EXTRACTOR_JAVASCRIPT_ROOT";
10+
11+
/**
12+
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
13+
* SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
14+
*/
15+
public static String tryGetExtractorRoot() {
16+
String env = Env.systemEnv().get(CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR);
17+
if (env != null && !env.isEmpty()) return env;
18+
env = Env.systemEnv().get(Var.SEMMLE_DIST);
19+
if (env != null && !env.isEmpty()) return env;
20+
return null;
21+
}
22+
23+
/**
24+
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
25+
* SEMMLE_DIST</code> or environment variable, or throws a UserError if neither is set.
26+
*/
27+
public static String getExtractorRoot() {
28+
String env = tryGetExtractorRoot();
29+
if (env == null) {
30+
throw new UserError("SEMMLE_DIST or CODEQL_EXTRACTOR_JAVASCRIPT_ROOT must be set");
31+
}
32+
return env;
33+
}
34+
}

javascript/extractor/src/com/semmle/js/parser/TypeScriptParser.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.gson.JsonParseException;
88
import com.google.gson.JsonParser;
99
import com.google.gson.JsonPrimitive;
10+
import com.semmle.js.extractor.EnvironmentVariables;
1011
import com.semmle.js.extractor.ExtractionMetrics;
1112
import com.semmle.js.parser.JSParser.Result;
1213
import com.semmle.ts.extractor.TypeTable;
@@ -290,14 +291,12 @@ private File getParserWrapper() {
290291
File parserWrapper;
291292
LogbackUtils.getLogger(AbstractProcessBuilder.class).setLevel(Level.INFO);
292293
String explicitPath = Env.systemEnv().get(PARSER_WRAPPER_PATH_ENV_VAR);
293-
String semmleDistVar = Env.systemEnv().get(Env.Var.SEMMLE_DIST.name());
294294
if (explicitPath != null) {
295295
parserWrapper = new File(explicitPath);
296-
} else if (semmleDistVar != null && !semmleDistVar.isEmpty()) {
297-
parserWrapper = new File(semmleDistVar, "tools/typescript-parser-wrapper/main.js");
298296
} else {
299-
throw new CatastrophicError(
300-
"Could not find TypeScript parser: " + Env.Var.SEMMLE_DIST.name() + " is not set.");
297+
parserWrapper =
298+
new File(
299+
EnvironmentVariables.getExtractorRoot(), "tools/typescript-parser-wrapper/main.js");
301300
}
302301
if (!parserWrapper.isFile())
303302
throw new ResourceError(

0 commit comments

Comments
 (0)