fix: write_source_files should use target platform for additional_update_targets (#297)

This commit is contained in:
Greg Magolan 2022-12-03 15:02:33 -08:00 committed by GitHub
parent 68aee64093
commit 35b7662e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -158,7 +158,15 @@ _write_source_file_attrs = {
"out_file": attr.string(mandatory = False),
"executable": attr.bool(),
# buildifier: disable=attr-cfg
"additional_update_targets": attr.label_list(cfg = "host", mandatory = False, providers = [WriteSourceFileInfo]),
"additional_update_targets": attr.label_list(
# Intentionally use the target platform since the target is always meant to be `bazel run`
# on the host machine but we don't want to transition it to the host platform and have the
# generated file rebuilt in a separate output tree. Target platform should always be equal
# to the host platform when using `write_source_files`.
cfg = "target",
mandatory = False,
providers = [WriteSourceFileInfo],
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_macos_constraint": attr.label(default = "@platforms//os:macos"),
}

View File

@ -152,7 +152,10 @@ _write_source_file_test = rule(
"write_source_file_target": attr.label(
allow_single_file = True,
executable = True,
# Should be cfg = "exec" but a bazel bug causes a wrong executable symlink on windows
# Intentionally use the target platform since the target is always meant to be `bazel
# run` on the host machine but we don't want to transition it to the host platform and
# have the generated file rebuilt in a separate output tree. Target platform should
# always be equal to the host platform when using `write_source_files`.
cfg = "target",
mandatory = True,
),