Skip to content

Commit

Permalink
Tree-sitter: Allow for multiple file lists in simple extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed May 31, 2024
1 parent 4c97b0c commit 69c12eb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ql/extractor/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
trap_dir: options.output_dir,
trap_compression: trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION"),
source_archive_dir: options.source_archive_dir,
file_list: options.file_list,
file_lists: vec![options.file_list],
};

extractor.run()
Expand Down
17 changes: 13 additions & 4 deletions shared/tree-sitter-extractor/src/extractor/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Extractor {
pub languages: Vec<LanguageSpec>,
pub trap_dir: PathBuf,
pub source_archive_dir: PathBuf,
pub file_list: PathBuf,
pub file_lists: Vec<PathBuf>,
// Typically constructed via `trap::Compression::from_env`.
// This allow us to report the error using our diagnostics system
// without exposing it to consumers.
Expand Down Expand Up @@ -74,7 +74,14 @@ impl Extractor {
.build_global()
.unwrap();

let file_list = File::open(&self.file_list)?;
let file_lists: Vec<File> = self
.file_lists
.iter()
.map(|file_list| {
File::open(file_list)
.expect(format!("Unable to open file list at {:?}", file_list).as_str())
})
.collect();

let mut schemas = vec![];
for lang in &self.languages {
Expand Down Expand Up @@ -103,8 +110,10 @@ impl Extractor {
)
};

let lines: std::io::Result<Vec<String>> =
std::io::BufReader::new(file_list).lines().collect();
let lines: std::io::Result<Vec<String>> = file_lists
.iter()
.flat_map(|file_list| std::io::BufReader::new(file_list).lines())
.collect();
let lines = lines?;

lines
Expand Down
2 changes: 1 addition & 1 deletion shared/tree-sitter-extractor/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn simple_extractor() {
languages: vec![language],
trap_dir,
source_archive_dir,
file_list,
file_lists: vec![file_list],
trap_compression: Ok(trap::Compression::Gzip),
};

Expand Down
2 changes: 1 addition & 1 deletion shared/tree-sitter-extractor/tests/multiple_languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn multiple_language_extractor() {
languages: vec![lang_ql, lang_json],
trap_dir,
source_archive_dir,
file_list,
file_lists: vec![file_list],
trap_compression: Ok(trap::Compression::Gzip),
};

Expand Down

0 comments on commit 69c12eb

Please sign in to comment.