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

Add new ToolchainTypeInfo provider to track toolchain type information. #6235

Closed
wants to merge 6 commits into from

Conversation

katre
Copy link
Member

@katre katre commented Sep 25, 2018

Will eventually be part of checking the toolchain provider types, as
part of #6015.

Change-Id: I74e9372fb19d1f78c00a340c484c3c4d4b2f2ab1

Will eventually be part of checking the toolchain provider types, as
part of bazelbuild#6015.

Change-Id: I74e9372fb19d1f78c00a340c484c3c4d4b2f2ab1
@katre katre requested a review from lberki as a code owner September 25, 2018 16:29
katre added a commit to katre/bazel that referenced this pull request Sep 25, 2018
This will be required after
bazelbuild#6235 requires actual
dependencies on toolchain_type targets.

Part of the work on bazelbuild#6015.

Change-Id: I21e5399dc0c43bb7b4d42e1f1bd5b9a1c820075e
@iirina iirina added the team-Configurability platforms, toolchains, cquery, select(), config transitions label Sep 26, 2018
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.

Forgive my ignorance, but this is motivated by C++ toolchain resolution, and the desire to not have to litter awkward checking throughout the code base, right?

What's the current state of Starlark-defined C++ toolchain definitions and the rules that consume them? i..e. which rule definitions for C++ would this logic use to do the checking?

@@ -0,0 +1,70 @@
package com.google.devtools.build.lib.analysis.platform;
Copy link
Contributor

Choose a reason for hiding this comment

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

File header comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(toolchain_type) -->
The type of the toolchain, which should be the label of a toolchain_type() target.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr(TOOLCHAIN_TYPE_ATTR, BuildType.NODEP_LABEL)
attr(TOOLCHAIN_TYPE_ATTR, BuildType.LABEL)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the NODEP_LABEL to LABEL change signify?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is so that the toolchain_type() rule referred to by the label gets analyzed and thus the ToolchainTypeInfo gets created.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exactly. There's now an actual dependency on the toolchain type, so:
a) it must exist, and
b) the new provider can now be used.

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;

/** Info object representing data about a specific platform. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, fixed it.

public static final NativeProvider<ToolchainTypeInfo> PROVIDER =
new NativeProvider<ToolchainTypeInfo>(ToolchainTypeInfo.class, SKYLARK_NAME) {};

private final Label typeLabel;
Copy link
Contributor

Choose a reason for hiding this comment

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

What other information is expected to be here other than the label?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a branch in progress that adds a (string-valued) provider_id attribute, which can then be checked against the actual provider during toolchain resolution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood! I don't know what your plans are and thus I can't say anything wise about them, but I think this change by itself is a net win, since I consider nodep labels a hack (they are confusing because label attributes usually mean a dependency).

I'm somewhat worried about the "string-valued provider_id attribute" part, but we can discuss that in a separate thread.


/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(toolchain_type) -->
The type of the toolchain, which should be the label of a toolchain_type() target.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr(TOOLCHAIN_TYPE_ATTR, BuildType.NODEP_LABEL)
attr(TOOLCHAIN_TYPE_ATTR, BuildType.LABEL)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is so that the toolchain_type() rule referred to by the label gets analyzed and thus the ToolchainTypeInfo gets created.

bazel-io pushed a commit that referenced this pull request Sep 27, 2018
This will be required after
#6235 requires actual
dependencies on toolchain_type targets.

Part of the work on #6015.

Change-Id: I21e5399dc0c43bb7b4d42e1f1bd5b9a1c820075e

Closes #6239.

Change-Id: I9d784437e8838875b3f8618e53752ba1f635f31e
PiperOrigin-RevId: 214768353
Change-Id: Iec98478ea0051440129d9e19efbf6c3aff68d3da
Change-Id: I6022b2f8ace0b41599753584823a3fda82b85370
@katre
Copy link
Member Author

katre commented Sep 27, 2018

Correct, this came about from a conversation @lberki and I had about type checking C++ toolchain providers. The same issues will also come up for Java toolchain providers.

While the C++ crosstool is moving into Starlark, I'm not aware of any long-term plans to re-write the CppToolchainProvider as Starlark code, as it is very heavily used in Bazel internals. Given that, we still need the check that a target that requires a c++ toolchain gets an actual CppToolchainProvider, in order to avoid the current potential class cast errors.

Change-Id: Ic1d98c1cbeb3c40a3d3a81c03ccfb6c8f0a87b86
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.

Thanks for the explanation. I defer to @lberki for further comments on this change.

As to the larger issue, the exact API for (2) in #6015 still remains TBD?

@katre
Copy link
Member Author

katre commented Sep 27, 2018

For the larger check, I need to test what exactly is available to validate on. Every toolchain has to be a subclass of ToolchainInfo, so that is the actual provider type for them all. I may need to do class name matching for native providers instead, or add a "type" to the ToolchainInfo for comparison. Still considering.

@katre
Copy link
Member Author

katre commented Oct 2, 2018

Yes, still working out the best way to do the actual check on the provider type. It turns out to be fairly tricky. But I think this change is still worthwhile even without the provider type checking.

Change-Id: I53d6a0d41c05029b98dddac4c8b8a7f60aa218d6
Change-Id: I80592a3e130dea99bee9ccecfaaf2b64b73bc80a
@bazel-io bazel-io closed this in 2348893 Oct 4, 2018
bazel-io pushed a commit that referenced this pull request Oct 5, 2018
*** Reason for rollback ***

This change is causing many rules_* jobs to fail at HEAD:

https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/480

Filed issue: #6311

*** Original change description ***

Add new ToolchainTypeInfo provider to track toolchain type information.

Will eventually be part of checking the toolchain provider types, as
part of #6015.

Closes #6235.

PiperOrigin-RevId: 215911302
@katre katre deleted the ttp-01-toolchain-type-provider branch October 23, 2018 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants