Skip to content

Commit 78da9d4

Browse files
authored
Merge pull request #310 from sourcegraph/nsc/lsif-buildtool-error-detection
fix LsifBuildTool errors.nonEmpty checks
2 parents 3b574a3 + 928dbdf commit 78da9d4

File tree

2 files changed

+25
-85
lines changed

2 files changed

+25
-85
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
136136
val deps = Dependencies.resolveDependencies(config.dependencies.map(_.repr))
137137
val sourceroot = index.workingDirectory
138138
if (!Files.isDirectory(sourceroot)) {
139-
throw new NoSuchFileException(sourceroot.toString())
139+
throw new NoSuchFileException(sourceroot.toString)
140140
}
141141
val allSourceFiles = collectAllSourceFiles(sourceroot)
142142
val javaFiles = allSourceFiles.filter(path => javaPattern.matches(path))
@@ -150,46 +150,47 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
150150
return CommandResult(0, Nil)
151151
}
152152
val errors = ListBuffer.empty[Try[Unit]]
153-
errors += compileJavaFiles(tmp, deps, config, javaFiles)
154-
errors += compileScalaFiles(deps, scalaFiles)
153+
compileJavaFiles(tmp, deps, config, javaFiles)
154+
.recover(e => errors.addOne(Failure(e)))
155+
compileScalaFiles(deps, scalaFiles).recover(e => errors.addOne(Failure(e)))
155156
if (index.cleanup) {
156157
Files.walkFileTree(tmp, new DeleteVisitor)
157158
}
158159
val isSemanticdbGenerated = Files
159160
.isDirectory(targetroot.resolve("META-INF"))
160161
if (errors.nonEmpty && !isSemanticdbGenerated) {
161162
CommandResult(1, Nil)
162-
} else {
163-
if (isSemanticdbGenerated) {
164-
index
165-
.app
166-
.reporter
167-
.info(
168-
"Some SemanticDB files got generated even if there were compile errors. " +
169-
"In most cases, this means that lsif-java managed to index everything " +
170-
"except the locations that had compile errors and you can ignore the compile errors."
171-
)
172-
}
173-
CommandResult(0, Nil)
163+
} else if (errors.nonEmpty && isSemanticdbGenerated) {
164+
index
165+
.app
166+
.reporter
167+
.info(
168+
"Some SemanticDB files got generated even if there were compile errors. " +
169+
"In most cases, this means that lsif-java managed to index everything " +
170+
"except the locations that had compile errors and you can ignore the compile errors." +
171+
errors.mkString("\n")
172+
)
174173
}
174+
CommandResult(0, Nil)
175175
}
176176

177177
private def compileScalaFiles(
178178
deps: Dependencies,
179179
allScalaFiles: List[Path]
180180
): Try[Unit] =
181181
Try {
182-
withScalaPresentationCompiler(deps) { compiler =>
183-
allScalaFiles.foreach { path =>
184-
try compileScalaFile(compiler, path)
185-
catch {
186-
case NonFatal(e) =>
187-
// We want to try and index as much as possible so we don't fail the entire
188-
// compilation even if a single file fails to compile.
189-
index.app.reporter.log(Diagnostic.exception(e))
182+
if (allScalaFiles.nonEmpty)
183+
withScalaPresentationCompiler(deps) { compiler =>
184+
allScalaFiles.foreach { path =>
185+
try compileScalaFile(compiler, path)
186+
catch {
187+
case NonFatal(e) =>
188+
// We want to try and index as much as possible so we don't fail the entire
189+
// compilation even if a single file fails to compile.
190+
index.app.reporter.log(Diagnostic.exception(e))
191+
}
190192
}
191193
}
192-
}
193194
}
194195

195196
private def compileScalaFile(

tests/unit/src/test/scala/tests/PackageStoreSuite.scala

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)