Skip to content

Commit 765afdb

Browse files
committed
Rust: add option to extract dependencies as source files
1 parent a519eab commit 765afdb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

rust/codeql-extractor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ options:
8282
title: Skip path resolution
8383
description: >
8484
Skip path resolution. This is experimental, while we move path resolution from the extractor to the QL library.
85+
type: string
86+
pattern: "^(false|true)$"
87+
extract_dependencies_as_source:
88+
title: Extract dependencies as source code
89+
description: >
90+
Extract the full source code of dependencies instead of only extracting signatures.
91+
type: string
92+
pattern: "^(false|true)$"

rust/extractor/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub struct Config {
6767
pub extra_includes: Vec<PathBuf>,
6868
pub proc_macro_server: Option<PathBuf>,
6969
pub skip_path_resolution: bool,
70+
pub extract_dependencies_as_source: bool,
7071
}
7172

7273
impl Config {

rust/extractor/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ fn main() -> anyhow::Result<()> {
277277
} else {
278278
ResolvePaths::Yes
279279
};
280+
let library_mode = if cfg.extract_dependencies_as_source {
281+
SourceKind::Source
282+
} else {
283+
SourceKind::Library
284+
};
285+
let library_resolve_paths = if cfg.extract_dependencies_as_source {
286+
resolve_paths
287+
} else {
288+
ResolvePaths::No
289+
};
280290
let mut processed_files: HashSet<PathBuf, RandomState> =
281291
HashSet::from_iter(files.iter().cloned());
282292
for (manifest, files) in map.values().filter(|(_, files)| !files.is_empty()) {
@@ -312,12 +322,13 @@ fn main() -> anyhow::Result<()> {
312322
.source_root(db)
313323
.is_library
314324
{
325+
tracing::info!("file: {}", file.display());
315326
extractor.extract_with_semantics(
316327
file,
317328
&semantics,
318329
vfs,
319-
ResolvePaths::No,
320-
SourceKind::Library,
330+
library_resolve_paths,
331+
library_mode,
321332
);
322333
extractor.archiver.archive(file);
323334
}

0 commit comments

Comments
 (0)