-
Notifications
You must be signed in to change notification settings - Fork 450
Store all built-in languages #3811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
bad0a74
e6c21da
97bcdd8
8cf2dc5
130ab2d
7c9e131
cb52ba6
1aef4ed
90d7616
f8b6213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "lib": ["esnext"], | ||
| "rootDir": "../../..", | ||
| "sourceMap": false, | ||
| "noEmit": true, | ||
| }, | ||
| "include": ["./*.ts"], | ||
| "exclude": ["node_modules"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env npx tsx | ||
henrymercer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Updates src/languages/builtin.json by querying the CodeQL CLI for: | ||
| * - Languages that have default queries (via codeql-extractor.yml) | ||
| * - Language aliases (via `codeql resolve languages --format=betterjson --extractor-include-aliases`) | ||
| * | ||
| * Usage: | ||
| * npx tsx .github/workflows/script/update-builtin-languages.ts [path-to-codeql] | ||
| * | ||
| * If no path is given, falls back to "codeql". | ||
| */ | ||
|
|
||
| import { execFileSync } from "node:child_process"; | ||
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
|
|
||
| import * as yaml from "yaml"; | ||
|
|
||
| const codeqlPath = process.argv[2] || "codeql"; | ||
|
|
||
| // Step 1: Resolve all language extractor directories. | ||
henrymercer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const resolveJson: Record<string, string[]> = JSON.parse( | ||
| execFileSync( | ||
| codeqlPath, | ||
| ["resolve", "languages", "--format=json"], | ||
| { encoding: "utf8" }, | ||
| ), | ||
| ); | ||
henrymercer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Step 2: For each language, read codeql-extractor.yml and check default_queries. | ||
| const languages: string[] = []; | ||
|
|
||
| for (const [language, dirs] of Object.entries(resolveJson)) { | ||
| const extractorDir = dirs[0]; | ||
| const extractorYmlPath = path.join(extractorDir, "codeql-extractor.yml"); | ||
|
|
||
| if (!fs.existsSync(extractorYmlPath)) { | ||
| throw new Error(`Extractor YAML not found for language '${language}' at expected path: ${extractorYmlPath}`); | ||
| } | ||
|
|
||
| const extractorYml = yaml.parse(fs.readFileSync(extractorYmlPath, "utf8")); | ||
| const defaultQueries: unknown[] | undefined = extractorYml.default_queries; | ||
|
|
||
| if (Array.isArray(defaultQueries) && defaultQueries.length > 0) { | ||
| console.log(` ✅ ${language}: included (default_queries: ${JSON.stringify(defaultQueries)})`); | ||
| languages.push(language); | ||
| } else { | ||
| console.log(` ❌ ${language}: excluded (no default queries)`); | ||
henrymercer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| languages.sort(); | ||
|
|
||
| // Step 3: Resolve aliases, filtered to only those targeting included languages. | ||
| const betterjsonOutput = JSON.parse( | ||
| execFileSync( | ||
| codeqlPath, | ||
| ["resolve", "languages", "--format=betterjson", "--extractor-include-aliases"], | ||
| { encoding: "utf8" }, | ||
| ), | ||
| ); | ||
|
|
||
| const languageSet = new Set(languages); | ||
| const aliases: Record<string, string> = Object.fromEntries( | ||
| Object.entries((betterjsonOutput.aliases ?? {}) as Record<string, string>) | ||
| .filter(([, target]) => languageSet.has(target)) | ||
| .sort(([a], [b]) => a.localeCompare(b)), | ||
| ); | ||
|
|
||
| // Step 4: Write builtin.json. | ||
| const outputPath = path.join( | ||
| __dirname, | ||
| "..", | ||
| "..", | ||
| "..", | ||
| "src", | ||
| "languages", | ||
| "builtin.json", | ||
| ); | ||
henrymercer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const content = JSON.stringify({ languages, aliases }, null, 2) + "\n"; | ||
| fs.mkdirSync(path.dirname(outputPath), { recursive: true }); | ||
| fs.writeFileSync(outputPath, content); | ||
|
|
||
| console.log(`\nWrote ${outputPath}`); | ||
| console.log(` Languages: ${languages.join(", ")}`); | ||
| console.log(` Aliases: ${Object.keys(aliases).join(", ")}`); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.