diff --git a/scalafix/BUILD b/scalafix/BUILD new file mode 100644 index 0000000..4783bfa --- /dev/null +++ b/scalafix/BUILD @@ -0,0 +1,15 @@ +load("//rules:scala.bzl", "scala_binary") + +scala_binary( + name = "scalafmt", + args = [ + "--toolchain=", + "--opts=:--verbose:--config", + ], + main_class = "rules_scala3.scalafix.src.Main", + scala = "//scala:bootstrap_3", + visibility = ["//visibility:public"], + deps = [ + "@rules_scala3//3rdparty/jvm/com/github/scopt", + ], +) diff --git a/scalafix/run_scalafix.bzl b/scalafix/run_scalafix.bzl new file mode 100644 index 0000000..e69de29 diff --git a/scalafix/src/ArgsConfig.scala b/scalafix/src/ArgsConfig.scala new file mode 100644 index 0000000..e9aa5d6 --- /dev/null +++ b/scalafix/src/ArgsConfig.scala @@ -0,0 +1,43 @@ +package rules_scala3.scalafix.src + +import scopt.OParser + +case class ArgsConfig( + toolchain: Option[String] = None, + scalafixOpts: Option[String] = None, + targets: Seq[String] = Seq.empty, + excludedTargets: Seq[String] = Seq.empty +) + +object ArgsConfig: + private val builder = OParser.builder[ArgsConfig] + import builder.* + + private val parser = OParser.sequence( + programName("scalafix-runner"), + head("scalafix-runner", "1.0"), + + help('h', "help").text("Displays this usage text"), + + opt[String]('t', "toolchain") + .required() + .action((value, config) => config.copy(toolchain = Some(value))) + .text("Required. Specifies the toolchain with which targets will be built"), + + opt[String]('o', "opts") + .action((value, config) => config.copy(scalafixOpts = Some(value))) + .text("Options passed to scalafix as a colon-separated string (e.g., :--verbose:--config)"), + + arg[String]("...") + .unbounded() + .optional() + .action((target, config) => config.copy(targets = config.targets :+ target)) + .text("Specifies the Bazel targets to be included"), + + checkConfig { config => + val (excluded, included) = config.targets.partition(_.startsWith("-")) + Right(config.copy(excludedTargets = excluded.map(_.drop(1)), targets = included)) + } + ) + + def parse(args: Seq[String]): Option[ArgsConfig] = OParser.parse(parser, args, ArgsConfig()) \ No newline at end of file diff --git a/scalafix/src/Main.scala b/scalafix/src/Main.scala new file mode 100644 index 0000000..46c4139 --- /dev/null +++ b/scalafix/src/Main.scala @@ -0,0 +1,5 @@ +package rules_scala3.scalafix.src + +object Main: + def main(args: Array[String]): Unit = + given Vars = ArgsConfig(args.toIndexedSeq).getOrElse(sys.exit(2)) \ No newline at end of file