mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Only extract function bodies for local crates,
unless the -Oextract_dependencies=true flag is supplied
This commit is contained in:
@@ -13,4 +13,24 @@ file_types:
|
||||
- name: rust
|
||||
display_name: Rust files
|
||||
extensions:
|
||||
- .rs
|
||||
- .rs
|
||||
options:
|
||||
trap:
|
||||
title: Options pertaining to TRAP.
|
||||
type: object
|
||||
properties:
|
||||
compression:
|
||||
title: Controls compression for the TRAP files written by the extractor.
|
||||
description: >
|
||||
This option is only intended for use in debugging the extractor. Accepted
|
||||
values are 'brotli' (the default, to write brotli-compressed TRAP), 'gzip', and 'none'
|
||||
(to write uncompressed TRAP).
|
||||
type: string
|
||||
pattern: "^(none|gzip|brotli)$"
|
||||
extract_dependencies:
|
||||
title: Whether to extract dependencies.
|
||||
description: >
|
||||
Extract the source code of dependencies and the standard libraries in addition to
|
||||
normal source code.
|
||||
type: string
|
||||
pattern: "^(false|true)$"
|
||||
|
||||
@@ -32,6 +32,7 @@ pub struct Config {
|
||||
pub scratch_dir: PathBuf,
|
||||
pub trap_dir: PathBuf,
|
||||
pub source_archive_dir: PathBuf,
|
||||
pub extract_dependencies: bool,
|
||||
pub verbose: u8,
|
||||
pub compression: Compression,
|
||||
pub inputs: Vec<PathBuf>,
|
||||
@@ -72,6 +73,7 @@ impl Config {
|
||||
}
|
||||
Figment::new()
|
||||
.merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_"))
|
||||
.merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_OPTION_"))
|
||||
.merge(Serialized::defaults(cli_args))
|
||||
.extract()
|
||||
.context("loading configuration")
|
||||
|
||||
@@ -78,9 +78,16 @@ fn main() -> anyhow::Result<()> {
|
||||
crate_id.into_raw().into_u32()
|
||||
)),
|
||||
);
|
||||
translate::CrateTranslator::new(&db, trap, &krate, &vfs, &archiver)
|
||||
.emit_crate()
|
||||
.context("writing trap file")?;
|
||||
translate::CrateTranslator::new(
|
||||
&db,
|
||||
trap,
|
||||
&krate,
|
||||
&vfs,
|
||||
&archiver,
|
||||
cfg.extract_dependencies,
|
||||
)
|
||||
.emit_crate()
|
||||
.context("writing trap file")?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -32,6 +32,7 @@ pub struct CrateTranslator<'a> {
|
||||
krate: &'a Crate,
|
||||
vfs: &'a Vfs,
|
||||
archiver: &'a Archiver,
|
||||
extract_dependencies: bool,
|
||||
file_labels: HashMap<PathBuf, FileData>,
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@ impl CrateTranslator<'_> {
|
||||
krate: &'a Crate,
|
||||
vfs: &'a Vfs,
|
||||
archiver: &'a Archiver,
|
||||
extract_dependencies: bool,
|
||||
) -> CrateTranslator<'a> {
|
||||
CrateTranslator {
|
||||
db,
|
||||
@@ -49,6 +51,7 @@ impl CrateTranslator<'_> {
|
||||
krate,
|
||||
vfs,
|
||||
archiver,
|
||||
extract_dependencies,
|
||||
file_labels: HashMap::new(),
|
||||
}
|
||||
}
|
||||
@@ -928,20 +931,27 @@ impl CrateTranslator<'_> {
|
||||
}
|
||||
ModuleDef::Function(function) => {
|
||||
let def: ra_ap_hir::DefWithBody = function.into();
|
||||
let (body, source_map) = self.db.body_with_source_map(def.into());
|
||||
let txt = body.pretty_print(self.db, def.into(), Edition::Edition2021);
|
||||
println!("{}", &txt);
|
||||
|
||||
let name = function.name(self.db);
|
||||
|
||||
let location = self.emit_location(function);
|
||||
let body = self.emit_expr(body.body_expr, &body, &source_map);
|
||||
|
||||
let body = if self.extract_dependencies || self.krate.origin(self.db).is_local() {
|
||||
let (body, source_map) = self.db.body_with_source_map(def.into());
|
||||
let txt = body.pretty_print(self.db, def.into(), Edition::Edition2021);
|
||||
println!("{}", &txt);
|
||||
self.emit_expr(body.body_expr, &body, &source_map)
|
||||
} else {
|
||||
self.trap.emit(generated::MissingExpr {
|
||||
id: TrapId::Star,
|
||||
location: None,
|
||||
})
|
||||
};
|
||||
labels.push(self.trap.emit(generated::Function {
|
||||
id: trap_key![module_label, name.as_str()],
|
||||
location,
|
||||
name: name.as_str().into(),
|
||||
body,
|
||||
}));
|
||||
}))
|
||||
}
|
||||
ModuleDef::Adt(adt) => {
|
||||
let location = self.emit_location(adt);
|
||||
|
||||
Reference in New Issue
Block a user