From aaccd1f4e9a6fa58abed2b1c3dd79f78303aca17 Mon Sep 17 00:00:00 2001 From: Timothy Klim Date: Fri, 18 Oct 2024 13:18:32 +0700 Subject: [PATCH 1/4] chore: upgrade scala3 to 3.5.2 --- rules/scala/workspace.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/scala/workspace.bzl b/rules/scala/workspace.bzl index ba03ced..21142cc 100644 --- a/rules/scala/workspace.bzl +++ b/rules/scala/workspace.bzl @@ -65,7 +65,7 @@ def scala_repositories(): ) scala2 = "2.13.15" - scala3 = "3.5.2-RC2" + scala3 = "3.5.2" scalajs = "1.17.0" direct_deps = [ From 72a69e7e3ac6408a88ca74f122c8e26957ba1e46 Mon Sep 17 00:00:00 2001 From: Anna Skrodzka <56291558+anna-skrodzka@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:56:21 +0200 Subject: [PATCH 2/4] Automate deps generator (#44) * Deps generator modified * Dependencies file added to rules/scala_proto * Dependencies file added to rules/scala_proto * scala_deps edited * Dependencies.scala for /scala added * BUILD for /scala modified * deps_scala.bzl modified --------- Co-authored-by: anna-skrodzka --- deps/scala_deps.bzl | 10 ++++-- deps/src/Deps.scala | 47 +++++++++++++--------------- deps/src/Vars.scala | 5 +++ rules/scala_proto/BUILD | 12 +++++++ rules/scala_proto/Dependencies.scala | 29 +++++++++++++++++ rules/scalafmt/BUILD | 13 ++++++++ rules/scalafmt/Dependencies.scala | 32 +++++++++++++++++++ scala/BUILD | 13 ++++++++ scala/Dependencies.scala | 40 +++++++++++++++++++++++ 9 files changed, 172 insertions(+), 29 deletions(-) create mode 100644 rules/scala_proto/Dependencies.scala create mode 100644 rules/scalafmt/Dependencies.scala create mode 100644 scala/Dependencies.scala diff --git a/deps/scala_deps.bzl b/deps/scala_deps.bzl index 6d407d4..90ae71d 100644 --- a/deps/scala_deps.bzl +++ b/deps/scala_deps.bzl @@ -1,22 +1,26 @@ load("@rules_scala3//rules:scala.bzl", "scala_binary") def scala_deps( - name = "scala_deps", + name, + dependencies, + src, project_root = ".", scala_version = "3.5.1-RC1", - destination = "3rdparty", targets_dir_name = "jvm", targets_file_name = "BUILD"): + destination = native.package_name() + "/3rdparty" + scala_binary( name = name, main_class = "rules_scala3.deps.src.Deps", resources = ["//deps/src/templates:jar_artifact_callback"], scala = "//scala:bootstrap_3", visibility = ["//visibility:public"], - srcs = ["//deps/src:deps"], + srcs = ["//deps/src:deps", src], args = [ "--project-root=" + project_root, "--scala-version=" + scala_version, + "--dependencies=" + dependencies, "--destination=" + destination, "--targets-dir-name=" + targets_dir_name, "--targets-file-name=" + targets_file_name, diff --git a/deps/src/Deps.scala b/deps/src/Deps.scala index bf36405..d743370 100644 --- a/deps/src/Deps.scala +++ b/deps/src/Deps.scala @@ -1,37 +1,32 @@ package rules_scala3.deps.src import sbt.librarymanagement.syntax.* +import sbt.librarymanagement.{DependencyBuilders, ModuleID, Resolver}, DependencyBuilders.OrganizationArtifactName +import scala.util.Try +import scala.reflect.runtime.universe._ object Deps: def main(args: Array[String]): Unit = given Vars = Vars(args.toIndexedSeq).getOrElse(sys.exit(2)) - - val jmhV = "1.37" - given DepsCfg = DepsCfg( - resolvers = Vector( - "mavencentral".at("https://repo1.maven.org/maven2/"), - "sonatype releases".at("https://oss.sonatype.org/service/local/repositories/releases/content"), - "apache staging".at("https://repository.apache.org/content/repositories/staging"), - "apache snapshots".at("https://repository.apache.org/snapshots"), - "google".at("https://maven.google.com/"), - "jitsi-maven-repository".at("https://github.com/jitsi/jitsi-maven-repository/raw/master/releases") - ), + val dependenciesClassName = summon[Vars].dependencies + val dependenciesClass = getDependenciesClass(name = dependenciesClassName) + + val resolversField = dependenciesClass.getMethod("resolvers").invoke(null).asInstanceOf[Vector[Resolver]] + val replacementsField = dependenciesClass.getMethod("replacements").invoke(null).asInstanceOf[Map[OrganizationArtifactName, String]] + val dependenciesField = dependenciesClass.getMethod("dependencies").invoke(null).asInstanceOf[Vector[ModuleID]] - // Replacements are not handled by `librarymanagement`. any Scala prefix in the name will be dropped. - // It also doesn't matter whether you use double `%` to get the Scala version or not. - replacements = Map( - "org.scala-lang" % "scala3-library" -> "@scala_library_3_3_1//jar", - "org.scala-lang" % "scala-library" -> "@scala_library_2_13_11//jar", - "org.scala-lang" % "scala-reflect" -> "@scala_reflect_2_13_11//jar" - ), - dependencies = Vector( - "org.openjdk.jmh" % "jmh-core" % jmhV, - "org.openjdk.jmh" % "jmh-generator-bytecode" % jmhV, - "org.openjdk.jmh" % "jmh-generator-reflection" % jmhV, - "org.openjdk.jmh" % "jmh-generator-asm" % jmhV, - "com.github.scopt" %% "scopt" % "4.1.0" - ) + given DepsCfg = DepsCfg( + resolvers = resolversField, + replacements = replacementsField, + dependencies = dependenciesField ) - + MakeTree() + + private def getDependenciesClass(name: String) = + val dependenciesClass = Try(Class.forName(name)) match + case scala.util.Success(clazz) => clazz + case scala.util.Failure(e) => + throw new ClassNotFoundException(s"Failed to load Dependencies class: ${e.getMessage}", e) + dependenciesClass diff --git a/deps/src/Vars.scala b/deps/src/Vars.scala index fb9e7e8..4eafae8 100644 --- a/deps/src/Vars.scala +++ b/deps/src/Vars.scala @@ -6,6 +6,7 @@ import scopt.OParser case class Vars( projectRoot: File = new File("."), scalaVersion: String = "", + dependencies: String = "", destination: String = "3rdparty", bazelExtName: String = "workspace.bzl", targetsDirName: String = "jvm", @@ -32,6 +33,10 @@ object Vars: .required() .action((value, vars) => vars.copy(scalaVersion = value)) .text("The version of Scala used in project"), + opt[String]("dependencies") + .required() + .action((value, vars) => vars.copy(dependencies = value)) + .text("The full name of Dependencies.scala class"), opt[String]('d', "destination") .action((value, vars) => vars.copy(destination = value)) .text("""The name of the directory that will be created inside your diff --git a/rules/scala_proto/BUILD b/rules/scala_proto/BUILD index e326b2a..ee1cde0 100644 --- a/rules/scala_proto/BUILD +++ b/rules/scala_proto/BUILD @@ -7,6 +7,18 @@ toolchain_type( visibility = ["//visibility:public"], ) +filegroup( + name = "dependencies", + srcs = ["Dependencies.scala"], + visibility = ["//visibility:public"], +) + +scala_deps( + name = "scala_deps", + src = "//rules/scala_proto:dependencies", + dependencies = "rules_scala3.rules.scala_proto.Dependencies", +) + scala_binary( name = "worker", srcs = ["private/ScalaProtoWorker.scala"], diff --git a/rules/scala_proto/Dependencies.scala b/rules/scala_proto/Dependencies.scala new file mode 100644 index 0000000..3f1ec9f --- /dev/null +++ b/rules/scala_proto/Dependencies.scala @@ -0,0 +1,29 @@ +package rules_scala3.rules.scala_proto + +import sbt.librarymanagement.syntax.* +import sbt.librarymanagement.{DependencyBuilders, ModuleID, Resolver}, DependencyBuilders.OrganizationArtifactName + +object Dependencies: + + private val scalapbV = "1.0.0-alpha.1" + private val protocBridgeV = "0.9.7" + private val grpcwebV = "0.7.0" + + val resolvers: Seq[Resolver] = Vector( + "sonatype releases".at("https://oss.sonatype.org/service/local/repositories/releases/content"), + "apache staging".at("https://repository.apache.org/content/repositories/staging"), + "apache snapshots".at("https://repository.apache.org/snapshots"), + "google".at("https://maven.google.com/"), + "jitsi-maven-repository".at("https://github.com/jitsi/jitsi-maven-repository/raw/master/releases") + ) + val replacements: Map[OrganizationArtifactName, String] = Map( + "org.scala-lang" % "scala3-library" -> "@scala3_library//jar", + "org.scala-lang" % "scala-library" -> "@scala_library_2_13//jar", + "org.scala-lang" % "scala-reflect" -> "@scala_reflect_2_13//jar" + ) + val dependencies: Seq[ModuleID] = Vector( + "com.thesamet.scalapb" %% "compilerplugin" % scalapbV, + "com.thesamet.scalapb" %% "protoc-bridge_2.13" % protocBridgeV, + "com.thesamet.scalapb" %% "protoc-gen_2.13" % protocBridgeV, + "com.thesamet.scalapb.grpcweb" %% "scalapb-grpcweb-code-gen" % grpcwebV + ) diff --git a/rules/scalafmt/BUILD b/rules/scalafmt/BUILD index 4a62a4d..018f0e6 100644 --- a/rules/scalafmt/BUILD +++ b/rules/scalafmt/BUILD @@ -1,3 +1,4 @@ +load("//deps:scala_deps.bzl", "scala_deps") load("//rules:scala.bzl", "scala_binary") load("//rules:scalafmt.bzl", "scala_format_test") load( @@ -5,6 +6,18 @@ load( _add_non_default_format_phase_singleton = "add_non_default_format_phase_singleton", ) +filegroup( + name = "dependencies", + srcs = ["Dependencies.scala"], + visibility = ["//visibility:public"], +) + +scala_deps( + name = "scala_deps", + src = "//rules/scalafmt:dependencies", + dependencies = "rules_scala3.rules.scalafmt.Dependencies", +) + filegroup( name = "runner", srcs = ["private/format.template.sh"], diff --git a/rules/scalafmt/Dependencies.scala b/rules/scalafmt/Dependencies.scala new file mode 100644 index 0000000..1f8a958 --- /dev/null +++ b/rules/scalafmt/Dependencies.scala @@ -0,0 +1,32 @@ +package rules_scala3.rules.scalafmt + +import sbt.librarymanagement.syntax.* +import sbt.librarymanagement.{DependencyBuilders, ModuleID, Resolver}, DependencyBuilders.OrganizationArtifactName + +object Dependencies: + + private val scalafmtV = "3.8.3" + private val parsersV = "4.10.2" + + val resolvers: Seq[Resolver] = Vector( + "mavencentral".at("https://repo1.maven.org/maven2/"), + "sonatype releases".at("https://oss.sonatype.org/service/local/repositories/releases/content"), + "apache staging".at("https://repository.apache.org/content/repositories/staging"), + "apache snapshots".at("https://repository.apache.org/snapshots"), + "google".at("https://maven.google.com/"), + "jitsi-maven-repository".at("https://github.com/jitsi/jitsi-maven-repository/raw/master/releases") + ) + // Replacements are not handled by `librarymanagement`. any Scala prefix in the name will be dropped. + // It also doesn't matter whether you use double `%` to get the Scala version or not. + val replacements: Map[OrganizationArtifactName, String] = Map( + "org.scala-lang" % "scala3-library" -> "@scala3_library//jar", + "org.scala-lang" % "scala-library" -> "@scala_library_2_13//jar", + "org.scala-lang" % "scala-reflect" -> "@scala_reflect_2_13//jar" + ) + val dependencies: Seq[ModuleID] = Vector( + "com.geirsson" % "metaconfig-core_2.13" % "0.12.0", + "org.scalameta" % "parsers_2.13" % parsersV, + "org.scalameta" % "trees_2.13" % parsersV, + "org.scalameta" % "scalafmt-core_2.13" % scalafmtV, + "org.scalameta" % "scalafmt-sysops_2.13" % scalafmtV, + ) diff --git a/scala/BUILD b/scala/BUILD index 0e4a7cb..9da4597 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -4,6 +4,19 @@ load( "configure_zinc_scala", "scala_library", ) +load("//deps:scala_deps.bzl", "scala_deps") + +filegroup( + name = "dependencies", + srcs = ["Dependencies.scala"], + visibility = ["//visibility:public"], +) + +scala_deps( + name = "scala_deps", + src = "//scala:dependencies", + dependencies = "rules_scala3.scala.Dependencies", +) config_setting( name = "deps_used_off", diff --git a/scala/Dependencies.scala b/scala/Dependencies.scala new file mode 100644 index 0000000..a861490 --- /dev/null +++ b/scala/Dependencies.scala @@ -0,0 +1,40 @@ +package rules_scala3.scala + +import sbt.librarymanagement.syntax.* +import sbt.librarymanagement.{DependencyBuilders, ModuleID, Resolver}, DependencyBuilders.OrganizationArtifactName + +object Dependencies: + + private val sbtVersion = "2.0.0-M2" + private val zincVersion = "2.0.0-alpha14" + val scalapbV = "1.0.0-alpha.1" + + val resolvers: Seq[Resolver] = Vector( + "mavencentral".at("https://repo1.maven.org/maven2/"), + "sonatype releases".at("https://oss.sonatype.org/service/local/repositories/releases/content"), + "apache staging".at("https://repository.apache.org/content/repositories/staging"), + "apache snapshots".at("https://repository.apache.org/snapshots"), + "google".at("https://maven.google.com/"), + "jitsi-maven-repository".at("https://github.com/jitsi/jitsi-maven-repository/raw/master/releases") + ) + val replacements: Map[OrganizationArtifactName, String] = Map( + "org.scala-lang" % "scala3-library" -> "@scala3_library//jar", + "org.scala-lang" % "scala-library" -> "@scala_library_2_13//jar", + "org.scala-lang" % "scala-reflect" -> "@scala_reflect_2_13//jar" + ) + val dependencies: Seq[ModuleID] = Vector( + "org.jacoco" % "org.jacoco.core" % "0.8.10", + "org.jline" % "jline-reader" % "3.24.1", + "org.scala-lang.modules" %% "scala-xml" % "2.3.0", + "org.scala-sbt" % "test-interface" % "1.0", + "org.scala-sbt" % "compiler-interface" % zincVersion, + "org.scala-sbt" % "util-interface" % sbtVersion, + "org.scala-sbt" %% "util-logging_3" % sbtVersion, + "org.scala-sbt" %% "zinc_3" % zincVersion, + "org.scala-sbt" %% "zinc-core" % zincVersion, + "org.scala-sbt" %% "zinc-classpath" % zincVersion, + "org.scala-sbt" %% "zinc-compile-core" % zincVersion, + "org.scala-sbt" %% "zinc-persist" % zincVersion, + "org.scala-sbt" %% "zinc-apiinfo" % zincVersion, + "org.scalameta" %% "munit_3" % "1.0.2", + ) \ No newline at end of file From 2f5461a14d2359fb64ef84fd85b66337211f7e58 Mon Sep 17 00:00:00 2001 From: Anna Skrodzka <56291558+anna-skrodzka@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:26:55 +0200 Subject: [PATCH 3/4] Fix WORKSPACE in the test framework (#45) * maven_dependencies added to WORKSPACE * io_bazel_rules_scala to rules_scala3 * zinc_3_3_migration to zinc_3_migration --------- Co-authored-by: anna-skrodzka --- tests/WORKSPACE | 10 +++++++++- tests/compat/scalacopts/BUILD | 2 +- tests/grpc/BUILD | 4 ++-- tests/proto/BUILD | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/WORKSPACE b/tests/WORKSPACE index 0baf9ac..3e37146 100644 --- a/tests/WORKSPACE +++ b/tests/WORKSPACE @@ -33,7 +33,7 @@ load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_depende rules_nixpkgs_dependencies() -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_local_repository", "nixpkgs_cc_configure") +load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_cc_configure", "nixpkgs_local_repository") nixpkgs_local_repository( name = "nixpkgs", @@ -108,6 +108,14 @@ load("//3rdparty:workspace.bzl", "maven_dependencies") maven_dependencies() +load("@rules_scala3//3rdparty:workspace.bzl", "maven_dependencies") + +maven_dependencies() + +load("@rules_scala3//scala/3rdparty:workspace.bzl", "maven_dependencies") + +maven_dependencies() + bind( name = "default_scala", actual = "@rules_scala3//scala:zinc_3_3", diff --git a/tests/compat/scalacopts/BUILD b/tests/compat/scalacopts/BUILD index f16ba9e..096d160 100644 --- a/tests/compat/scalacopts/BUILD +++ b/tests/compat/scalacopts/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library") +load("@rules_scala3//rules:scala.bzl", "scala_library") scala_library( name = "default", diff --git a/tests/grpc/BUILD b/tests/grpc/BUILD index 5104336..4dec82e 100644 --- a/tests/grpc/BUILD +++ b/tests/grpc/BUILD @@ -44,7 +44,7 @@ scala_library( deps_used_whitelist = [ "@com_google_protobuf//java/core", ], - scala = "@rules_scala3//scala:zinc_3_3_migration", + scala = "@rules_scala3//scala:zinc_3_migration", deps = [ "//3rdparty/jvm/com/thesamet/scalapb:scalapb_runtime", "//3rdparty/jvm/com/thesamet/scalapb:scalapb_runtime_grpc", @@ -66,7 +66,7 @@ scala_library( deps_used_whitelist = [ "@com_google_protobuf//java/core", ], - scala = "@rules_scala3//scala:zinc_3_3_migration", + scala = "@rules_scala3//scala:zinc_3_migration", scalacopts = [ "-scalajs", ], diff --git a/tests/proto/BUILD b/tests/proto/BUILD index ea54baa..75f58e6 100644 --- a/tests/proto/BUILD +++ b/tests/proto/BUILD @@ -23,7 +23,7 @@ scala_library( deps_unused_whitelist = [ "//3rdparty/jvm/com/google/protobuf:protobuf_java", ], - scala = "@rules_scala3//scala:zinc_3_3_migration", + scala = "@rules_scala3//scala:zinc_3_migration", deps = [ "//3rdparty/jvm/com/thesamet/scalapb:scalapb_runtime", ], From 7cc5b4183a3c9a43103a7f446647dfa94a36f4b4 Mon Sep 17 00:00:00 2001 From: Anna Skrodzka <56291558+anna-skrodzka@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:31:05 +0200 Subject: [PATCH 4/4] Generate 3rdparty for scala_proto & scalafmt (#46) * generate deps for scalafmt * generate deps for scalafmt * generate deps for scala_proto * extra dependencies removed from 3rdparty --------- Co-authored-by: anna-skrodzka --- 3rdparty/jvm/org/scala_lang/BUILD | 19 +-- 3rdparty/workspace.bzl | 7 -- WORKSPACE | 8 ++ rules/scala_proto/3rdparty/BUILD | 0 .../3rdparty}/jvm/com/google/protobuf/BUILD | 2 +- .../3rdparty}/jvm/com/thesamet/scalapb/BUILD | 12 +- .../jvm/com/thesamet/scalapb/grpcweb/BUILD | 4 +- .../scala_proto/3rdparty}/jvm/dev/dirs/BUILD | 2 +- .../3rdparty/jvm/org/scala_lang/BUILD | 20 +++ .../jvm/org/scala_lang/modules/BUILD | 4 +- rules/scala_proto/3rdparty/workspace.bzl | 54 ++++++++ rules/scala_proto/BUILD | 8 +- rules/scala_proto/Dependencies.scala | 4 +- rules/scalafmt/3rdparty/BUILD | 0 .../scalafmt/3rdparty/jvm/com/geirsson/BUILD | 49 ++++++++ rules/scalafmt/3rdparty/jvm/com/lihaoyi/BUILD | 27 ++++ .../scalafmt/3rdparty/jvm/com/typesafe/BUILD | 10 ++ .../jvm/io/github/java_diff_utils/BUILD | 10 ++ .../3rdparty/jvm/net/java/dev/jna/BUILD | 10 ++ rules/scalafmt/3rdparty/jvm/org/jline/BUILD | 10 ++ .../3rdparty/jvm/org/scala_lang/BUILD | 49 ++++++++ .../3rdparty/jvm/org/scala_lang/modules/BUILD | 26 ++++ .../scalafmt/3rdparty/jvm/org/scalameta/BUILD | 117 ++++++++++++++++++ .../scalafmt/3rdparty/jvm/org/typelevel/BUILD | 13 ++ rules/scalafmt/3rdparty/workspace.bzl | 70 +++++++++++ rules/scalafmt/BUILD | 8 +- rules/scalafmt/scalafmt/ScalafmtRunner.scala | 4 +- 27 files changed, 502 insertions(+), 45 deletions(-) create mode 100644 rules/scala_proto/3rdparty/BUILD rename {3rdparty => rules/scala_proto/3rdparty}/jvm/com/google/protobuf/BUILD (77%) rename {3rdparty => rules/scala_proto/3rdparty}/jvm/com/thesamet/scalapb/BUILD (61%) rename {3rdparty => rules/scala_proto/3rdparty}/jvm/com/thesamet/scalapb/grpcweb/BUILD (65%) rename {3rdparty => rules/scala_proto/3rdparty}/jvm/dev/dirs/BUILD (76%) create mode 100644 rules/scala_proto/3rdparty/jvm/org/scala_lang/BUILD rename {3rdparty => rules/scala_proto/3rdparty}/jvm/org/scala_lang/modules/BUILD (65%) create mode 100644 rules/scala_proto/3rdparty/workspace.bzl create mode 100644 rules/scalafmt/3rdparty/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/com/geirsson/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/com/lihaoyi/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/com/typesafe/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/io/github/java_diff_utils/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/net/java/dev/jna/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/org/jline/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/org/scala_lang/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/org/scala_lang/modules/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/org/scalameta/BUILD create mode 100644 rules/scalafmt/3rdparty/jvm/org/typelevel/BUILD create mode 100644 rules/scalafmt/3rdparty/workspace.bzl diff --git a/3rdparty/jvm/org/scala_lang/BUILD b/3rdparty/jvm/org/scala_lang/BUILD index 814cd04..a9a9d19 100644 --- a/3rdparty/jvm/org/scala_lang/BUILD +++ b/3rdparty/jvm/org/scala_lang/BUILD @@ -1,21 +1,10 @@ load("@rules_scala3//rules:scala.bzl", "scala_import") - scala_import( name = "scala3_library", - visibility = [ - "//3rdparty/jvm:__subpackages__", - ], exports = [ - "@scala3_library//jar", + "@scala3_library//jar" ], -) - -scala_import( - name = "scala_library", visibility = [ - "//3rdparty/jvm:__subpackages__", - ], - exports = [ - "@scala_library_2_13//jar", - ], -) \ No newline at end of file + "//3rdparty/jvm:__subpackages__" + ] +) diff --git a/3rdparty/workspace.bzl b/3rdparty/workspace.bzl index f1a9e01..afd0bb3 100644 --- a/3rdparty/workspace.bzl +++ b/3rdparty/workspace.bzl @@ -41,12 +41,6 @@ def jar_artifact_callback(hash): def list_dependencies(): return [ {"artifact":"com.github.scopt:scopt_3:4.1.0","url":"https://repo1.maven.org/maven2/com/github/scopt/scopt_3/4.1.0/scopt_3-4.1.0.jar","name":"com_github_scopt_scopt_3","actual":"@com_github_scopt_scopt_3//jar","bind": "jar/com/github/scopt/scopt_3"}, - {"artifact":"com.google.protobuf:protobuf-java:4.28.2","url":"https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.28.2/protobuf-java-4.28.2.jar","name":"com_google_protobuf_protobuf_java","actual":"@com_google_protobuf_protobuf_java//jar","bind": "jar/com/google/protobuf/protobuf_java"}, - {"artifact":"com.thesamet.scalapb:compilerplugin_3:1.0.0-alpha.1","url":"https://repo1.maven.org/maven2/com/thesamet/scalapb/compilerplugin_3/1.0.0-alpha.1/compilerplugin_3-1.0.0-alpha.1.jar","name":"com_thesamet_scalapb_compilerplugin_3","actual":"@com_thesamet_scalapb_compilerplugin_3//jar","bind": "jar/com/thesamet/scalapb/compilerplugin_3"}, - {"artifact":"com.thesamet.scalapb.grpcweb:scalapb-grpcweb-code-gen_3:0.7.0","url":"https://repo1.maven.org/maven2/com/thesamet/scalapb/grpcweb/scalapb-grpcweb-code-gen_3/0.7.0/scalapb-grpcweb-code-gen_3-0.7.0.jar","name":"com_thesamet_scalapb_grpcweb_scalapb_grpcweb_code_gen_3","actual":"@com_thesamet_scalapb_grpcweb_scalapb_grpcweb_code_gen_3//jar","bind": "jar/com/thesamet/scalapb/grpcweb/scalapb_grpcweb_code_gen_3"}, - {"artifact":"com.thesamet.scalapb:protoc-bridge_2.13:0.9.7","url":"https://repo1.maven.org/maven2/com/thesamet/scalapb/protoc-bridge_2.13/0.9.7/protoc-bridge_2.13-0.9.7.jar","name":"com_thesamet_scalapb_protoc_bridge_2_13","actual":"@com_thesamet_scalapb_protoc_bridge_2_13//jar","bind": "jar/com/thesamet/scalapb/protoc_bridge_2_13"}, - {"artifact":"com.thesamet.scalapb:protoc-gen_2.13:0.9.7","url":"https://repo1.maven.org/maven2/com/thesamet/scalapb/protoc-gen_2.13/0.9.7/protoc-gen_2.13-0.9.7.jar","name":"com_thesamet_scalapb_protoc_gen_2_13","actual":"@com_thesamet_scalapb_protoc_gen_2_13//jar","bind": "jar/com/thesamet/scalapb/protoc_gen_2_13"}, - {"artifact":"dev.dirs:directories:26","url":"https://repo1.maven.org/maven2/dev/dirs/directories/26/directories-26.jar","name":"dev_dirs_directories","actual":"@dev_dirs_directories//jar","bind": "jar/dev/dirs/directories"}, {"artifact":"net.sf.jopt-simple:jopt-simple:5.0.4","url":"https://repo1.maven.org/maven2/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar","name":"net_sf_jopt_simple_jopt_simple","actual":"@net_sf_jopt_simple_jopt_simple//jar","bind": "jar/net/sf/jopt_simple/jopt_simple"}, {"artifact":"org.apache.commons:commons-math3:3.6.1","url":"https://repo1.maven.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar","name":"org_apache_commons_commons_math3","actual":"@org_apache_commons_commons_math3//jar","bind": "jar/org/apache/commons/commons_math3"}, {"artifact":"org.openjdk.jmh:jmh-core:1.37","url":"https://repo1.maven.org/maven2/org/openjdk/jmh/jmh-core/1.37/jmh-core-1.37.jar","name":"org_openjdk_jmh_jmh_core","actual":"@org_openjdk_jmh_jmh_core//jar","bind": "jar/org/openjdk/jmh/jmh_core"}, @@ -54,7 +48,6 @@ def list_dependencies(): {"artifact":"org.openjdk.jmh:jmh-generator-bytecode:1.37","url":"https://repo1.maven.org/maven2/org/openjdk/jmh/jmh-generator-bytecode/1.37/jmh-generator-bytecode-1.37.jar","name":"org_openjdk_jmh_jmh_generator_bytecode","actual":"@org_openjdk_jmh_jmh_generator_bytecode//jar","bind": "jar/org/openjdk/jmh/jmh_generator_bytecode"}, {"artifact":"org.openjdk.jmh:jmh-generator-reflection:1.37","url":"https://repo1.maven.org/maven2/org/openjdk/jmh/jmh-generator-reflection/1.37/jmh-generator-reflection-1.37.jar","name":"org_openjdk_jmh_jmh_generator_reflection","actual":"@org_openjdk_jmh_jmh_generator_reflection//jar","bind": "jar/org/openjdk/jmh/jmh_generator_reflection"}, {"artifact":"org.ow2.asm:asm:9.0","url":"https://repo1.maven.org/maven2/org/ow2/asm/asm/9.0/asm-9.0.jar","name":"org_ow2_asm_asm","actual":"@org_ow2_asm_asm//jar","bind": "jar/org/ow2/asm/asm"}, - {"artifact":"org.scala-lang.modules:scala-collection-compat_3:2.12.0","url":"https://repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_3/2.12.0/scala-collection-compat_3-2.12.0.jar","name":"org_scala_lang_modules_scala_collection_compat_3","actual":"@org_scala_lang_modules_scala_collection_compat_3//jar","bind": "jar/org/scala_lang/modules/scala_collection_compat_3"}, ] def maven_dependencies(callback = jar_artifact_callback): diff --git a/WORKSPACE b/WORKSPACE index d624382..a905501 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -94,6 +94,14 @@ load("//scala/3rdparty:workspace.bzl", "maven_dependencies") maven_dependencies() +load("//rules/scalafmt/3rdparty:workspace.bzl", "maven_dependencies") + +maven_dependencies() + +load("//rules/scala_proto/3rdparty:workspace.bzl", "maven_dependencies") + +maven_dependencies() + load("//mezel_compatibility:repositories.bzl", "mezel_compatibility_repository") mezel_compatibility_repository( diff --git a/rules/scala_proto/3rdparty/BUILD b/rules/scala_proto/3rdparty/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/3rdparty/jvm/com/google/protobuf/BUILD b/rules/scala_proto/3rdparty/jvm/com/google/protobuf/BUILD similarity index 77% rename from 3rdparty/jvm/com/google/protobuf/BUILD rename to rules/scala_proto/3rdparty/jvm/com/google/protobuf/BUILD index 331fe60..b2c40cd 100644 --- a/3rdparty/jvm/com/google/protobuf/BUILD +++ b/rules/scala_proto/3rdparty/jvm/com/google/protobuf/BUILD @@ -5,6 +5,6 @@ java_import( "//external:jar/com/google/protobuf/protobuf_java" ], visibility = [ - "//3rdparty/jvm:__subpackages__" + "//rules/scala_proto/3rdparty/jvm:__subpackages__" ] ) diff --git a/3rdparty/jvm/com/thesamet/scalapb/BUILD b/rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/BUILD similarity index 61% rename from 3rdparty/jvm/com/thesamet/scalapb/BUILD rename to rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/BUILD index 9c413a2..d479fca 100644 --- a/3rdparty/jvm/com/thesamet/scalapb/BUILD +++ b/rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/BUILD @@ -5,9 +5,9 @@ scala_import( "//external:jar/com/thesamet/scalapb/compilerplugin_3" ], runtime_deps = [ - "//3rdparty/jvm/com/google/protobuf:protobuf_java", - "//3rdparty/jvm/org/scala_lang/modules:scala_collection_compat", - "//3rdparty/jvm/org/scala_lang:scala3_library", + "//rules/scala_proto/3rdparty/jvm/com/google/protobuf:protobuf_java", + "//rules/scala_proto/3rdparty/jvm/org/scala_lang/modules:scala_collection_compat", + "//rules/scala_proto/3rdparty/jvm/org/scala_lang:scala3_library", ":protoc_gen" ], visibility = [ @@ -21,8 +21,8 @@ scala_import( "//external:jar/com/thesamet/scalapb/protoc_bridge_2_13" ], runtime_deps = [ - "//3rdparty/jvm/dev/dirs:directories", - "//3rdparty/jvm/org/scala_lang:scala_library" + "//rules/scala_proto/3rdparty/jvm/dev/dirs:directories", + "//rules/scala_proto/3rdparty/jvm/org/scala_lang:scala_library" ], visibility = [ "//visibility:public" @@ -35,7 +35,7 @@ scala_import( "//external:jar/com/thesamet/scalapb/protoc_gen_2_13" ], runtime_deps = [ - "//3rdparty/jvm/org/scala_lang:scala_library", + "//rules/scala_proto/3rdparty/jvm/org/scala_lang:scala_library", ":protoc_bridge" ], visibility = [ diff --git a/3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD b/rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD similarity index 65% rename from 3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD rename to rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD index 0a98586..1e57275 100644 --- a/3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD +++ b/rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/grpcweb/BUILD @@ -5,8 +5,8 @@ scala_import( "//external:jar/com/thesamet/scalapb/grpcweb/scalapb_grpcweb_code_gen_3" ], runtime_deps = [ - "//3rdparty/jvm/com/thesamet/scalapb:compilerplugin", - "//3rdparty/jvm/org/scala_lang:scala3_library" + "//rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb:compilerplugin", + "//rules/scala_proto/3rdparty/jvm/org/scala_lang:scala3_library" ], visibility = [ "//visibility:public" diff --git a/3rdparty/jvm/dev/dirs/BUILD b/rules/scala_proto/3rdparty/jvm/dev/dirs/BUILD similarity index 76% rename from 3rdparty/jvm/dev/dirs/BUILD rename to rules/scala_proto/3rdparty/jvm/dev/dirs/BUILD index db4b692..4dd708f 100644 --- a/3rdparty/jvm/dev/dirs/BUILD +++ b/rules/scala_proto/3rdparty/jvm/dev/dirs/BUILD @@ -5,6 +5,6 @@ java_import( "//external:jar/dev/dirs/directories" ], visibility = [ - "//3rdparty/jvm:__subpackages__" + "//rules/scala_proto/3rdparty/jvm:__subpackages__" ] ) diff --git a/rules/scala_proto/3rdparty/jvm/org/scala_lang/BUILD b/rules/scala_proto/3rdparty/jvm/org/scala_lang/BUILD new file mode 100644 index 0000000..b867dde --- /dev/null +++ b/rules/scala_proto/3rdparty/jvm/org/scala_lang/BUILD @@ -0,0 +1,20 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +scala_import( + name = "scala3_library", + exports = [ + "@scala3_library//jar" + ], + visibility = [ + "//rules/scala_proto/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "scala_library", + exports = [ + "@scala_library_2_13//jar" + ], + visibility = [ + "//rules/scala_proto/3rdparty/jvm:__subpackages__" + ] +) diff --git a/3rdparty/jvm/org/scala_lang/modules/BUILD b/rules/scala_proto/3rdparty/jvm/org/scala_lang/modules/BUILD similarity index 65% rename from 3rdparty/jvm/org/scala_lang/modules/BUILD rename to rules/scala_proto/3rdparty/jvm/org/scala_lang/modules/BUILD index d6e54e9..5961aa0 100644 --- a/3rdparty/jvm/org/scala_lang/modules/BUILD +++ b/rules/scala_proto/3rdparty/jvm/org/scala_lang/modules/BUILD @@ -5,9 +5,9 @@ scala_import( "//external:jar/org/scala_lang/modules/scala_collection_compat_3" ], runtime_deps = [ - "//3rdparty/jvm/org/scala_lang:scala3_library" + "//rules/scala_proto/3rdparty/jvm/org/scala_lang:scala3_library" ], visibility = [ - "//3rdparty/jvm:__subpackages__" + "//rules/scala_proto/3rdparty/jvm:__subpackages__" ] ) diff --git a/rules/scala_proto/3rdparty/workspace.bzl b/rules/scala_proto/3rdparty/workspace.bzl new file mode 100644 index 0000000..a93ae79 --- /dev/null +++ b/rules/scala_proto/3rdparty/workspace.bzl @@ -0,0 +1,54 @@ +# Do not edit. rules_scala3 autogenerates this file +def _jar_artifact_impl(ctx): + jar_name = "%s.jar" % ctx.name + ctx.download( + output = ctx.path("jar/%s" % jar_name), + url = ctx.attr.urls, + executable = False, + ) + build_file_contents = """ +package(default_visibility = ['//visibility:public']) +filegroup( + name = 'jar', + srcs = ['{jar_name}'], + visibility = ['//visibility:public'], +) +alias( + name = "file", + actual = ":jar", + visibility = ["//visibility:public"], +)\n""".format(artifact = ctx.attr.artifact, jar_name = jar_name) + ctx.file(ctx.path("jar/BUILD"), build_file_contents, False) + return None + +jar_artifact = repository_rule( + attrs = { + "artifact": attr.string(mandatory = True), + "urls": attr.string_list(mandatory = True), + }, + implementation = _jar_artifact_impl, +) + +def jar_artifact_callback(hash): + jar_artifact( + artifact = hash["artifact"], + name = hash["name"], + urls = [hash["url"]], + ) + native.bind(name = hash["bind"], actual = hash["actual"]) + + +def list_dependencies(): + return [ + {"artifact":"com.google.protobuf:protobuf-java:4.28.2","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/google/protobuf/protobuf-java/4.28.2/protobuf-java-4.28.2.jar","name":"com_google_protobuf_protobuf_java","actual":"@com_google_protobuf_protobuf_java//jar","bind": "jar/com/google/protobuf/protobuf_java"}, + {"artifact":"com.thesamet.scalapb:compilerplugin_3:1.0.0-alpha.1","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/thesamet/scalapb/compilerplugin_3/1.0.0-alpha.1/compilerplugin_3-1.0.0-alpha.1.jar","name":"com_thesamet_scalapb_compilerplugin_3","actual":"@com_thesamet_scalapb_compilerplugin_3//jar","bind": "jar/com/thesamet/scalapb/compilerplugin_3"}, + {"artifact":"com.thesamet.scalapb.grpcweb:scalapb-grpcweb-code-gen_3:0.7.0","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/thesamet/scalapb/grpcweb/scalapb-grpcweb-code-gen_3/0.7.0/scalapb-grpcweb-code-gen_3-0.7.0.jar","name":"com_thesamet_scalapb_grpcweb_scalapb_grpcweb_code_gen_3","actual":"@com_thesamet_scalapb_grpcweb_scalapb_grpcweb_code_gen_3//jar","bind": "jar/com/thesamet/scalapb/grpcweb/scalapb_grpcweb_code_gen_3"}, + {"artifact":"com.thesamet.scalapb:protoc-bridge_2.13:0.9.7","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/thesamet/scalapb/protoc-bridge_2.13/0.9.7/protoc-bridge_2.13-0.9.7.jar","name":"com_thesamet_scalapb_protoc_bridge_2_13","actual":"@com_thesamet_scalapb_protoc_bridge_2_13//jar","bind": "jar/com/thesamet/scalapb/protoc_bridge_2_13"}, + {"artifact":"com.thesamet.scalapb:protoc-gen_2.13:0.9.7","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/thesamet/scalapb/protoc-gen_2.13/0.9.7/protoc-gen_2.13-0.9.7.jar","name":"com_thesamet_scalapb_protoc_gen_2_13","actual":"@com_thesamet_scalapb_protoc_gen_2_13//jar","bind": "jar/com/thesamet/scalapb/protoc_gen_2_13"}, + {"artifact":"dev.dirs:directories:26","url":"https://oss.sonatype.org/service/local/repositories/releases/content/dev/dirs/directories/26/directories-26.jar","name":"dev_dirs_directories","actual":"@dev_dirs_directories//jar","bind": "jar/dev/dirs/directories"}, + {"artifact":"org.scala-lang.modules:scala-collection-compat_3:2.12.0","url":"https://oss.sonatype.org/service/local/repositories/releases/content/org/scala-lang/modules/scala-collection-compat_3/2.12.0/scala-collection-compat_3-2.12.0.jar","name":"org_scala_lang_modules_scala_collection_compat_3","actual":"@org_scala_lang_modules_scala_collection_compat_3//jar","bind": "jar/org/scala_lang/modules/scala_collection_compat_3"}, + ] + +def maven_dependencies(callback = jar_artifact_callback): + for hash in list_dependencies(): + callback(hash) diff --git a/rules/scala_proto/BUILD b/rules/scala_proto/BUILD index ee1cde0..39cf5d3 100644 --- a/rules/scala_proto/BUILD +++ b/rules/scala_proto/BUILD @@ -28,10 +28,10 @@ scala_binary( visibility = ["//visibility:public"], deps = [ "//3rdparty/jvm/com/github/scopt", - "//3rdparty/jvm/com/thesamet/scalapb:compilerplugin", - "//3rdparty/jvm/com/thesamet/scalapb:protoc_bridge", - "//3rdparty/jvm/com/thesamet/scalapb:protoc_gen", - "//3rdparty/jvm/com/thesamet/scalapb/grpcweb:scalapb_grpcweb_code_gen", + "//rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb:compilerplugin", + "//rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb:protoc_bridge", + "//rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb:protoc_gen", + "//rules/scala_proto/3rdparty/jvm/com/thesamet/scalapb/grpcweb:scalapb_grpcweb_code_gen", "//scala/common/worker", "//scala/workers/common", ], diff --git a/rules/scala_proto/Dependencies.scala b/rules/scala_proto/Dependencies.scala index 3f1ec9f..06859ab 100644 --- a/rules/scala_proto/Dependencies.scala +++ b/rules/scala_proto/Dependencies.scala @@ -23,7 +23,7 @@ object Dependencies: ) val dependencies: Seq[ModuleID] = Vector( "com.thesamet.scalapb" %% "compilerplugin" % scalapbV, - "com.thesamet.scalapb" %% "protoc-bridge_2.13" % protocBridgeV, - "com.thesamet.scalapb" %% "protoc-gen_2.13" % protocBridgeV, + "com.thesamet.scalapb" % "protoc-bridge_2.13" % protocBridgeV, + "com.thesamet.scalapb" % "protoc-gen_2.13" % protocBridgeV, "com.thesamet.scalapb.grpcweb" %% "scalapb-grpcweb-code-gen" % grpcwebV ) diff --git a/rules/scalafmt/3rdparty/BUILD b/rules/scalafmt/3rdparty/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/rules/scalafmt/3rdparty/jvm/com/geirsson/BUILD b/rules/scalafmt/3rdparty/jvm/com/geirsson/BUILD new file mode 100644 index 0000000..ae8d73e --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/com/geirsson/BUILD @@ -0,0 +1,49 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") + +scala_import( + name = "metaconfig_core", + jars = [ + "//external:jar/com/geirsson/metaconfig_core_2_13", + ], + visibility = [ + "//visibility:public", + ], + runtime_deps = [ + ":metaconfig_pprint", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_reflect", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang/modules:scala_collection_compat", + "//rules/scalafmt/3rdparty/jvm/org/typelevel:paiges_core", + ], +) + +scala_import( + name = "metaconfig_pprint", + jars = [ + "//external:jar/com/geirsson/metaconfig_pprint_2_13", + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/com/lihaoyi:fansi", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_compiler", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_reflect", + ], +) + +scala_import( + name = "metaconfig_typesafe_config", + jars = [ + "//external:jar/com/geirsson/metaconfig_typesafe_config_2_13", + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + runtime_deps = [ + ":metaconfig_core", + "//rules/scalafmt/3rdparty/jvm/com/typesafe:config", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + ], +) diff --git a/rules/scalafmt/3rdparty/jvm/com/lihaoyi/BUILD b/rules/scalafmt/3rdparty/jvm/com/lihaoyi/BUILD new file mode 100644 index 0000000..8e7fc77 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/com/lihaoyi/BUILD @@ -0,0 +1,27 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +scala_import( + name = "fansi", + jars = [ + "//external:jar/com/lihaoyi/fansi_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + ":sourcecode" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "sourcecode", + jars = [ + "//external:jar/com/lihaoyi/sourcecode_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/com/typesafe/BUILD b/rules/scalafmt/3rdparty/jvm/com/typesafe/BUILD new file mode 100644 index 0000000..197868f --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/com/typesafe/BUILD @@ -0,0 +1,10 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +java_import( + name = "config", + jars = [ + "//external:jar/com/typesafe/config" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/io/github/java_diff_utils/BUILD b/rules/scalafmt/3rdparty/jvm/io/github/java_diff_utils/BUILD new file mode 100644 index 0000000..9912440 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/io/github/java_diff_utils/BUILD @@ -0,0 +1,10 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +java_import( + name = "java_diff_utils", + jars = [ + "//external:jar/io/github/java_diff_utils/java_diff_utils" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/net/java/dev/jna/BUILD b/rules/scalafmt/3rdparty/jvm/net/java/dev/jna/BUILD new file mode 100644 index 0000000..ce9eca3 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/net/java/dev/jna/BUILD @@ -0,0 +1,10 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +java_import( + name = "jna", + jars = [ + "//external:jar/net/java/dev/jna/jna" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/org/jline/BUILD b/rules/scalafmt/3rdparty/jvm/org/jline/BUILD new file mode 100644 index 0000000..c298576 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/org/jline/BUILD @@ -0,0 +1,10 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +java_import( + name = "jline", + jars = [ + "//external:jar/org/jline/jline" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/org/scala_lang/BUILD b/rules/scalafmt/3rdparty/jvm/org/scala_lang/BUILD new file mode 100644 index 0000000..28fb3dd --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/org/scala_lang/BUILD @@ -0,0 +1,49 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") + +scala_import( + name = "scala_compiler", + jars = [ + "//external:jar/org/scala_lang/scala_compiler", + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + runtime_deps = [ + ":scala_library", + ":scala_reflect", + "//rules/scalafmt/3rdparty/jvm/io/github/java_diff_utils", + "//rules/scalafmt/3rdparty/jvm/net/java/dev/jna", + "//rules/scalafmt/3rdparty/jvm/org/jline", + ], +) + +scala_import( + name = "scala_library", + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + exports = [ + "@scala_library_2_13//jar", + ], +) + +scala_import( + name = "scala_reflect", + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + exports = [ + "@scala_reflect_2_13//jar", + ], +) + +scala_import( + name = "scalap", + jars = [ + "//external:jar/org/scala_lang/scalap", + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__", + ], + runtime_deps = [":scala_compiler"], +) diff --git a/rules/scalafmt/3rdparty/jvm/org/scala_lang/modules/BUILD b/rules/scalafmt/3rdparty/jvm/org/scala_lang/modules/BUILD new file mode 100644 index 0000000..ecda328 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/org/scala_lang/modules/BUILD @@ -0,0 +1,26 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +scala_import( + name = "scala_collection_compat", + jars = [ + "//external:jar/org/scala_lang/modules/scala_collection_compat_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "scala_parallel_collections", + jars = [ + "//external:jar/org/scala_lang/modules/scala_parallel_collections_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/org/scalameta/BUILD b/rules/scalafmt/3rdparty/jvm/org/scalameta/BUILD new file mode 100644 index 0000000..192c907 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/org/scalameta/BUILD @@ -0,0 +1,117 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +scala_import( + name = "common", + jars = [ + "//external:jar/org/scalameta/common_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/com/lihaoyi:sourcecode", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "mdoc_parser", + jars = [ + "//external:jar/org/scalameta/mdoc_parser_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "parsers", + jars = [ + "//external:jar/org/scalameta/parsers_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + ":trees" + ], + visibility = [ + "//visibility:public" + ] +) + +scala_import( + name = "scalafmt_config", + jars = [ + "//external:jar/org/scalameta/scalafmt_config_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/com/geirsson:metaconfig_core", + "//rules/scalafmt/3rdparty/jvm/com/geirsson:metaconfig_typesafe_config", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "scalafmt_core", + jars = [ + "//external:jar/org/scalameta/scalafmt_core_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_reflect", + ":mdoc_parser", + ":scalafmt_config", + ":scalafmt_sysops", + ":scalameta" + ], + visibility = [ + "//visibility:public" + ] +) + +scala_import( + name = "scalafmt_sysops", + jars = [ + "//external:jar/org/scalameta/scalafmt_sysops_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang/modules:scala_parallel_collections", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//visibility:public" + ] +) + +scala_import( + name = "scalameta", + jars = [ + "//external:jar/org/scalameta/scalameta_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scalap", + ":parsers" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) + +scala_import( + name = "trees", + jars = [ + "//external:jar/org/scalameta/trees_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library", + ":common" + ], + visibility = [ + "//visibility:public" + ] +) diff --git a/rules/scalafmt/3rdparty/jvm/org/typelevel/BUILD b/rules/scalafmt/3rdparty/jvm/org/typelevel/BUILD new file mode 100644 index 0000000..810cdf8 --- /dev/null +++ b/rules/scalafmt/3rdparty/jvm/org/typelevel/BUILD @@ -0,0 +1,13 @@ +load("@rules_scala3//rules:scala.bzl", "scala_import") +scala_import( + name = "paiges_core", + jars = [ + "//external:jar/org/typelevel/paiges_core_2_13" + ], + runtime_deps = [ + "//rules/scalafmt/3rdparty/jvm/org/scala_lang:scala_library" + ], + visibility = [ + "//rules/scalafmt/3rdparty/jvm:__subpackages__" + ] +) diff --git a/rules/scalafmt/3rdparty/workspace.bzl b/rules/scalafmt/3rdparty/workspace.bzl new file mode 100644 index 0000000..327ad6a --- /dev/null +++ b/rules/scalafmt/3rdparty/workspace.bzl @@ -0,0 +1,70 @@ +# Do not edit. rules_scala3 autogenerates this file +def _jar_artifact_impl(ctx): + jar_name = "%s.jar" % ctx.name + ctx.download( + output = ctx.path("jar/%s" % jar_name), + url = ctx.attr.urls, + executable = False, + ) + build_file_contents = """ +package(default_visibility = ['//visibility:public']) +filegroup( + name = 'jar', + srcs = ['{jar_name}'], + visibility = ['//visibility:public'], +) +alias( + name = "file", + actual = ":jar", + visibility = ["//visibility:public"], +)\n""".format(artifact = ctx.attr.artifact, jar_name = jar_name) + ctx.file(ctx.path("jar/BUILD"), build_file_contents, False) + return None + +jar_artifact = repository_rule( + attrs = { + "artifact": attr.string(mandatory = True), + "urls": attr.string_list(mandatory = True), + }, + implementation = _jar_artifact_impl, +) + +def jar_artifact_callback(hash): + jar_artifact( + artifact = hash["artifact"], + name = hash["name"], + urls = [hash["url"]], + ) + native.bind(name = hash["bind"], actual = hash["actual"]) + + +def list_dependencies(): + return [ + {"artifact":"com.geirsson:metaconfig-core_2.13:0.12.0","url":"https://repo1.maven.org/maven2/com/geirsson/metaconfig-core_2.13/0.12.0/metaconfig-core_2.13-0.12.0.jar","name":"com_geirsson_metaconfig_core_2_13","actual":"@com_geirsson_metaconfig_core_2_13//jar","bind": "jar/com/geirsson/metaconfig_core_2_13"}, + {"artifact":"com.geirsson:metaconfig-pprint_2.13:0.12.0","url":"https://repo1.maven.org/maven2/com/geirsson/metaconfig-pprint_2.13/0.12.0/metaconfig-pprint_2.13-0.12.0.jar","name":"com_geirsson_metaconfig_pprint_2_13","actual":"@com_geirsson_metaconfig_pprint_2_13//jar","bind": "jar/com/geirsson/metaconfig_pprint_2_13"}, + {"artifact":"com.geirsson:metaconfig-typesafe-config_2.13:0.12.0","url":"https://repo1.maven.org/maven2/com/geirsson/metaconfig-typesafe-config_2.13/0.12.0/metaconfig-typesafe-config_2.13-0.12.0.jar","name":"com_geirsson_metaconfig_typesafe_config_2_13","actual":"@com_geirsson_metaconfig_typesafe_config_2_13//jar","bind": "jar/com/geirsson/metaconfig_typesafe_config_2_13"}, + {"artifact":"com.lihaoyi:fansi_2.13:0.4.0","url":"https://repo1.maven.org/maven2/com/lihaoyi/fansi_2.13/0.4.0/fansi_2.13-0.4.0.jar","name":"com_lihaoyi_fansi_2_13","actual":"@com_lihaoyi_fansi_2_13//jar","bind": "jar/com/lihaoyi/fansi_2_13"}, + {"artifact":"com.lihaoyi:sourcecode_2.13:0.4.2","url":"https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.13/0.4.2/sourcecode_2.13-0.4.2.jar","name":"com_lihaoyi_sourcecode_2_13","actual":"@com_lihaoyi_sourcecode_2_13//jar","bind": "jar/com/lihaoyi/sourcecode_2_13"}, + {"artifact":"com.typesafe:config:1.4.1","url":"https://repo1.maven.org/maven2/com/typesafe/config/1.4.1/config-1.4.1.jar","name":"com_typesafe_config","actual":"@com_typesafe_config//jar","bind": "jar/com/typesafe/config"}, + {"artifact":"io.github.java-diff-utils:java-diff-utils:4.12","url":"https://repo1.maven.org/maven2/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar","name":"io_github_java_diff_utils_java_diff_utils","actual":"@io_github_java_diff_utils_java_diff_utils//jar","bind": "jar/io/github/java_diff_utils/java_diff_utils"}, + {"artifact":"net.java.dev.jna:jna:5.13.0","url":"https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar","name":"net_java_dev_jna_jna","actual":"@net_java_dev_jna_jna//jar","bind": "jar/net/java/dev/jna/jna"}, + {"artifact":"org.jline:jline:3.22.0","url":"https://repo1.maven.org/maven2/org/jline/jline/3.22.0/jline-3.22.0.jar","name":"org_jline_jline","actual":"@org_jline_jline//jar","bind": "jar/org/jline/jline"}, + {"artifact":"org.scala-lang.modules:scala-collection-compat_2.13:2.11.0","url":"https://repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.11.0/scala-collection-compat_2.13-2.11.0.jar","name":"org_scala_lang_modules_scala_collection_compat_2_13","actual":"@org_scala_lang_modules_scala_collection_compat_2_13//jar","bind": "jar/org/scala_lang/modules/scala_collection_compat_2_13"}, + {"artifact":"org.scala-lang.modules:scala-parallel-collections_2.13:1.0.4","url":"https://repo1.maven.org/maven2/org/scala-lang/modules/scala-parallel-collections_2.13/1.0.4/scala-parallel-collections_2.13-1.0.4.jar","name":"org_scala_lang_modules_scala_parallel_collections_2_13","actual":"@org_scala_lang_modules_scala_parallel_collections_2_13//jar","bind": "jar/org/scala_lang/modules/scala_parallel_collections_2_13"}, + {"artifact":"org.scala-lang:scala-compiler:2.13.11","url":"https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.11/scala-compiler-2.13.11.jar","name":"org_scala_lang_scala_compiler","actual":"@org_scala_lang_scala_compiler//jar","bind": "jar/org/scala_lang/scala_compiler"}, + {"artifact":"org.scala-lang:scala-compiler:2.13.11","url":"https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.11/scala-compiler-2.13.11.jar","name":"org_scala_lang_scala_compiler","actual":"@org_scala_lang_scala_compiler//jar","bind": "jar/org/scala_lang/scala_compiler"}, + {"artifact":"org.scala-lang:scalap:2.13.11","url":"https://repo1.maven.org/maven2/org/scala-lang/scalap/2.13.11/scalap-2.13.11.jar","name":"org_scala_lang_scalap","actual":"@org_scala_lang_scalap//jar","bind": "jar/org/scala_lang/scalap"}, + {"artifact":"org.scalameta:common_2.13:4.10.2","url":"https://repo1.maven.org/maven2/org/scalameta/common_2.13/4.10.2/common_2.13-4.10.2.jar","name":"org_scalameta_common_2_13","actual":"@org_scalameta_common_2_13//jar","bind": "jar/org/scalameta/common_2_13"}, + {"artifact":"org.scalameta:mdoc-parser_2.13:2.5.4","url":"https://repo1.maven.org/maven2/org/scalameta/mdoc-parser_2.13/2.5.4/mdoc-parser_2.13-2.5.4.jar","name":"org_scalameta_mdoc_parser_2_13","actual":"@org_scalameta_mdoc_parser_2_13//jar","bind": "jar/org/scalameta/mdoc_parser_2_13"}, + {"artifact":"org.scalameta:parsers_2.13:4.10.2","url":"https://repo1.maven.org/maven2/org/scalameta/parsers_2.13/4.10.2/parsers_2.13-4.10.2.jar","name":"org_scalameta_parsers_2_13","actual":"@org_scalameta_parsers_2_13//jar","bind": "jar/org/scalameta/parsers_2_13"}, + {"artifact":"org.scalameta:scalafmt-config_2.13:3.8.3","url":"https://repo1.maven.org/maven2/org/scalameta/scalafmt-config_2.13/3.8.3/scalafmt-config_2.13-3.8.3.jar","name":"org_scalameta_scalafmt_config_2_13","actual":"@org_scalameta_scalafmt_config_2_13//jar","bind": "jar/org/scalameta/scalafmt_config_2_13"}, + {"artifact":"org.scalameta:scalafmt-core_2.13:3.8.3","url":"https://repo1.maven.org/maven2/org/scalameta/scalafmt-core_2.13/3.8.3/scalafmt-core_2.13-3.8.3.jar","name":"org_scalameta_scalafmt_core_2_13","actual":"@org_scalameta_scalafmt_core_2_13//jar","bind": "jar/org/scalameta/scalafmt_core_2_13"}, + {"artifact":"org.scalameta:scalafmt-sysops_2.13:3.8.3","url":"https://repo1.maven.org/maven2/org/scalameta/scalafmt-sysops_2.13/3.8.3/scalafmt-sysops_2.13-3.8.3.jar","name":"org_scalameta_scalafmt_sysops_2_13","actual":"@org_scalameta_scalafmt_sysops_2_13//jar","bind": "jar/org/scalameta/scalafmt_sysops_2_13"}, + {"artifact":"org.scalameta:scalameta_2.13:4.9.9","url":"https://repo1.maven.org/maven2/org/scalameta/scalameta_2.13/4.9.9/scalameta_2.13-4.9.9.jar","name":"org_scalameta_scalameta_2_13","actual":"@org_scalameta_scalameta_2_13//jar","bind": "jar/org/scalameta/scalameta_2_13"}, + {"artifact":"org.scalameta:trees_2.13:4.10.2","url":"https://repo1.maven.org/maven2/org/scalameta/trees_2.13/4.10.2/trees_2.13-4.10.2.jar","name":"org_scalameta_trees_2_13","actual":"@org_scalameta_trees_2_13//jar","bind": "jar/org/scalameta/trees_2_13"}, + {"artifact":"org.typelevel:paiges-core_2.13:0.4.3","url":"https://repo1.maven.org/maven2/org/typelevel/paiges-core_2.13/0.4.3/paiges-core_2.13-0.4.3.jar","name":"org_typelevel_paiges_core_2_13","actual":"@org_typelevel_paiges_core_2_13//jar","bind": "jar/org/typelevel/paiges_core_2_13"}, + ] + +def maven_dependencies(callback = jar_artifact_callback): + for hash in list_dependencies(): + callback(hash) diff --git a/rules/scalafmt/BUILD b/rules/scalafmt/BUILD index 018f0e6..ba05135 100644 --- a/rules/scalafmt/BUILD +++ b/rules/scalafmt/BUILD @@ -39,11 +39,13 @@ scala_binary( visibility = ["//visibility:public"], deps = [ "//3rdparty/jvm/com/github/scopt", + "//rules/scalafmt/3rdparty/jvm/com/geirsson:metaconfig_core", + "//rules/scalafmt/3rdparty/jvm/org/scalameta:parsers", + "//rules/scalafmt/3rdparty/jvm/org/scalameta:scalafmt_core", + "//rules/scalafmt/3rdparty/jvm/org/scalameta:scalafmt_sysops", + "//rules/scalafmt/3rdparty/jvm/org/scalameta:trees", "//scala/common/worker", "//scala/workers/common", - "@annex_scalafmt//:com_geirsson_metaconfig_core_2_13", - "@annex_scalafmt//:org_scalameta_parsers_2_13", - "@annex_scalafmt//:org_scalameta_scalafmt_core_2_13", ], ) diff --git a/rules/scalafmt/scalafmt/ScalafmtRunner.scala b/rules/scalafmt/scalafmt/ScalafmtRunner.scala index 4ee3ffd..163a1ea 100644 --- a/rules/scalafmt/scalafmt/ScalafmtRunner.scala +++ b/rules/scalafmt/scalafmt/ScalafmtRunner.scala @@ -6,7 +6,7 @@ import java.nio.file.{Files, Path, Paths} import scala.annotation.tailrec import scala.io.Codec -import org.scalafmt.config.Config +import org.scalafmt.config.ScalafmtConfig import org.scalafmt.Scalafmt import org.scalafmt.sysops.FileOps import scopt.{DefaultOParserSetup, OParser, OParserSetup} @@ -22,7 +22,7 @@ object ScalafmtRunner extends WorkerMain[Unit]: val source = FileOps.readFile(workArgs.input)(Codec.UTF8) - val config = Config.fromHoconFile(workArgs.config).get + val config = ScalafmtConfig.fromHoconFile(workArgs.config).get @tailrec def format(code: String): String = val formatted = Scalafmt.format(code, config).get if code == formatted then code else format(formatted)