Skip to content

Commit cf68038

Browse files
committed
feat: Add initial generated code
1 parent 31bc9a8 commit cf68038

File tree

134 files changed

+6497
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+6497
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["extractor"]

codeql-extractor.code-workspace

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"folders": [
3+
{
4+
"name": "Library",
5+
"path": "ql/lib"
6+
},
7+
{
8+
"name": "Queries",
9+
"path": "ql/src"
10+
},
11+
{
12+
"name": "Tests",
13+
"path": "ql/test"
14+
},
15+
{
16+
"name": "Extractor",
17+
"path": "extractor"
18+
}
19+
],
20+
"settings": {
21+
"codeQL.runningTests.additionalTestArguments": [
22+
"./extractor-pack"
23+
]
24+
}
25+
}

codeql-extractor.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: bicep
2+
display_name: Bicep
3+
version: 0.1.0
4+
column_kind: utf8
5+
legacy_qltest_extraction: true
6+
build_modes:
7+
- none
8+
github_api_languages:
9+
- Bicep
10+
scc_languages:
11+
- Bicep
12+
file_types:
13+
- name: bicep
14+
display_name: Bicep
15+
extensions:
16+
- .bicep

downgrades/qlpack.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: codeql/bicep-downgrades
2+
groups: bicep
3+
downgrades: .
4+
library: true
5+
warnOnImplicitThis: true

extractor/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "codeql-extractor-bicep"
3+
version = "0.1.0"
4+
authors = ["GitHub"]
5+
edition = "2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
flate2 = "1.0"
11+
clap = { version = "4.4", features = ["derive"] }
12+
tracing = "0.1"
13+
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
14+
rayon = "1.8"
15+
regex = "1.11.1"
16+
# Tree Sitter
17+
tree-sitter-bicep = { path = "./tree-sitter" }
18+
tree-sitter = "^0.24"
19+
# CodeQL - v2.20.4
20+
codeql-extractor = { git = "https://github.com/github/codeql", rev = "c524a98eb91c769cb2994b8373181c2ebd27c20f" }

extractor/src/autobuilder.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::env;
2+
use std::path::PathBuf;
3+
4+
use clap::Args;
5+
6+
use codeql_extractor::autobuilder;
7+
8+
#[derive(Args)]
9+
// The autobuilder takes no command-line options, but this may change in the future.
10+
pub struct Options {}
11+
12+
pub fn run(_: Options) -> std::io::Result<()> {
13+
let database = env::var("CODEQL_EXTRACTOR_BICEP_WIP_DATABASE")
14+
.expect("CODEQL_EXTRACTOR_BICEP_WIP_DATABASE not set");
15+
16+
autobuilder::Autobuilder::new("bicep", PathBuf::from(database))
17+
.include_extensions(&[".bicep"])
18+
.exclude_globs(&["**/.git"])
19+
.size_limit("10m")
20+
.run()
21+
}

extractor/src/extractor.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use clap::Args;
2+
use std::path::PathBuf;
3+
4+
use codeql_extractor::{
5+
extractor::simple::{Extractor, LanguageSpec},
6+
file_paths, trap,
7+
};
8+
9+
#[derive(Args)]
10+
pub struct Options {
11+
/// Sets a custom source achive folder
12+
#[arg(long)]
13+
source_archive_dir: PathBuf,
14+
15+
/// Sets a custom trap folder
16+
#[arg(long)]
17+
output_dir: PathBuf,
18+
19+
/// A text file containing the paths of the files to extract
20+
#[arg(long)]
21+
file_list: String,
22+
}
23+
24+
pub fn run(options: Options) -> std::io::Result<()> {
25+
tracing_subscriber::fmt()
26+
.with_target(false)
27+
.without_time()
28+
.with_level(true)
29+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
30+
.init();
31+
32+
let file_list = file_paths::path_from_string(&options.file_list);
33+
let file_lists: Vec<PathBuf> = vec![file_list];
34+
35+
let extractor = Extractor {
36+
prefix: "bicep".to_string(),
37+
languages: vec![
38+
// Bicep
39+
LanguageSpec {
40+
prefix: "bicep",
41+
ts_language: tree_sitter_bicep::LANGUAGE.into(),
42+
node_types: tree_sitter_bicep::NODE_TYPES,
43+
file_globs: vec!["*.bicep".into()],
44+
},
45+
],
46+
trap_dir: options.output_dir,
47+
trap_compression: trap::Compression::from_env("CODEQL_BICEP_TRAP_COMPRESSION"),
48+
source_archive_dir: options.source_archive_dir,
49+
file_lists,
50+
};
51+
52+
extractor.run()
53+
}

extractor/src/generator.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use clap::Args;
2+
use std::path::PathBuf;
3+
4+
use codeql_extractor::generator::{generate, language::Language};
5+
6+
#[derive(Args)]
7+
pub struct Options {
8+
/// Path of the generated dbscheme file
9+
#[arg(long)]
10+
dbscheme: PathBuf,
11+
12+
/// Path of the generated QLL file
13+
#[arg(long)]
14+
library: PathBuf,
15+
}
16+
17+
pub fn run(options: Options) -> std::io::Result<()> {
18+
codeql_extractor::extractor::set_tracing_level("bicep");
19+
20+
let languages = vec![Language {
21+
name: "BICEP".to_owned(),
22+
node_types: tree_sitter_bicep::NODE_TYPES,
23+
}];
24+
25+
generate(languages, options.dbscheme, options.library)
26+
}

extractor/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use clap::Parser;
2+
3+
mod autobuilder;
4+
mod extractor;
5+
mod generator;
6+
7+
#[derive(Parser)]
8+
#[command(author, version, about)]
9+
enum Cli {
10+
Extract(extractor::Options),
11+
Generate(generator::Options),
12+
Autobuild(autobuilder::Options),
13+
}
14+
15+
fn main() -> std::io::Result<()> {
16+
let cli = Cli::parse();
17+
18+
match cli {
19+
Cli::Extract(options) => extractor::run(options),
20+
Cli::Generate(options) => generator::run(options),
21+
Cli::Autobuild(options) => autobuilder::run(options),
22+
}
23+
}

0 commit comments

Comments
 (0)