From 929b3180cc099ba76859f5e88710d2ac087fbfa3 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Thu, 30 Jan 2020 10:34:10 +0100 Subject: [PATCH] When building JMH benchmarks, fail on error, instead of proceeding. 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. --- .../jmh_support/BenchmarkGenerator.scala | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala b/src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala index d367ff424..b443f3e68 100644 --- a/src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala +++ b/src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala @@ -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 = { @@ -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)