Skip to content

Commit

Permalink
Honor the Lua tracer FF for database trace-command invocations for …
Browse files Browse the repository at this point in the history
…scanned languages.

In theory, a scanned language will not setup the build tracer, and so
shouldn't care about lua versus legacy tracing. However, `go` is a
special case where the autobuilder runs under the build tracer, that
then gets disabled immediately again, unless a special environment
variable is used.
Therefore, we need to thread through the feature flag to this
`database trace-command` invocation. For other scanned languages,
this should be a no-op, as no tracing is ever set up.
  • Loading branch information
criemen authored Jun 27, 2022
1 parent 47bcabd commit f422a50
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 23 deletions.
6 changes: 5 additions & 1 deletion lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/runner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/runner.js.map

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/analyze-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
runQueries,
runFinalize,
} from "./analyze";
import { getGitHubVersionActionsOnly } from "./api-client";
import { CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { uploadDatabases } from "./database-upload";
import { GitHubFeatureFlags } from "./feature-flags";
import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import * as upload_lib from "./upload-lib";
Expand Down Expand Up @@ -112,7 +114,16 @@ async function run() {
util.getRequiredEnvParam("GITHUB_REPOSITORY")
);

await runFinalize(outputDir, threads, memory, config, logger);
const gitHubVersion = await getGitHubVersionActionsOnly();

const featureFlags = new GitHubFeatureFlags(
gitHubVersion,
apiDetails,
repositoryNwo,
logger
);

await runFinalize(outputDir, threads, memory, config, logger, featureFlags);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
runStats = await runQueries(
outputDir,
Expand Down
23 changes: 17 additions & 6 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "./codeql";
import * as configUtils from "./config-utils";
import { countLoc } from "./count-loc";
import { FeatureFlags } from "./feature-flags";
import { isScannedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import * as sharedEnv from "./shared-environment";
Expand Down Expand Up @@ -116,7 +117,8 @@ async function setupPythonExtractor(logger: Logger) {

async function createdDBForScannedLanguages(
config: configUtils.Config,
logger: Logger
logger: Logger,
featureFlags: FeatureFlags
) {
// Insert the LGTM_INDEX_X env vars at this point so they are set when
// we extract any scanned languages.
Expand All @@ -136,7 +138,8 @@ async function createdDBForScannedLanguages(

await codeql.extractScannedLanguage(
util.getCodeQLDatabasePath(config, language),
language
language,
featureFlags
);
logger.endGroup();
}
Expand Down Expand Up @@ -166,9 +169,10 @@ async function finalizeDatabaseCreation(
config: configUtils.Config,
threadsFlag: string,
memoryFlag: string,
logger: Logger
logger: Logger,
featureFlags: FeatureFlags
) {
await createdDBForScannedLanguages(config, logger);
await createdDBForScannedLanguages(config, logger, featureFlags);

const codeql = await getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
Expand Down Expand Up @@ -425,7 +429,8 @@ export async function runFinalize(
threadsFlag: string,
memoryFlag: string,
config: configUtils.Config,
logger: Logger
logger: Logger,
featureFlags: FeatureFlags
) {
const codeql = await getCodeQL(config.codeQLCmd);
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
Expand All @@ -445,7 +450,13 @@ export async function runFinalize(
}
await fs.promises.mkdir(outputDir, { recursive: true });

await finalizeDatabaseCreation(config, threadsFlag, memoryFlag, logger);
await finalizeDatabaseCreation(
config,
threadsFlag,
memoryFlag,
logger,
featureFlags
);
}

export async function runCleanup(
Expand Down
23 changes: 21 additions & 2 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export interface CodeQL {
* Extract code for a scanned language using 'codeql database trace-command'
* and running the language extractor.
*/
extractScannedLanguage(database: string, language: Language): Promise<void>;
extractScannedLanguage(
database: string,
language: Language,
featureFlags: FeatureFlags
): Promise<void>;
/**
* Finalize a database using 'codeql database finalize'.
*/
Expand Down Expand Up @@ -789,7 +793,11 @@ async function getCodeQLForCmd(

await runTool(autobuildCmd);
},
async extractScannedLanguage(databasePath: string, language: Language) {
async extractScannedLanguage(
databasePath: string,
language: Language,
featureFlags: FeatureFlags
) {
// Get extractor location
let extractorPath = "";
await new toolrunner.ToolRunner(
Expand Down Expand Up @@ -821,13 +829,24 @@ async function getCodeQLForCmd(
"tools",
`autobuild${ext}`
);
const extraArgs: string[] = [];
if (
await util.codeQlVersionAbove(this, CODEQL_VERSION_LUA_TRACER_CONFIG)
) {
if (await featureFlags.getValue(FeatureFlag.LuaTracerConfigEnabled)) {
extraArgs.push("--internal-use-lua-tracing");
} else {
extraArgs.push("--no-internal-use-lua-tracing");
}
}

// Run trace command
await toolrunnerErrorCatcher(
cmd,
[
"database",
"trace-command",
...extraArgs,
...getExtraOptionsFromEnv(["database", "trace-command"]),
databasePath,
"--",
Expand Down
9 changes: 8 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,14 @@ program
logger
);
const memory = getMemoryFlag(cmd.ram || initEnv["CODEQL_RAM"]);
await runFinalize(outputDir, threads, memory, config, logger);
await runFinalize(
outputDir,
threads,
memory,
config,
logger,
createFeatureFlags([])
);
await runQueries(
outputDir,
memory,
Expand Down

0 comments on commit f422a50

Please sign in to comment.