Skip to content

Commit

Permalink
Merge pull request #3118 from Gedochao/feature/jmh-directives
Browse files Browse the repository at this point in the history
Add directives for JMH
  • Loading branch information
Gedochao authored Aug 22, 2024
2 parents 834d785 + 644d8b6 commit 5dd4c64
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 290 deletions.
5 changes: 5 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
|
| def ghOrg = "$ghOrg"
| def ghName = "$ghName"
|
| def jmhVersion = "${Deps.Versions.jmh}"
| def jmhOrg = "${Deps.jmhCore.dep.module.organization.value}"
| def jmhCoreModule = "${Deps.jmhCore.dep.module.name.value}"
| def jmhGeneratorBytecodeModule = "${Deps.jmhGeneratorBytecode.dep.module.name.value}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
Expand Down
2 changes: 1 addition & 1 deletion modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ object Build {

build0 match {
case successful: Successful =>
if (options.jmhOptions.runJmh.getOrElse(false) && scope == Scope.Main)
if (options.jmhOptions.canRunJmh && scope == Scope.Main)
value {
val res = jmhBuild(
inputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.build.preprocessing.directives
object DirectivesPreprocessingUtils {
val usingDirectiveHandlers: Seq[DirectiveHandler[BuildOptions]] =
Seq[DirectiveHandler[_ <: HasBuildOptions]](
directives.Benchmarking.handler,
directives.BuildInfo.handler,
directives.ComputeVersion.handler,
directives.Exclude.handler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Bloop extends ScalaCommand[BloopOptions] {
jvm = opts.jvm,
coursier = opts.coursier
)
val options = sharedOptions.buildOptions(false, None).orExit(opts.global.logging.logger)
val options = sharedOptions.buildOptions().orExit(opts.global.logging.logger)

val javaHomeInfo = opts.compilationServer.bloopJvm
.map(JvmUtils.downloadJvm(_, options))
Expand Down
7 changes: 1 addition & 6 deletions modules/cli/src/main/scala/scala/cli/commands/doc/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ object Doc extends ScalaCommand[DocOptions] {

override def buildOptions(options: DocOptions): Option[BuildOptions] =
sharedOptions(options)
.map(shared =>
shared.buildOptions(
enableJmh = shared.benchmarking.jmh.getOrElse(false),
jmhVersion = shared.benchmarking.jmhVersion
).orExit(shared.logger)
)
.map(shared => shared.buildOptions().orExit(shared.logger))

override def helpFormat: HelpFormat = super.helpFormat.withPrimaryGroup(HelpGroup.Doc)

Expand Down
10 changes: 4 additions & 6 deletions modules/cli/src/main/scala/scala/cli/commands/run/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
override def buildOptions(options: RunOptions): Some[BuildOptions] = Some {
import options.*
import options.sharedRun.*
val logger = options.shared.logger
val baseOptions = shared.buildOptions(
enableJmh = shared.benchmarking.jmh.contains(true),
jmhVersion = shared.benchmarking.jmhVersion
).orExit(logger)
val logger = options.shared.logger
val baseOptions = shared.buildOptions().orExit(logger)
baseOptions.copy(
mainClass = mainClass.mainClass,
javaOptions = baseOptions.javaOptions.copy(
Expand Down Expand Up @@ -375,7 +372,8 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {

val mainClassOpt = build.options.mainClass.filter(_.nonEmpty) // trim it too?
.orElse {
if (build.options.jmhOptions.runJmh.contains(false)) Some("org.openjdk.jmh.Main")
if build.options.jmhOptions.enableJmh.contains(true) && !build.options.jmhOptions.canRunJmh
then Some("org.openjdk.jmh.Main")
else None
}
val mainClass = mainClassOpt match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scala.cli.commands.shared

import caseapp.*

import scala.build.internal.Constants
import scala.cli.commands.tags

// format: off
Expand All @@ -12,7 +13,7 @@ final case class BenchmarkingOptions(
jmh: Option[Boolean] = None,
@Group(HelpGroup.Benchmarking.toString)
@Tag(tags.experimental)
@HelpMessage("Set JMH version")
@HelpMessage(s"Set JMH version (default: ${Constants.jmhVersion})")
@ValueDescription("version")
jmhVersion: Option[String] = None
)
Expand Down
Loading

0 comments on commit 5dd4c64

Please sign in to comment.