Skip to content

Commit be4fce2

Browse files
authored
Merge pull request github#16631 from hvitved/tree-sitter/multi-file-lists
Tree-sitter: Allow for multiple file lists in simple extractor
2 parents 2d3d49f + d6a3765 commit be4fce2

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

ql/extractor/src/extractor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
5353
trap_dir: options.output_dir,
5454
trap_compression: trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION"),
5555
source_archive_dir: options.source_archive_dir,
56-
file_list: options.file_list,
56+
file_lists: vec![options.file_list],
5757
};
5858

5959
extractor.run()

shared/tree-sitter-extractor/src/extractor/simple.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Extractor {
2020
pub languages: Vec<LanguageSpec>,
2121
pub trap_dir: PathBuf,
2222
pub source_archive_dir: PathBuf,
23-
pub file_list: PathBuf,
23+
pub file_lists: Vec<PathBuf>,
2424
// Typically constructed via `trap::Compression::from_env`.
2525
// This allow us to report the error using our diagnostics system
2626
// without exposing it to consumers.
@@ -74,7 +74,14 @@ impl Extractor {
7474
.build_global()
7575
.unwrap();
7676

77-
let file_list = File::open(&self.file_list)?;
77+
let file_lists: Vec<File> = self
78+
.file_lists
79+
.iter()
80+
.map(|file_list| {
81+
File::open(file_list)
82+
.unwrap_or_else(|_| panic!("Unable to open file list at {:?}", file_list))
83+
})
84+
.collect();
7885

7986
let mut schemas = vec![];
8087
for lang in &self.languages {
@@ -103,8 +110,10 @@ impl Extractor {
103110
)
104111
};
105112

106-
let lines: std::io::Result<Vec<String>> =
107-
std::io::BufReader::new(file_list).lines().collect();
113+
let lines: std::io::Result<Vec<String>> = file_lists
114+
.iter()
115+
.flat_map(|file_list| std::io::BufReader::new(file_list).lines())
116+
.collect();
108117
let lines = lines?;
109118

110119
lines

shared/tree-sitter-extractor/tests/integration_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn simple_extractor() {
3030
languages: vec![language],
3131
trap_dir,
3232
source_archive_dir,
33-
file_list,
33+
file_lists: vec![file_list],
3434
trap_compression: Ok(trap::Compression::Gzip),
3535
};
3636

shared/tree-sitter-extractor/tests/multiple_languages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn multiple_language_extractor() {
3939
languages: vec![lang_ql, lang_json],
4040
trap_dir,
4141
source_archive_dir,
42-
file_list,
42+
file_lists: vec![file_list],
4343
trap_compression: Ok(trap::Compression::Gzip),
4444
};
4545

0 commit comments

Comments
 (0)