Skip to content

Commit a609ba1

Browse files
authored
Fix duplicate documents in Bazel index aggregation (#972)
1 parent 04d6a3a commit a609ba1

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

scip-java/src/main/kotlin/org/scip_code/scip_java/buildtools/BazelBuildTool.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ To narrow the set of targets to index or pass additional flags to Bazel, include
137137
Files.walkFileTree(
138138
bazelOutLink,
139139
object : SimpleFileVisitor<Path>() {
140+
override fun preVisitDirectory(
141+
dir: Path,
142+
attrs: BasicFileAttributes,
143+
): FileVisitResult {
144+
// The aspect declares a `<target>.scip-targetroot` directory that
145+
// contains the intermediate per-source `*.scip` shards. Those shards
146+
// are already aggregated into the sibling `<target>.scip` file, so
147+
// including them here would duplicate every document in the index.
148+
return if (dir.fileName.toString().endsWith(".scip-targetroot")) {
149+
FileVisitResult.SKIP_SUBTREE
150+
} else {
151+
FileVisitResult.CONTINUE
152+
}
153+
}
154+
140155
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
141156
if (scipPattern.matches(file)) {
142157
val bytes = Files.readAllBytes(file)

scip-java/src/main/resources/scip-java/scip_java.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ many *.scip (https://github.com/scip-code/scip) files.
1313
These files encode information about which symbols are referenced from which
1414
locations in your source code.
1515
16-
Use the command below to merge all of these SCIP files into a single index:
16+
Use the command below to merge all of these SCIP files into a single index.
17+
The `*.scip-targetroot` directories are excluded because they contain
18+
intermediate per-source shards that are already aggregated into the sibling
19+
`<target>.scip` files:
1720
18-
find bazel-bin/ -type f -name '*.scip' | xargs cat > index.scip
21+
find bazel-bin/ -type f -name '*.scip' -not -path '*.scip-targetroot/*' | xargs cat > index.scip
1922
2023
Use `src code-intel upload` to upload the unified SCIP file to Sourcegraph:
2124

0 commit comments

Comments
 (0)