Skip to content

Commit 83e92ed

Browse files
committed
Improve detection of Rust in languages input
1 parent cfb8d07 commit 83e92ed

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

lib/config-utils.js

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

lib/config-utils.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/init-action.js

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

lib/init-action.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/config-utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ export async function getLanguages(
398398
return languages;
399399
}
400400

401+
export function getRawLanguagesNoAutodetect(
402+
languagesInput: string | undefined,
403+
): string[] {
404+
return (languagesInput || "")
405+
.split(",")
406+
.map((x) => x.trim().toLowerCase())
407+
.filter((x) => x.length > 0);
408+
}
409+
401410
/**
402411
* Gets the set of languages in the current repository without checking to
403412
* see if these languages are actually supported by CodeQL.
@@ -416,12 +425,8 @@ export async function getRawLanguages(
416425
rawLanguages: string[];
417426
autodetected: boolean;
418427
}> {
419-
// Obtain from action input 'languages' if set
420-
const languagesFromInput = (languagesInput || "")
421-
.split(",")
422-
.map((x) => x.trim().toLowerCase())
423-
.filter((x) => x.length > 0);
424428
// If the user has specified languages, use those.
429+
const languagesFromInput = getRawLanguagesNoAutodetect(languagesInput);
425430
if (languagesFromInput.length) {
426431
return { rawLanguages: languagesFromInput, autodetected: false };
427432
}

src/init-action.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,16 @@ async function run() {
362362
}
363363
core.endGroup();
364364

365-
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
366-
if (getOptionalInput("languages")?.includes(KnownLanguage.rust)) {
365+
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for Rust. We need to set this environment
366+
// variable before initializing the config, otherwise Rust analysis will not be
367+
// enabled.
368+
if (
369+
// Only enable Rust analysis if the user has explicitly requested it - don't
370+
// enable it via language autodetection.
371+
configUtils
372+
.getRawLanguagesNoAutodetect(getOptionalInput("languages"))
373+
.includes(KnownLanguage.rust)
374+
) {
367375
const feat = Feature.RustAnalysis;
368376
const minVer = featureConfig[feat].minimumVersion as string;
369377
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";

0 commit comments

Comments
 (0)