Skip to content

Commit 1dc6288

Browse files
committed
C++: introduce automatic installation of dependencies in the autobuilder
This introduces the possibility to automatically install dependencies when running the C++ autobuilder on an Ubuntu runner, that will be available with upcoming version 2.15.0. An experimental `cpp-autoinstall-dependencies` input is added to the `autobuild` action. When not set, the default is driven by a feature flag.
1 parent c459726 commit 1dc6288

File tree

7 files changed

+145
-4
lines changed

7 files changed

+145
-4
lines changed

autobuild/action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ inputs:
1212
working directory. If this input is not set, the autobuilder runs with
1313
$GITHUB_WORKSPACE as its working directory.
1414
required: false
15+
cpp-autoinstall-dependencies:
16+
description: >-
17+
Experimental input, the API may change in the future.
18+
Set to true to enable trying to automatically detect and install
19+
dependencies when running the C/C++ autobuilder, set to anything else
20+
to explicitly disable it. This only works when running on Ubuntu and
21+
is automatically disabled otherwise. If this input is not set the
22+
default is currently driven by the cpp_dependency_installation_enabled
23+
feature flag or the CODEQL_CPP_DEPENDENCY_INSTALLATION environment
24+
variable.
25+
required: false
1526
runs:
1627
using: 'node16'
1728
main: '../lib/autobuild-action.js'

lib/autobuild.js

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/autobuild.ts

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { getCodeQL } from "./codeql";
1+
import * as core from "@actions/core";
2+
3+
import { getOptionalInput, getTemporaryDirectory } from "./actions-util";
4+
import { getGitHubVersion } from "./api-client";
5+
import { CodeQL, getCodeQL } from "./codeql";
26
import * as configUtils from "./config-utils";
3-
import { Language, isTracedLanguage } from "./languages";
7+
import { Feature, Features } from "./feature-flags";
8+
import { isTracedLanguage, Language } from "./languages";
49
import { Logger } from "./logging";
10+
import { parseRepositoryNwo } from "./repository";
11+
import { codeQlVersionAbove, getRequiredEnvParam } from "./util";
512

613
export async function determineAutobuildLanguages(
714
config: configUtils.Config,
@@ -91,13 +98,60 @@ export async function determineAutobuildLanguages(
9198
return languages;
9299
}
93100

101+
async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
102+
const envVar = "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES";
103+
const actionInput = getOptionalInput("cpp-autoinstall-dependencies");
104+
const featureName = "C++ automatic installation of dependencies";
105+
if (actionInput === "true") {
106+
if (!(await codeQlVersionAbove(codeql, "2.15.0"))) {
107+
logger.warning(
108+
`${featureName} was explicitly requested but is only available starting from CodeQL version 2.15.0, disabling it`,
109+
);
110+
core.exportVariable(envVar, "false");
111+
} else {
112+
logger.info(
113+
`${
114+
actionInput === "true" ? "Enabling" : "Disabling"
115+
} ${featureName} explicitly requested`,
116+
);
117+
core.exportVariable(envVar, actionInput);
118+
}
119+
} else if (process.env["RUNNER_ENVIRONMENT"] === "self-hosted") {
120+
logger.info(
121+
`Disabling ${featureName} which is the default for self-hosted runners`,
122+
);
123+
core.exportVariable(envVar, "false");
124+
} else {
125+
const gitHubVersion = await getGitHubVersion();
126+
const repositoryNwo = parseRepositoryNwo(
127+
getRequiredEnvParam("GITHUB_REPOSITORY"),
128+
);
129+
const features = new Features(
130+
gitHubVersion,
131+
repositoryNwo,
132+
getTemporaryDirectory(),
133+
logger,
134+
);
135+
if (await features.getValue(Feature.CppDependencyInstallation, codeql)) {
136+
logger.info(`Enabling ${featureName}`);
137+
core.exportVariable(envVar, "true");
138+
} else {
139+
logger.info(`Disabling ${featureName}`);
140+
core.exportVariable(envVar, "false");
141+
}
142+
}
143+
}
144+
94145
export async function runAutobuild(
95146
language: Language,
96147
config: configUtils.Config,
97148
logger: Logger,
98149
) {
99150
logger.startGroup(`Attempting to automatically build ${language} code`);
100151
const codeQL = await getCodeQL(config.codeQLCmd);
152+
if (language === Language.cpp) {
153+
await setupCppAutobuild(codeQL, logger);
154+
}
101155
await codeQL.runAutobuild(language);
102156
logger.endGroup();
103157
}

src/feature-flags.ts

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum Feature {
5151
AnalysisSummaryV2Enabled = "analysis_summary_v2_enabled",
5252
CliConfigFileEnabled = "cli_config_file_enabled",
5353
CodeqlJavaLombokEnabled = "codeql_java_lombok_enabled",
54+
CppDependencyInstallation = "cpp_dependency_installation_enabled",
5455
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
5556
DisablePythonDependencyInstallationEnabled = "disable_python_dependency_installation_enabled",
5657
EvaluatorIntraLayerParallelismEnabled = "evaluator_intra_layer_parallelism_enabled",
@@ -74,6 +75,11 @@ export const featureConfig: Record<
7475
minimumVersion: "2.14.0",
7576
defaultValue: false,
7677
},
78+
[Feature.CppDependencyInstallation]: {
79+
envVar: "CODEQL_CPP_DEPENDENCY_INSTALLATION",
80+
minimumVersion: "2.15.0",
81+
defaultValue: false,
82+
},
7783
[Feature.DisableKotlinAnalysisEnabled]: {
7884
envVar: "CODEQL_DISABLE_KOTLIN_ANALYSIS",
7985
minimumVersion: undefined,

0 commit comments

Comments
 (0)