Skip to content

Allow use of "$(location //foo)" in compiler_options #524

@carpenterjc

Description

@carpenterjc

We use "$(location //foo)" syntax https://bazel.build/reference/be/make-variables#predefined_label_variables and have patched 19.2 to call expand_location.

Can we request support for make variable substitution using technique.

Example patch for 19.2:

diff --git dotnet/private/rules/csharp/binary.bzl dotnet/private/rules/csharp/binary.bzl
index 005e5e1..ebfd504 100644
--- dotnet/private/rules/csharp/binary.bzl
+++ dotnet/private/rules/csharp/binary.bzl
@@ -15,6 +15,12 @@ load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

 def _compile_action(ctx, tfm):
     toolchain = ctx.toolchains["//dotnet:toolchain_type"]
+
+    compiler_options = []
+    for opt in ctx.attr.compiler_options:
+        added = ctx.expand_location(opt, ctx.attr.compile_data)
+        compiler_options.append(added)
+
     return AssemblyAction(
         ctx.actions,
         ctx.executable._compiler_wrapper_bat if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else ctx.executable._compiler_wrapper_sh,
@@ -53,7 +59,7 @@ def _compile_action(ctx, tfm):
         is_analyzer = False,
         is_language_specific_analyzer = False,
         analyzer_configs = ctx.files.analyzer_configs,
-        compiler_options = ctx.attr.compiler_options,
+        compiler_options = compiler_options,
         is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]),
     )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions