Skip to content

Commit aa2664f

Browse files
Robert Grossefacebook-github-bot
authored andcommitted
Add ability of scip encoder to merge multiple scips
Summary: Modify scip encoder so it can take multiple scip files as input. It will combine the results into the output glean json, skipping any file that appears more than once. Reviewed By: josh-gordon-fb Differential Revision: D78521570 fbshipit-source-id: 644694b1eb00730aab008cde60944b0e66a188b9
1 parent 6b9416e commit aa2664f

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

glean/lang/scip/indexer/scip_to_glean/src/angle.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,20 @@ impl Env {
110110
path_prefix: Option<&str>,
111111
doc: Document,
112112
) -> Result<()> {
113-
let src_file_id = self.next_id();
114113
// todo - adjust filepath with prefix and suffix
115114
let mut filepath = doc.relative_path.to_owned();
116115
if let Some(path_prefix) = path_prefix {
117116
filepath = format!("{}{}", path_prefix, filepath);
118117
}
119118
let filepath = filepath.into_boxed_str();
120119

121-
self.set_def_fact(StringPredicate::File, filepath.clone(), src_file_id);
120+
// Skip files if the same file has already been seen.
121+
// Note that this differs from the Haskell version, which does not have this check.
122+
let (src_file_id, already_seen) =
123+
self.get_or_set_fact(StringPredicate::File, filepath.clone());
124+
if already_seen {
125+
return Ok(());
126+
}
122127

123128
self.out.src_file(src_file_id, filepath.clone());
124129
let lang_file_id = self.next_id();

glean/lang/scip/indexer/scip_to_glean/src/main.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod output;
3838
)]
3939
struct BuildJsonArgs {
4040
#[arg(short, long)]
41-
input: PathBuf,
41+
input: Vec<PathBuf>,
4242
#[arg(short, long)]
4343
output: PathBuf,
4444

@@ -99,13 +99,15 @@ fn build_json(args: BuildJsonArgs) -> Result<()> {
9999
.and_then(|s| LanguageId::new(s).known());
100100

101101
let mut env = Env::new();
102-
decode_scip_data(
103-
&mut env,
104-
&args.input,
105-
default_language,
106-
args.infer_language,
107-
args.root_prefix.as_deref(),
108-
)?;
102+
for input in &args.input {
103+
decode_scip_data(
104+
&mut env,
105+
input,
106+
default_language,
107+
args.infer_language,
108+
args.root_prefix.as_deref(),
109+
)?;
110+
}
109111

110112
let output_facts = env.output();
111113
info!("Found {} facts total", output_facts.total_facts_count());
@@ -213,7 +215,7 @@ mod tests {
213215
let output_json = NamedTempFile::new().expect("unable to create temp file");
214216

215217
let args = BuildJsonArgs {
216-
input: scip_file.path().to_path_buf(),
218+
input: vec![scip_file.path().to_path_buf()],
217219
output: output_json.path().to_path_buf(),
218220
infer_language: true,
219221
language: None,
@@ -235,7 +237,7 @@ mod tests {
235237
let output_json_dir = tempfile::TempDir::new().expect("Unable to create temp dir");
236238

237239
let args = BuildJsonArgs {
238-
input: scip_file.path().to_path_buf(),
240+
input: vec![scip_file.path().to_path_buf()],
239241
output: output_json_dir.path().to_path_buf(),
240242
infer_language: true,
241243
language: None,

0 commit comments

Comments
 (0)