From 66f66d4bfa9c26f884f0d2969b2d7a8f6dd685be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wawrzyk?= Date: Thu, 15 Jun 2023 17:19:03 +0200 Subject: [PATCH 1/2] Collect scalac options from toolchain --- install/src/main/resources/aspects.bzl | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/install/src/main/resources/aspects.bzl b/install/src/main/resources/aspects.bzl index 2cb71d240..3af4a7c6e 100644 --- a/install/src/main/resources/aspects.bzl +++ b/install/src/main/resources/aspects.bzl @@ -143,7 +143,32 @@ def extract_scala_info(target, ctx, output_groups): if not provider: return None - scalac_opts = getattr(ctx.rule.attr, "scalacopts", []) + # proper solution, but it requires adding scala_toolchain to the aspect + # SCALA_TOOLCHAIN = "@io_bazel_rules_scala//scala:toolchain_type" + # check of _scala_toolchain is necessary, because SCALA_TOOLCHAIN will always be present + # if hasattr(ctx.rule.attr, "_scala_toolchain"): + # common_scalac_opts = ctx.toolchains[SCALA_TOOLCHAIN].scalacopts + # else: + # common_scalac_opts = [] + # scalac_opts = common_scalac_opts + getattr(ctx.rule.attr, "scalacopts", []) + + scalac_opts = [] + + # don't bother inspecting non-scala targets + if hasattr(ctx.rule.attr, "_scala_toolchain"): + for action in target.actions: + if action.mnemonic == "Scalac": + found_scalac_opts = False + for arg in action.argv: + if arg == "--ScalacOpts": + found_scalac_opts = True + elif found_scalac_opts: + # Next worker option appeared. + # Currently --ScalacOpts is the last one, but just in case + if arg.startswith("--"): + break + scalac_opts.append(arg) + break scala_info = struct( scalac_opts = scalac_opts, From 428b683aa62461af24593b72e7ea8da43307bb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wawrzyk?= Date: Fri, 16 Jun 2023 14:49:17 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcbc49979..a3cf7e198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,15 @@ ## [Unreleased] + +### Fixes 🛠️ +- Collect scalac options from the toolchain + | [#433](https://github.com/JetBrains/bazel-bsp/pull/433) + ### Performance - Reduce peak memory footprint | [#428](https://github.com/JetBrains/bazel-bsp/pull/428) + ## [2.7.1] ### Fixes 🛠️