Skip to content

Commit 242362a

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 242362a

File tree

7 files changed

+140
-4
lines changed

7 files changed

+140
-4
lines changed

autobuild/action.yml

Lines changed: 11 additions & 0 deletions
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

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/autobuild.ts

Lines changed: 54 additions & 2 deletions
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,58 @@ 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) {
106+
if (
107+
actionInput === "true" &&
108+
!(await codeQlVersionAbove(codeql, "2.15.0"))
109+
) {
110+
logger.warning(
111+
`${featureName} was explicitly requested but is only available starting from CodeQL version 2.15.0, disabling it`,
112+
);
113+
core.exportVariable(envVar, "false");
114+
} else {
115+
logger.info(
116+
`${
117+
actionInput === "true" ? "Enabling" : "Disabling"
118+
} ${featureName} explicitly requested`,
119+
);
120+
core.exportVariable(envVar, actionInput);
121+
}
122+
} else {
123+
const gitHubVersion = await getGitHubVersion();
124+
const repositoryNwo = parseRepositoryNwo(
125+
getRequiredEnvParam("GITHUB_REPOSITORY"),
126+
);
127+
const features = new Features(
128+
gitHubVersion,
129+
repositoryNwo,
130+
getTemporaryDirectory(),
131+
logger,
132+
);
133+
if (await features.getValue(Feature.CppDependencyInstallation, codeql)) {
134+
logger.info(`Enabling ${featureName}`);
135+
core.exportVariable(envVar, "true");
136+
} else {
137+
logger.info(`Disabling ${featureName}`);
138+
core.exportVariable(envVar, "false");
139+
}
140+
}
141+
}
142+
94143
export async function runAutobuild(
95144
language: Language,
96145
config: configUtils.Config,
97146
logger: Logger,
98147
) {
99148
logger.startGroup(`Attempting to automatically build ${language} code`);
100149
const codeQL = await getCodeQL(config.codeQLCmd);
150+
if (language === Language.cpp) {
151+
await setupCppAutobuild(codeQL, logger);
152+
}
101153
await codeQL.runAutobuild(language);
102154
logger.endGroup();
103155
}

src/feature-flags.ts

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy