From 80f0abde25ec17a4113189b0cff3fbaa96d9c3f4 Mon Sep 17 00:00:00 2001 From: "P. Oscar Boykin" Date: Wed, 6 Jul 2016 20:11:26 -1000 Subject: [PATCH] Support runtime_deps rather than exports for maven deps (#12) * checkpoint support for runtime_deps * update exports * use runtime deps and not exports by default --- 3rdparty/jvm/com/fasterxml/jackson/core/BUILD | 4 +- .../com/fasterxml/jackson/dataformat/BUILD | 8 ++-- 3rdparty/jvm/com/google/guava/BUILD | 4 +- 3rdparty/jvm/io/circe/BUILD | 38 +++++++++--------- 3rdparty/jvm/javax/enterprise/BUILD | 4 +- 3rdparty/jvm/org/apache/httpcomponents/BUILD | 6 +-- 3rdparty/jvm/org/apache/maven/BUILD | 26 ++++++------ 3rdparty/jvm/org/eclipse/aether/BUILD | 36 ++++++++--------- 3rdparty/jvm/org/eclipse/sisu/BUILD | 14 +++---- 3rdparty/jvm/org/scalacheck/BUILD | 8 ++-- 3rdparty/jvm/org/slf4j/BUILD | 4 +- 3rdparty/jvm/org/typelevel/BUILD | 40 +++++++++---------- README.md | 10 ++++- dependencies.yaml | 19 ++++++++- .../com/github/johnynek/bazel_deps/BUILD | 11 ++++- .../github/johnynek/bazel_deps/Decoders.scala | 6 +++ .../johnynek/bazel_deps/DepsModel.scala | 14 ++++++- .../github/johnynek/bazel_deps/Writer.scala | 32 +++++++++------ 18 files changed, 168 insertions(+), 116 deletions(-) diff --git a/3rdparty/jvm/com/fasterxml/jackson/core/BUILD b/3rdparty/jvm/com/fasterxml/jackson/core/BUILD index 463eacf..f8958df 100644 --- a/3rdparty/jvm/com/fasterxml/jackson/core/BUILD +++ b/3rdparty/jvm/com/fasterxml/jackson/core/BUILD @@ -7,6 +7,6 @@ java_library(name = "jackson_core", visibility = ["//visibility:public"]) java_library(name = "jackson_databind", - exports = ["//external:jar/com/fasterxml/jackson/core/jackson_databind", - ":jackson_annotations"], + exports = ["//external:jar/com/fasterxml/jackson/core/jackson_databind"], + runtime_deps = [":jackson_annotations"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/com/fasterxml/jackson/dataformat/BUILD b/3rdparty/jvm/com/fasterxml/jackson/dataformat/BUILD index 2ae8ae1..6d2d329 100644 --- a/3rdparty/jvm/com/fasterxml/jackson/dataformat/BUILD +++ b/3rdparty/jvm/com/fasterxml/jackson/dataformat/BUILD @@ -1,6 +1,6 @@ java_library(name = "jackson_dataformat_yaml", - exports = ["//3rdparty/jvm/com/fasterxml/jackson/core:jackson_core", - "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_databind", - "//3rdparty/jvm/org/yaml:snakeyaml", - "//external:jar/com/fasterxml/jackson/dataformat/jackson_dataformat_yaml"], + exports = ["//external:jar/com/fasterxml/jackson/dataformat/jackson_dataformat_yaml"], + runtime_deps = ["//3rdparty/jvm/com/fasterxml/jackson/core:jackson_core", + "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_databind", + "//3rdparty/jvm/org/yaml:snakeyaml"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/com/google/guava/BUILD b/3rdparty/jvm/com/google/guava/BUILD index 8766213..5e8acb6 100644 --- a/3rdparty/jvm/com/google/guava/BUILD +++ b/3rdparty/jvm/com/google/guava/BUILD @@ -1,4 +1,4 @@ java_library(name = "guava", - exports = ["//3rdparty/jvm/com/google/code/findbugs:jsr305", - "//external:jar/com/google/guava/guava"], + exports = ["//external:jar/com/google/guava/guava"], + runtime_deps = ["//3rdparty/jvm/com/google/code/findbugs:jsr305"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/io/circe/BUILD b/3rdparty/jvm/io/circe/BUILD index e317d8a..60f2881 100644 --- a/3rdparty/jvm/io/circe/BUILD +++ b/3rdparty/jvm/io/circe/BUILD @@ -1,29 +1,31 @@ scala_library(name = "circe_core", - exports = ["//3rdparty/jvm/org/scala_lang:scala_library", - "//3rdparty/jvm/org/typelevel:cats_core", - "//external:jar/io/circe/circe_core_2_11", - ":circe_numbers_2_11"], + exports = ["//external:jar/io/circe/circe_core_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang:scala_library", + "//3rdparty/jvm/org/typelevel:cats_core", + ":circe_numbers_2_11"], visibility = ["//visibility:public"]) scala_library(name = "circe_generic", exports = ["//3rdparty/jvm/com/chuusai:shapeless", - "//3rdparty/jvm/org/scala_lang:scala_library", + "//3rdparty/jvm/org/typelevel:cats_core", + "//3rdparty/jvm/org/typelevel:cats_kernel", "//3rdparty/jvm/org/typelevel:macro_compat", - "//external:jar/io/circe/circe_generic_2_11", - ":circe_core"], + "//external:jar/io/circe/circe_generic_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang:scala_library", + ":circe_core"], visibility = ["//visibility:public"]) scala_library(name = "circe_jackson", - exports = ["//3rdparty/jvm/com/fasterxml/jackson/core:jackson_core", - "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_databind", - "//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/io/circe/circe_jackson_2_11", - ":circe_core"], + exports = ["//external:jar/io/circe/circe_jackson_2_11"], + runtime_deps = ["//3rdparty/jvm/com/fasterxml/jackson/core:jackson_core", + "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_databind", + "//3rdparty/jvm/org/scala_lang:scala_library", + ":circe_core"], visibility = ["//visibility:public"]) java_library(name = "circe_jawn_2_11", - exports = ["//3rdparty/jvm/org/spire_math:jawn_parser_2_11", - "//external:jar/io/circe/circe_jawn_2_11"], + exports = ["//external:jar/io/circe/circe_jawn_2_11"], + runtime_deps = ["//3rdparty/jvm/org/spire_math:jawn_parser_2_11"], visibility = ["//visibility:public"]) java_library(name = "circe_numbers_2_11", @@ -31,8 +33,8 @@ java_library(name = "circe_numbers_2_11", visibility = ["//visibility:public"]) scala_library(name = "circe_parser", - exports = ["//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/io/circe/circe_parser_2_11", - ":circe_core", - ":circe_jawn_2_11"], + exports = ["//external:jar/io/circe/circe_parser_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang:scala_library", + ":circe_core", + ":circe_jawn_2_11"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/javax/enterprise/BUILD b/3rdparty/jvm/javax/enterprise/BUILD index e5b0ab0..f8a997d 100644 --- a/3rdparty/jvm/javax/enterprise/BUILD +++ b/3rdparty/jvm/javax/enterprise/BUILD @@ -1,4 +1,4 @@ java_library(name = "cdi_api", - exports = ["//3rdparty/jvm/javax/annotation:jsr250_api", - "//external:jar/javax/enterprise/cdi_api"], + exports = ["//external:jar/javax/enterprise/cdi_api"], + runtime_deps = ["//3rdparty/jvm/javax/annotation:jsr250_api"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/org/apache/httpcomponents/BUILD b/3rdparty/jvm/org/apache/httpcomponents/BUILD index d7fc203..cd9735a 100644 --- a/3rdparty/jvm/org/apache/httpcomponents/BUILD +++ b/3rdparty/jvm/org/apache/httpcomponents/BUILD @@ -1,7 +1,7 @@ java_library(name = "httpclient", - exports = ["//3rdparty/jvm/commons_codec:commons_codec", - "//external:jar/org/apache/httpcomponents/httpclient", - ":httpcore"], + exports = ["//external:jar/org/apache/httpcomponents/httpclient"], + runtime_deps = ["//3rdparty/jvm/commons_codec:commons_codec", + ":httpcore"], visibility = ["//visibility:public"]) java_library(name = "httpcore", diff --git a/3rdparty/jvm/org/apache/maven/BUILD b/3rdparty/jvm/org/apache/maven/BUILD index b9c8eb2..0bdeff8 100644 --- a/3rdparty/jvm/org/apache/maven/BUILD +++ b/3rdparty/jvm/org/apache/maven/BUILD @@ -1,15 +1,15 @@ java_library(name = "maven_aether_provider", - exports = ["//3rdparty/jvm/org/codehaus/plexus:plexus_component_annotations", - "//3rdparty/jvm/org/codehaus/plexus:plexus_utils", - "//3rdparty/jvm/org/eclipse/aether:aether_api", - "//3rdparty/jvm/org/eclipse/aether:aether_impl", - "//3rdparty/jvm/org/eclipse/aether:aether_spi", - "//3rdparty/jvm/org/eclipse/aether:aether_util", - "//3rdparty/jvm/org/eclipse/sisu:org_eclipse_sisu_plexus", - "//external:jar/org/apache/maven/maven_aether_provider", - ":maven_model", - ":maven_model_builder", - ":maven_repository_metadata"], + exports = ["//external:jar/org/apache/maven/maven_aether_provider"], + runtime_deps = ["//3rdparty/jvm/org/codehaus/plexus:plexus_component_annotations", + "//3rdparty/jvm/org/codehaus/plexus:plexus_utils", + "//3rdparty/jvm/org/eclipse/aether:aether_api", + "//3rdparty/jvm/org/eclipse/aether:aether_impl", + "//3rdparty/jvm/org/eclipse/aether:aether_spi", + "//3rdparty/jvm/org/eclipse/aether:aether_util", + "//3rdparty/jvm/org/eclipse/sisu:org_eclipse_sisu_plexus", + ":maven_model", + ":maven_model_builder", + ":maven_repository_metadata"], visibility = ["//visibility:public"]) java_library(name = "maven_model", @@ -17,8 +17,8 @@ java_library(name = "maven_model", visibility = ["//visibility:public"]) java_library(name = "maven_model_builder", - exports = ["//3rdparty/jvm/org/codehaus/plexus:plexus_interpolation", - "//external:jar/org/apache/maven/maven_model_builder"], + exports = ["//external:jar/org/apache/maven/maven_model_builder"], + runtime_deps = ["//3rdparty/jvm/org/codehaus/plexus:plexus_interpolation"], visibility = ["//visibility:public"]) java_library(name = "maven_repository_metadata", diff --git a/3rdparty/jvm/org/eclipse/aether/BUILD b/3rdparty/jvm/org/eclipse/aether/BUILD index 4774d54..5c2d995 100644 --- a/3rdparty/jvm/org/eclipse/aether/BUILD +++ b/3rdparty/jvm/org/eclipse/aether/BUILD @@ -3,17 +3,17 @@ java_library(name = "aether_api", visibility = ["//visibility:public"]) java_library(name = "aether_connector_basic", - exports = ["//external:jar/org/eclipse/aether/aether_connector_basic", - ":aether_api", - ":aether_spi", - ":aether_util"], + exports = ["//external:jar/org/eclipse/aether/aether_connector_basic"], + runtime_deps = [":aether_api", + ":aether_spi", + ":aether_util"], visibility = ["//visibility:public"]) java_library(name = "aether_impl", - exports = ["//external:jar/org/eclipse/aether/aether_impl", - ":aether_api", - ":aether_spi", - ":aether_util"], + exports = ["//external:jar/org/eclipse/aether/aether_impl"], + runtime_deps = [":aether_api", + ":aether_spi", + ":aether_util"], visibility = ["//visibility:public"]) java_library(name = "aether_spi", @@ -21,19 +21,19 @@ java_library(name = "aether_spi", visibility = ["//visibility:public"]) java_library(name = "aether_transport_file", - exports = ["//external:jar/org/eclipse/aether/aether_transport_file", - ":aether_api", - ":aether_spi", - ":aether_util"], + exports = ["//external:jar/org/eclipse/aether/aether_transport_file"], + runtime_deps = [":aether_api", + ":aether_spi", + ":aether_util"], visibility = ["//visibility:public"]) java_library(name = "aether_transport_http", - exports = ["//3rdparty/jvm/org/apache/httpcomponents:httpclient", - "//3rdparty/jvm/org/slf4j:jcl_over_slf4j", - "//external:jar/org/eclipse/aether/aether_transport_http", - ":aether_api", - ":aether_spi", - ":aether_util"], + exports = ["//external:jar/org/eclipse/aether/aether_transport_http"], + runtime_deps = ["//3rdparty/jvm/org/apache/httpcomponents:httpclient", + "//3rdparty/jvm/org/slf4j:jcl_over_slf4j", + ":aether_api", + ":aether_spi", + ":aether_util"], visibility = ["//visibility:public"]) java_library(name = "aether_util", diff --git a/3rdparty/jvm/org/eclipse/sisu/BUILD b/3rdparty/jvm/org/eclipse/sisu/BUILD index ff4c9b4..b36e57b 100644 --- a/3rdparty/jvm/org/eclipse/sisu/BUILD +++ b/3rdparty/jvm/org/eclipse/sisu/BUILD @@ -1,12 +1,12 @@ java_library(name = "org_eclipse_sisu_inject", - exports = ["//3rdparty/jvm/asm:asm", - "//external:jar/org/eclipse/sisu/org_eclipse_sisu_inject"], + exports = ["//external:jar/org/eclipse/sisu/org_eclipse_sisu_inject"], + runtime_deps = ["//3rdparty/jvm/asm:asm"], visibility = ["//visibility:public"]) java_library(name = "org_eclipse_sisu_plexus", - exports = ["//3rdparty/jvm/com/google/guava:guava", - "//3rdparty/jvm/javax/enterprise:cdi_api", - "//3rdparty/jvm/org/codehaus/plexus:plexus_classworlds", - "//external:jar/org/eclipse/sisu/org_eclipse_sisu_plexus", - ":org_eclipse_sisu_inject"], + exports = ["//external:jar/org/eclipse/sisu/org_eclipse_sisu_plexus"], + runtime_deps = ["//3rdparty/jvm/com/google/guava:guava", + "//3rdparty/jvm/javax/enterprise:cdi_api", + "//3rdparty/jvm/org/codehaus/plexus:plexus_classworlds", + ":org_eclipse_sisu_inject"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/org/scalacheck/BUILD b/3rdparty/jvm/org/scalacheck/BUILD index 50b95c3..e5f8269 100644 --- a/3rdparty/jvm/org/scalacheck/BUILD +++ b/3rdparty/jvm/org/scalacheck/BUILD @@ -1,6 +1,6 @@ scala_library(name = "scalacheck", - exports = ["//3rdparty/jvm/org/scala_lang/modules:scala_parser_combinators", - "//3rdparty/jvm/org/scala_lang:scala_library", - "//3rdparty/jvm/org/scala_sbt:test_interface", - "//external:jar/org/scalacheck/scalacheck_2_11"], + exports = ["//external:jar/org/scalacheck/scalacheck_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang/modules:scala_parser_combinators", + "//3rdparty/jvm/org/scala_lang:scala_library", + "//3rdparty/jvm/org/scala_sbt:test_interface"], visibility = ["//visibility:public"]) diff --git a/3rdparty/jvm/org/slf4j/BUILD b/3rdparty/jvm/org/slf4j/BUILD index 2bf94c3..8fef3cc 100644 --- a/3rdparty/jvm/org/slf4j/BUILD +++ b/3rdparty/jvm/org/slf4j/BUILD @@ -1,6 +1,6 @@ java_library(name = "jcl_over_slf4j", - exports = ["//external:jar/org/slf4j/jcl_over_slf4j", - ":slf4j_api"], + exports = ["//external:jar/org/slf4j/jcl_over_slf4j"], + runtime_deps = [":slf4j_api"], visibility = ["//visibility:public"]) java_library(name = "slf4j_api", diff --git a/3rdparty/jvm/org/typelevel/BUILD b/3rdparty/jvm/org/typelevel/BUILD index d559a96..e143c13 100644 --- a/3rdparty/jvm/org/typelevel/BUILD +++ b/3rdparty/jvm/org/typelevel/BUILD @@ -1,36 +1,36 @@ scala_library(name = "cats_core", - exports = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", - "//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/org/typelevel/cats_core_2_11", - ":cats_kernel", - ":cats_macros", - ":machinist"], + exports = ["//external:jar/org/typelevel/cats_core_2_11", + ":cats_kernel"], + runtime_deps = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", + "//3rdparty/jvm/org/scala_lang:scala_library", + ":cats_macros", + ":machinist"], visibility = ["//visibility:public"]) scala_library(name = "cats_free", - exports = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", - "//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/org/typelevel/cats_free_2_11", - ":cats_core", - ":cats_macros", - ":machinist"], + exports = ["//external:jar/org/typelevel/cats_free_2_11"], + runtime_deps = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", + "//3rdparty/jvm/org/scala_lang:scala_library", + ":cats_core", + ":cats_macros", + ":machinist"], visibility = ["//visibility:public"]) scala_library(name = "cats_kernel", - exports = ["//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/org/typelevel/cats_kernel_2_11"], + exports = ["//external:jar/org/typelevel/cats_kernel_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang:scala_library"], visibility = ["//visibility:public"]) scala_library(name = "cats_macros", - exports = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", - "//3rdparty/jvm/org/scala_lang:scala_library", - "//external:jar/org/typelevel/cats_macros_2_11", - ":machinist"], + exports = ["//external:jar/org/typelevel/cats_macros_2_11"], + runtime_deps = ["//3rdparty/jvm/com/github/mpilquist:simulacrum", + "//3rdparty/jvm/org/scala_lang:scala_library", + ":machinist"], visibility = ["//visibility:public"]) scala_library(name = "machinist", - exports = ["//3rdparty/jvm/org/scala_lang:scala_reflect", - "//external:jar/org/typelevel/machinist_2_11"], + exports = ["//external:jar/org/typelevel/machinist_2_11"], + runtime_deps = ["//3rdparty/jvm/org/scala_lang:scala_reflect"], visibility = ["//visibility:public"]) scala_library(name = "macro_compat", diff --git a/README.md b/README.md index 0a57219..f086527 100755 --- a/README.md +++ b/README.md @@ -70,9 +70,15 @@ dependencies: Each group id can only appear once, so you should collocate dependencies by group. ### Options -In the options, we set the allowed languages (and in the case of scala, the version). +In the options we set: + +* languages: java and scala +* versionConflictPolicy: `fixed`, `fail` or `highest` +* transitivity: `runtime_deps` or `exports` +* resolvers: the maven servers to use. + In the default case, with no options given, we use the `highest` versionConflictPolicy, -allow java and scala `2.11`, and use maven central as the resolver. +exports transitivity, allow java and scala `2.11`, and use maven central as the resolver. ### Replacements Some maven jars should not be used and instead are replaced by internal targets. Here are diff --git a/dependencies.yaml b/dependencies.yaml index 5fdf494..ed212c9 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,6 +1,7 @@ options: languages: ["java", "scala:2.11.8"] versionConflictPolicy: highest + transitivity: runtime_deps resolvers: - id: mavencentral type: default @@ -16,8 +17,16 @@ dependencies: io.circe: circe: version: "0.5.0-M2" - modules: [core, generic, jackson, parser] + modules: [core, jackson, parser] lang: scala + circe-generic: + version: "0.5.0-M2" + lang: scala + exports: + - "com.chuusai:shapeless" + - "org.typelevel:cats-core" + - "org.typelevel:cats-kernel" + - "org.typelevel:macro-compat" org.apache.maven: maven-aether-provider: @@ -38,7 +47,12 @@ dependencies: cats: version: 0.6.0 lang: scala - modules: [core, kernel, macros, free] + modules: [kernel, macros, free] + cats-core: + version: 0.6.0 + lang: scala + exports: ["org.typelevel:cats-kernel"] + macro-compat: lang: scala @@ -49,6 +63,7 @@ dependencies: com.github.mpilquist: simulacrum: lang: scala # not using explicitly, declaring as scala + exports: ["org.typelevel:macro-compat"] replacements: org.scala-lang: diff --git a/src/scala/com/github/johnynek/bazel_deps/BUILD b/src/scala/com/github/johnynek/bazel_deps/BUILD index b644bdf..ee89072 100644 --- a/src/scala/com/github/johnynek/bazel_deps/BUILD +++ b/src/scala/com/github/johnynek/bazel_deps/BUILD @@ -12,8 +12,9 @@ scala_repl(name = "repl", scala_library(name = "resolver", srcs = ["Resolver.scala"], deps = [ - "//3rdparty/jvm/org/apache/maven:maven_aether_provider", + "//3rdparty/jvm/org/apache/maven:maven_aether_provider", "//3rdparty/jvm/org/eclipse/aether:aether_api", + "//3rdparty/jvm/org/eclipse/aether:aether_spi", "//3rdparty/jvm/org/eclipse/aether:aether_connector_basic", "//3rdparty/jvm/org/eclipse/aether:aether_impl", "//3rdparty/jvm/org/eclipse/aether:aether_transport_file", @@ -25,7 +26,10 @@ scala_library(name = "resolver", scala_library(name = "io", srcs = ["IO.scala"], - deps = ["//3rdparty/jvm/org/typelevel:cats_free"], + deps = [ + "//3rdparty/jvm/org/typelevel:cats_core", + "//3rdparty/jvm/org/typelevel:cats_free" + ], visibility = ["//visibility:public"]) scala_library(name = "normalizer", @@ -77,8 +81,11 @@ scala_binary(name = "parseproject", scala_library(name = "circeyaml", srcs = ["CirceYaml.scala"], deps = [ + "//3rdparty/jvm/org/typelevel:cats_core", "//3rdparty/jvm/io/circe:circe_core", "//3rdparty/jvm/io/circe:circe_jackson", + "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_core", + "//3rdparty/jvm/com/fasterxml/jackson/core:jackson_databind", "//3rdparty/jvm/com/fasterxml/jackson/dataformat:jackson_dataformat_yaml", ], visibility = ["//visibility:public"]) diff --git a/src/scala/com/github/johnynek/bazel_deps/Decoders.scala b/src/scala/com/github/johnynek/bazel_deps/Decoders.scala index e629db7..58c4ae9 100644 --- a/src/scala/com/github/johnynek/bazel_deps/Decoders.scala +++ b/src/scala/com/github/johnynek/bazel_deps/Decoders.scala @@ -9,6 +9,12 @@ object Decoders { implicit val subprojDecoder: Decoder[Subproject] = stringWrapper(Subproject(_)) implicit val dirnameDecoder: Decoder[DirectoryName] = stringWrapper(DirectoryName(_)) implicit val targetDecoder: Decoder[BazelTarget] = stringWrapper(BazelTarget(_)) + implicit val transitivityDecoder: Decoder[Transitivity] = + Decoder.decodeString.emap { + case "exports" => Xor.right(Transitivity.Exports) + case "runtime_deps" => Xor.right(Transitivity.RuntimeDeps) + case other => Xor.left(s"unrecogized transitivity: $other") + } implicit val groupArtDecoder: Decoder[(MavenGroup, ArtifactOrProject)] = Decoder.decodeString.emap { s => s.split(':') match { diff --git a/src/scala/com/github/johnynek/bazel_deps/DepsModel.scala b/src/scala/com/github/johnynek/bazel_deps/DepsModel.scala index a600633..41e2113 100644 --- a/src/scala/com/github/johnynek/bazel_deps/DepsModel.scala +++ b/src/scala/com/github/johnynek/bazel_deps/DepsModel.scala @@ -435,11 +435,18 @@ object DirectoryName { def default: DirectoryName = DirectoryName("3rdparty/jvm") } +sealed abstract class Transitivity +object Transitivity { + case object RuntimeDeps extends Transitivity + case object Exports extends Transitivity +} + case class Options( versionConflictPolicy: Option[VersionConflictPolicy], thirdPartyDirectory: Option[DirectoryName], languages: Option[List[Language]], - resolvers: Option[List[MavenServer]]) { + resolvers: Option[List[MavenServer]], + transitivity: Option[Transitivity]) { def getThirdPartyDirectory: DirectoryName = thirdPartyDirectory.getOrElse(DirectoryName.default) @@ -454,8 +461,11 @@ case class Options( def getResolvers: List[MavenServer] = resolvers.getOrElse( List(MavenServer("central", "default", "http://central.maven.org/maven2/"))) + + def getTransitivity: Transitivity = + transitivity.getOrElse(Transitivity.Exports) } object Options { - def default: Options = Options(None, None, None, None) + def default: Options = Options(None, None, None, None, None) } diff --git a/src/scala/com/github/johnynek/bazel_deps/Writer.scala b/src/scala/com/github/johnynek/bazel_deps/Writer.scala index 4edea1a..17667a9 100644 --- a/src/scala/com/github/johnynek/bazel_deps/Writer.scala +++ b/src/scala/com/github/johnynek/bazel_deps/Writer.scala @@ -140,7 +140,7 @@ object Writer { val langFn = language(g, model) def replacedTarget(u: UnversionedCoordinate): Option[Target] = Label.replaced(u, model.getReplacements).map { case (lab, lang) => - Target(lang, Label.localTarget(pathInRoot, u, lang), Nil, List(lab), Nil) + Target(lang, Label.localTarget(pathInRoot, u, lang), Set.empty, Set(lab), Set.empty) } /* * We make 1 label for each target, the path @@ -149,20 +149,26 @@ object Writer { val cache = scala.collection.mutable.Map[UnversionedCoordinate, Target]() def coordToTarget(u: UnversionedCoordinate): Target = cache.getOrElseUpdate(u, { val deps = g.hasSource(uvToVerExplicit(u)) - val depLabels = deps.map { e => targetFor(e.destination.unversioned).name }.toList - def labLang(u: UnversionedCoordinate): (Label, Language) = + val depLabels = deps.map { e => targetFor(e.destination.unversioned).name } + val (lab, lang) = Label.replaced(u, model.getReplacements) .getOrElse { (Label.parse(u.bindTarget), langFn(u)) } - val (lab, lang) = labLang(u) - // Build explicit exports: + // Build explicit exports, no need to add these to runtime deps val uvexports = model.dependencies .exportedUnversioned(u, model.getReplacements).right.get - .map(labLang(_)._1) + .map(targetFor(_).name) - val exports = lab :: (depLabels ::: uvexports) - Target(lang, Label.localTarget(pathInRoot, u, lang), Nil, exports, Nil) + val (exports, runtime_deps) = model.getOptions.getTransitivity match { + case Transitivity.Exports => (depLabels + lab, Set.empty[Label]) + case Transitivity.RuntimeDeps => (Set(lab), depLabels) + } + Target(lang, + Label.localTarget(pathInRoot, u, lang), + Set.empty, + exports ++ uvexports, + runtime_deps -- uvexports) }) def targetFor(u: UnversionedCoordinate): Target = replacedTarget(u).getOrElse(coordToTarget(u)) @@ -237,9 +243,9 @@ object Label { case class Target( lang: Language, name: Label, - deps: List[Label], - exports: List[Label], - runtimeDeps: List[Label]) { + deps: Set[Label], + exports: Set[Label], + runtimeDeps: Set[Label]) { def toBazelString: String = { /** @@ -250,7 +256,7 @@ case class Target( * runtime_deps = [ ], * visibility = ["//visibility:public"]) */ - def labelList(outerIndent: Int, key: String, l: List[Label]): String = { + def labelList(outerIndent: Int, key: String, l: Set[Label]): String = { if (l.isEmpty) "" else { val prefix = s"$key = [" @@ -259,7 +265,7 @@ case class Target( l.map { label => val str = label.asStringFrom(name.path) s""""$str"""" - }.sorted.mkString("[", s",\n$spaced", "]") + }.toList.sorted.mkString("[", s",\n$spaced", "]") } } val langName = lang match {