Skip to content

Commit

Permalink
When building JMH benchmarks, fail on error, instead of proceeding.
Browse files Browse the repository at this point in the history
Currently, if there are errors in some (but not all) benchmarks, running
`bazel run //path/to/benchmark` will compile them, fail on some, and
then run the rest.

This changes that behavior so that any JMH build failure will fail the
build.
  • Loading branch information
SamirTalwar committed Jan 30, 2020
1 parent cbf3093 commit 929b318
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,24 @@ object BenchmarkGenerator {
classPath: List[Path]
)

private case class GenerationException(messageLines: Seq[String])
extends RuntimeException(messageLines.mkString("\n"))

def main(argv: Array[String]): Unit = {
val args = parseArgs(argv)
generateJmhBenchmark(
args.generatorType,
args.resultSourceJar,
args.resultResourceJar,
args.inputJar,
args.classPath
)
try {
generateJmhBenchmark(
args.generatorType,
args.resultSourceJar,
args.resultResourceJar,
args.inputJar,
args.classPath
)
} catch {
case GenerationException(messageLines) =>
messageLines.foreach(log)
sys.exit(1)
}
}

private def parseArgs(argv: Array[String]): BenchmarkGeneratorArgs = {
Expand Down Expand Up @@ -168,10 +177,8 @@ object BenchmarkGenerator {
generator.generate(source, destination)
generator.complete(source, destination)
if (destination.hasErrors) {
log("JMH Benchmark generator failed")
for (e <- destination.getErrors.asScala) {
log(e.toString)
}
throw new GenerationException(
"JHM Benchmark generator failed" +: destination.getErrors.asScala.map(_.toString).toSeq)
}
}
constructJar(sourceJarOut, tmpSourceDir)
Expand Down

0 comments on commit 929b318

Please sign in to comment.