Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix make substitution in starlark cc_test env #19038

Closed
wants to merge 1 commit into from

Conversation

dflems
Copy link
Contributor

@dflems dflems commented Jul 24, 2023

#18882 introduced an issue where nested make variable substitution would fail under cc_test. The change to the starlark tests fails before the change in cc_helper.bzl and passes after.

cc_test(
    name = "test",
    srcs = ["test.cc"],
    data = ["data.txt"],
    env = {
        "DATA_LOCATION": "$(location :data.txt)",
    }
)
ERROR: /playground/BUILD.bazel:1:8: in cc_test rule //:test:
Traceback (most recent call last):
	File "/virtual_builtins_bzl/common/cc/cc_test.bzl", line 70, column 29, in _impl
	File "/virtual_builtins_bzl/common/cc/cc_test.bzl", line 30, column 47, in _cc_test_impl
	File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 900, column 34, in _get_expanded_env
	File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 783, column 46, in _expand
	File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 717, column 27, in _expand_nested_variable
Error in extend: trying to mutate a frozen list value
ERROR: /playground/BUILD.bazel:1:8: Analysis of target '//:test' failed
ERROR: Analysis of target '//:test' failed; build aborted:

@brentleyjones @oquenchil

@dflems dflems requested a review from iancha1992 as a code owner July 24, 2023 23:08
@brentleyjones
Copy link
Contributor

@iancha1992 I think this deserves going into a 6.3.1 release.

@brentleyjones
Copy link
Contributor

@dflems thank you 🙏. Do we need a similar change on master? There it is also set to a default. Regardless it would be nice to have this test there as well.

@dflems
Copy link
Contributor Author

dflems commented Jul 24, 2023

@brentleyjones I think master differs in a way where this doesn't happen there

def _expand_nested_variable(ctx, additional_vars, exp, execpath = True, targets = []):
# If make variable is predefined path variable(like $(location ...))
# we will expand it first.
if exp.find(" ") != -1:
if not execpath:
if exp.startswith("location"):
exp = exp.replace("location", "rootpath", 1)
data_targets = []
if ctx.attr.data != None:
data_targets = ctx.attr.data
# Make sure we do not duplicate targets.
unified_targets_set = {}
for data_target in data_targets:
unified_targets_set[data_target] = True
for target in targets:
unified_targets_set[target] = True
return ctx.expand_location("$({})".format(exp), targets = unified_targets_set.keys())

Alternatively, we could cherry-pick the changes from master if they apply ok

@iancha1992
Copy link
Member

cc: @bazelbuild/triage

@keertk
Copy link
Member

keertk commented Jul 24, 2023

Hi @dflems could you submit a PR against master?
We can cherry-pick it into the release branch once approved and merged.

(Since 6.3.0 has been released, the release-6.3.0 branch is no longer active. We'll have to create a new one if we do a patch release.)

@dflems
Copy link
Contributor Author

dflems commented Jul 25, 2023

@keertk Master differs to the point where this patch cannot be applied, unfortunately

@dflems
Copy link
Contributor Author

dflems commented Jul 25, 2023

@brentleyjones @keertk @iancha1992

Looks like a fix for this exists on master at a63d8eb

Landed ~6mo ago but never landed on 6.x?

@brentleyjones
Copy link
Contributor

Ahh. I just missed it when performing my other cherry-pick. We should take that instead.

@brentleyjones
Copy link
Contributor

I can cherry-pick that against the new branch (if you haven't by the time I get to my computer). Thanks for the find!

@brentleyjones
Copy link
Contributor

@iancha1992 I'm pretty sure we will need a 6.3.1 release. Would you be able to create that branch?

@Pavank1992 Pavank1992 added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Jul 25, 2023
@buildbreaker2021
Copy link
Contributor

Hey, AFAIU we will cherry-pick a63d8eb instead of this PR right?
Because I remember I solved the same issue with that commit.

@keertk
Copy link
Member

keertk commented Jul 25, 2023

@brentleyjones the 6.3.1 branch has been created. Could you submit a cherry-pick PR? (We'll also need the same against 6.4.0)

@dflems dflems deleted the cc_test_env branch July 25, 2023 15:39
@keertk
Copy link
Member

keertk commented Jul 26, 2023

@dflems @brentleyjones Thank you for reporting / looking into this issue.
We're looking to improve our release process so that we can catch more issues early on in the cycle (before the final release) and would love your input. What can we do to make it easier for you to test release candidates in the future?

@meteorcloudy
Copy link
Member

@dflems Can you please confirm if this issue has been fixed in 6.3.1rc1?

@BalestraPatrick
Copy link
Member

@meteorcloudy Sorry for the delay, but yes this issue is fixed in 6.3.1.

@keertk Yes, we're very interested in this topic. We currently have an internal fork of Bazel with about 15 patches (used to be over 20 before 6.3.0 was released) on top of it (either open PRs that haven't been merged or other changes required to get our Android builds in a good/stable place). Every time we want to bump our version of Bazel we need to rebase our fork and fix any kind of conflict arising from new upstream changes. This would be much easier if we were able to reduce the number of patches we have and have them merged upstream so that we could directly test releases produced with every release candidate.

@meteorcloudy
Copy link
Member

This would be much easier if we were able to reduce the number of patches we have and have them merged upstream

Have you tried to upstream those patches? Any blocker from the Bazel side?

@BalestraPatrick
Copy link
Member

@meteorcloudy Here is our list with related PR/issue tracking it:

Patch Upstream issue / PR / commit
Add-link_library_resources-to-skip-linking-in-Androi.patch PR
Add-output_library_linked_resources-to-remove-ap_-fi.patch PR
Implement-non-transitive-R-class-via-android_non_tra.patch PR
Patch-manifest-merger-25.0.0-with-queries-support.patch Issue, PR
Add-debug_key_password-attribute-for-android_binary.patch Issue
Expose-compatibility-arguments-on-java-toolchains.patch Commit
Allow-passing-target-and-exec-constrains-to-java-rem.patch PR
Add-patch-to-enable-R8-support-on-6.3.1.patch PR
Fix-race-in-WorkerMetricsCollector.patch Issue
Pass-host_jvmopt-to-host-options-attribute.patch PR

On top of these that are available publicly, we have a few more that I need to check if possible to upstream.

@meteorcloudy
Copy link
Member

@BalestraPatrick Thanks for sharing!

Those PRs are in many different statues.

For PRs that are closed due to inactivity or waiting for user response, please try to reopen the PR, rebase to HEAD and address the reviewer comments.

For PRs waiting for review, I can try to draw some attention from:

@ahumesky @ted-xie for Android rules
@hvadehra for Java rules

@fmeum
Copy link
Collaborator

fmeum commented Aug 11, 2023

@BalestraPatrick The two PRs for making Java runtime constraints accessible may become unnecessary with #18262 (if you use them to work around Bazel bugs rather than to encode custom requirements). I asked for clarification on the configurability PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants