bazeltools / bazel-deps

Generate bazel dependencies for maven artifacts
MIT License
249 stars 121 forks source link

Is it even possible to template your dependencies yaml file? #355

Open grepwood opened 12 months ago

grepwood commented 12 months ago

Hi,

I have a file that starts like so:

options:
  buildHeader: [ "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")" ]
  languages: [ "java", "scala:2.12.10" ]

The project in question is a gargantuan monorepo. Therefore it stands to reason that I would like to change the Scala version in one place and see the change affect literally everything, to save myself work.

I have made the following changes:

  1. Add a file in my root directory called "scala_version.bzl" that contains SCALA_VERSION = "2.12.10"
  2. I have modified my dependencies yaml like this:
    options:
    buildHeader: [ "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")" , "load(\"//:scala_version\", \"SCALA_VERSION\")" ]
    languages: [ "java", "scala:" + SCALA_VERSION ]

This is where the cookie crumbles - I have no idea how to template this file. I tried:

Unfortunately, none of those worked. Can someone help please?

johnynek commented 12 months ago

this code uses snakeyaml to parse the yaml.

you can see the extent of the Yaml interop here:

https://github.com/bazeltools/bazel-deps/blob/b5c72316251af563b07516d835b981737836bc5c/src/scala/com/github/johnynek/bazel_deps/CirceYaml.scala#L14

I have never used yaml templating like this. It is possible snakeyaml requires some configurations to work with jackson to support templates.

I am willing to review code with tests to add support, but I will not have time to add support or debug this myself.

I would recommend you use another tool to convert templated yaml into the version you pass to this tool if you don't want to dig into snakeyaml.