Skip to content

Commit 929b318

Browse files
committed
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.
1 parent cbf3093 commit 929b318

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Diff for: src/scala/io/bazel/rules_scala/jmh_support/BenchmarkGenerator.scala

+18-11
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ object BenchmarkGenerator {
4141
classPath: List[Path]
4242
)
4343

44+
private case class GenerationException(messageLines: Seq[String])
45+
extends RuntimeException(messageLines.mkString("\n"))
46+
4447
def main(argv: Array[String]): Unit = {
4548
val args = parseArgs(argv)
46-
generateJmhBenchmark(
47-
args.generatorType,
48-
args.resultSourceJar,
49-
args.resultResourceJar,
50-
args.inputJar,
51-
args.classPath
52-
)
49+
try {
50+
generateJmhBenchmark(
51+
args.generatorType,
52+
args.resultSourceJar,
53+
args.resultResourceJar,
54+
args.inputJar,
55+
args.classPath
56+
)
57+
} catch {
58+
case GenerationException(messageLines) =>
59+
messageLines.foreach(log)
60+
sys.exit(1)
61+
}
5362
}
5463

5564
private def parseArgs(argv: Array[String]): BenchmarkGeneratorArgs = {
@@ -168,10 +177,8 @@ object BenchmarkGenerator {
168177
generator.generate(source, destination)
169178
generator.complete(source, destination)
170179
if (destination.hasErrors) {
171-
log("JMH Benchmark generator failed")
172-
for (e <- destination.getErrors.asScala) {
173-
log(e.toString)
174-
}
180+
throw new GenerationException(
181+
"JHM Benchmark generator failed" +: destination.getErrors.asScala.map(_.toString).toSeq)
175182
}
176183
}
177184
constructJar(sourceJarOut, tmpSourceDir)

0 commit comments

Comments
 (0)