Skip to content

Commit

Permalink
WIP: Bzlmod part the forty-ninth
Browse files Browse the repository at this point in the history
Made the config extension aware of the `SCALA_VERSION` and
`ENABLE_COMPILER_DEPENDENCY_TRACKING` env vars to fix part of
`test_classpath_contains_2_12` from test/shell/test_scala_config.sh.

Now it's dying with:

```txt
Analyzing: target //src/java/io/bazel/rulesscala/scalac:scalac
  (1 packages loaded, 0 targets configured)

ERROR: Traceback (most recent call last):
File ".../scala/extensions/deps.bzl", line 210, column 30,
  in _scala_deps_impl
    scalafmt_repositories(
File ".../scala/scalafmt/scalafmt_repositories.bzl", line 67, column 21,
  in scalafmt_repositories
    repositories(
File ".../third_party/repositories/repositories.bzl", line 103, column 33,
  in repositories
    artifact = artifacts[id]["artifact"],

Error: key "com_geirsson_metaconfig_pprint" not found in dictionary
ERROR: Analysis of target '//src/java/io/bazel/rulesscala/scalac:scalac'
  failed; build aborted: error evaluating module extension scala_deps in
  //scala/extensions:deps.bzl
```

Still, getting closer and closer to getting all the tests to pass under
Bzlmod!
  • Loading branch information
mbland committed Oct 8, 2024
1 parent 83f383c commit b9aea94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
10 changes: 7 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions scala/extensions/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ _settings = tag_class(
)

def _get_root_settings(module_ctx):
scala_version = DEFAULT_SCALA_VERSION
compiler_dep_tracking = False
root_settings = module_ctx.modules[0].tags.settings

if len(root_settings) == 0:
return DEFAULT_SCALA_VERSION, False
root = root_settings[0]
return root.scala_version, root.enable_compiler_dependency_tracking
if len(root_settings) != 0:
root = root_settings[0]
scala_version = root.scala_version
compiler_dep_tracking = root.enable_compiler_dependency_tracking

def _collect_versions(module_ctx):
versions = {}
return (
module_ctx.os.environ.get("SCALA_VERSION", scala_version),
module_ctx.os.environ.get(
"ENABLE_COMPILER_DEPENDENCY_TRACKING", compiler_dep_tracking
),
)

def _collect_versions(module_ctx, scala_version):
versions = {scala_version: None}

for mod in module_ctx.modules:
for settings in mod.tags.settings:
Expand All @@ -33,7 +42,7 @@ def _scala_config_impl(module_ctx):

_scala_config(
scala_version = version,
scala_versions = _collect_versions(module_ctx),
scala_versions = _collect_versions(module_ctx, version),
enable_compiler_dependency_tracking = compiler_dep_tracking,
)
return module_ctx.extension_metadata(
Expand All @@ -44,4 +53,5 @@ def _scala_config_impl(module_ctx):
scala_config = module_extension(
implementation = _scala_config_impl,
tag_classes = {"settings": _settings},
environ = ["SCALA_VERSION", "ENABLE_COMPILER_DEPENDENCY_TRACKING"],
)

0 comments on commit b9aea94

Please sign in to comment.