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

Set a default value for --host_crosstool_top #12093

Closed
wants to merge 4 commits into from

Conversation

katre
Copy link
Member

@katre katre commented Sep 11, 2020

Previously it was unset and defaulted to --crosstool_top in whatever configuration was being used, but that
doesn't make sense for android/apple/etc builds.

Instead we use getNormalized to set --host_crosstool_top in the target configuration.

@katre katre force-pushed the default-host-crosstool-top branch from 493fd7d to 86b4928 Compare September 11, 2020 15:51
Previously it was unset and defaulted to --crosstool_top, but that
doesn't make sense for android/apple/etc builds.

Ideally we would set --host_crosstool_top to the value of
--crosstool_top at the beginning of the build, but that isn't currently
possible.
@katre katre force-pushed the default-host-crosstool-top branch from 86b4928 to cdb1f0f Compare September 14, 2020 18:13
@katre katre changed the title [WIP] Set a default value for --host_crosstool_top Set a default value for --host_crosstool_top Sep 14, 2020
@katre katre requested a review from gregestren September 14, 2020 20:37
@katre katre marked this pull request as ready for review September 14, 2020 20:37
@katre katre requested a review from lberki as a code owner September 14, 2020 20:37
changed = true;
}
if (hostCrosstoolTop != null
&& hostCrosstoolTop.getName().equals(HOST_CROSSTOOL_TOP_NOT_YET_SET)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need a special marker value or does null still work here? As the code stands now, what case does the != null check catch?

It took me a lot of time to follow the logic from 6720ff3, which set this basic pattern. Even with the crucial comments at

* <p>It's not sufficient to use null for the default. That wouldn't handle the case of the
* top-level {@link #libcTopLabel} being null and {@link
* com.google.devtools.build.lib.rules.android.AndroidConfiguration.Options#androidLibcTopLabel}
* being non-null.
.

My recollection now is that null default doesn't work for targetLibcTopLabel because the similarly named libcTopLabel does default to null. So if you build in a default target configuration but with --android_grte_top=<something non-null>, the top-level version of getNormalized would set targetLibcTopLabel = libcTopLabel = null, and then the Android version would re-trigger because it thought null meant "never set".

host_crosstool_top isn't quite the same, is it? Because the equivalent to libcTopLabel is crosstoolTop, which itself doesn't default to null?

Whatever logic we want to use, can we document these obscure subtleties super-precisely?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, using "null" is fine for host_crosstool_top. Let me know if the current documentation is insufficient.

@gregestren
Copy link
Contributor

Also, did a particular use case catch this issue?

@katre
Copy link
Member Author

katre commented Sep 15, 2020

This was caught when I was testing the change to use toolchain transitions for Java toolchains. Specifically, building an android binary (which transitions the crosstool_top to an android-specific crosstool) stopped working, because Bazel was using the android crosstool to try and build tools.

This wasn't a problem previously because the single host transition was created before the android transition had happened, and so saw the original crosstool_top.

Copy link
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's indeed a large test! But looks good, and I think simpler than it was before.

@bazel-io bazel-io closed this in 6abf5b7 Sep 17, 2020
@katre katre deleted the default-host-crosstool-top branch September 17, 2020 17:00
Yannic pushed a commit to Yannic/bazel that referenced this pull request Oct 5, 2020
Previously it was unset and defaulted to --crosstool_top in whatever configuration was being used, but that
doesn't make sense for android/apple/etc builds.

Instead we use getNormalized to set --host_crosstool_top in the target configuration.

Closes bazelbuild#12093.

PiperOrigin-RevId: 332256211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants