From 47f5adfff329982d9af54170c4917be560944879 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewa Date: Tue, 10 Sep 2019 18:53:23 +0200 Subject: [PATCH] Debugging flags for benchOnly (#179) --- build.sbt | 10 +++--- project/BenchTasks.scala | 12 +++++++ ...ugCommand.scala => WithDebugCommand.scala} | 32 +++++++++++++------ 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 project/BenchTasks.scala rename project/{RunDebugCommand.scala => WithDebugCommand.scala} (69%) diff --git a/build.sbt b/build.sbt index 2257c9dea4..2d884e03e2 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,6 @@ import scala.sys.process._ +import org.enso.build.BenchTasks._ +import org.enso.build.WithDebugCommand // Global Configuration organization := "org.enso" @@ -15,9 +17,9 @@ scalacOptions ++= Seq( javacOptions ++= Seq("-source", "12", "-target", "1.8") // Benchmark Configuration -lazy val Benchmark = config("bench") extend Test -lazy val bench = taskKey[Unit]("Run Benchmarks") -lazy val benchOnly = inputKey[Unit]("Run benchmarks by name substring") +lazy val Benchmark = config("bench") extend sbt.Test + +// Native Image Generation lazy val buildNativeImage = taskKey[Unit]("Build native image for the Enso executable") @@ -93,7 +95,7 @@ lazy val interpreter = (project in file("Interpreter")) mainClass in (Compile, run) := Some("org.enso.interpreter.Main"), version := "0.1" ) - .settings(commands += RunDebugCommand.runDebug) + .settings(commands += WithDebugCommand.withDebug) .settings( libraryDependencies ++= Seq( "com.chuusai" %% "shapeless" % "2.3.3", diff --git a/project/BenchTasks.scala b/project/BenchTasks.scala new file mode 100644 index 0000000000..9d06cc4bc9 --- /dev/null +++ b/project/BenchTasks.scala @@ -0,0 +1,12 @@ +package org.enso.build + +import sbt.inputKey +import sbt.taskKey + +/** + * Defines benchmarking related task keys. + */ +object BenchTasks { + lazy val bench = taskKey[Unit]("Run Benchmarks") + lazy val benchOnly = inputKey[Unit]("Run benchmarks by name substring") +} diff --git a/project/RunDebugCommand.scala b/project/WithDebugCommand.scala similarity index 69% rename from project/RunDebugCommand.scala rename to project/WithDebugCommand.scala index 1e19d98303..c5f1681adb 100644 --- a/project/RunDebugCommand.scala +++ b/project/WithDebugCommand.scala @@ -1,17 +1,20 @@ -import sbt.Keys.javaOptions +package org.enso.build + import sbt._ -/** Command allowing to run the CLI program with additional JVM-level flags. - * The supported flags are: +/** Command allowing to run a task with additional JVM-level flags. + * Supported tasks are run and benchOnly. + * Supported flags are: * * `--dumpGraphs`: dumps IGV output of the program * * `--showCompilations`: prints Truffle compilation traces * * `--printAssembly`: prints the disassembler output - * Any CLI arguments should be passed following `--` like so: + * Any task arguments should be passed following `--` like so: * {{{ - * runDebug --dumpGraphs --printAssembly -- --run myFile.enso + * withDebug run --dumpGraphs --printAssembly -- --run myFile.enso + * withDebug benchOnly --showCompilations -- myBenchmark * }}} */ -object RunDebugCommand { +object WithDebugCommand { val truffleNoBackgroundCompilationOptions = Seq( "-Dgraal.TruffleBackgroundCompilation=false" @@ -42,13 +45,22 @@ object RunDebugCommand { val argSeparator = "--" - val commandName = "runDebug" + val commandName = "withDebug" + + val benchOnlyCommandName = "benchOnly" + val runCommandName = "run" /** The main logic for parsing and transforming the debug flags into JVM level flags */ - def runDebug: Command = Command.args(commandName, "") { + def withDebug: Command = Command.args(commandName, "") { (state, args) => val (debugFlags, prefixedRunArgs) = args.span(_ != argSeparator) val runArgs = " " + prefixedRunArgs.drop(1).mkString(" ") + + val taskKey = + if (debugFlags.contains(benchOnlyCommandName)) BenchTasks.benchOnly + else if (debugFlags.contains(runCommandName)) Compile / Keys.run + else throw new IllegalArgumentException("Invalid command name.") + val dumpGraphsOpts = if (debugFlags.contains(dumpGraphsOption)) truffleDumpGraphsOptions else Seq() @@ -69,12 +81,12 @@ object RunDebugCommand { val extracted = Project.extract(state) val withJavaOpts = extracted.appendWithoutSession( - Seq(Compile / Keys.run / Keys.javaOptions ++= javaOpts), + Seq(Compile / Keys.javaOptions ++= javaOpts), state ) Project .extract(withJavaOpts) - .runInputTask(Compile / Keys.run, runArgs, withJavaOpts) + .runInputTask(taskKey, runArgs, withJavaOpts) state } }