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

incompatible_disallow_struct_provider_syntax: disallow rule implementation functions returning struct #7347

Open
c-parsons opened this issue Feb 4, 2019 · 26 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: process

Comments

@c-parsons
Copy link
Contributor

Flag: --incompatible_disallow_struct_provider_syntax
Available since: 0.23 (February 2019 release)

Motivation
The motivation for this change is described in #6241

Migration
Rule implementation functions should return a collection of provider instances instead of a struct

# Before
def _rule_impl(ctx):
    return struct(
        foo_info = struct(foo =foo’),
        bar_info = struct(bar =bar’),
    )

my_rule = rule(implementation = _rule_impl)

# After
FooInfo = provider()
BarInfo = provider()
def _rule_impl(ctx):
    return [FooInfo(foo =foo’), BarInfo(bar =bar’)]

my_rule = rule(implementation = _rule_impl)

One corner case to note is specifying files for coverage. This used
to be done with the hardcoded struct field instrumented_files, but should
now be done by using coverage_common.instrumented_files_info(). For example:

# Before
def rule_impl(ctx):
    return struct(
        instrumented_files = struct(
            source_attributes = ["srcs"],
            dependency_attributes = ["deps", "image"],
            extensions = ["js"],
        ),
    )

my_rule = rule(implementation = _rule_impl)

# After
def rule_impl(ctx):
    my_coverage_info = coverage_common.instrumented_files_info(
        ctx,
        source_attributes = ["srcs"],
        dependency_attributes = ["deps", "image"],
        extensions = ["js"])
    return [my_coverage_info]

my_rule = rule(implementation = _rule_impl)
@c-parsons c-parsons added incompatible-change Incompatible/breaking change breaking-change-0.24 labels Feb 4, 2019
@c-parsons c-parsons self-assigned this Feb 4, 2019
bazel-io pushed a commit that referenced this issue Feb 5, 2019
Such functions should return a list of providers instead.
This change represents a deprecation of the "old" syntax.

This is an incompatible change attached to new flag --incompatible_disallow_struct_provider_syntax.

See https://docs.google.com/document/d/14A9HK8Jn2jErMayLEE3nrNJIxNfZWN_slFbhgtS6-aM for details.

Migration tracker: #7347
Progress toward #6241

RELNOTES: New incompatible flag --incompatible_disallow_struct_provider_syntax removes the ability for rule implementation functions to return struct. Such functions should return a list of providers instead. Migration tracking: #7347
PiperOrigin-RevId: 232547460
keith added a commit to keith/rules_swift that referenced this issue Feb 26, 2019
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0
keith added a commit to keith/rules_apple that referenced this issue Feb 26, 2019
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0
bazel-io pushed a commit that referenced this issue Feb 26, 2019
Baseline: 441fd75

Cherry picks:

   + 6ca7763:
     Fix a typo
   + 2310b1c:
     Ignore SIGCHLD in test setup script
   + f9eb1b5:
     Complete channel initialization in the event loop

Incompatible changes:

  - //src:bazel uses the minimal embedded JDK, if you want to
    avoid the extra steps of minimizing the JDK, use //src:bazel-dev
    instead.
  - //src:bazel uses the minimal embedded JDK, if you want to
    avoid the extra steps of building bazel with the minimized JDK,
    use //src:bazel-dev
    instead.
  - The default value of --host_platform and --platforms will be
      changed to not be dependent on the configuration. This means
    that setting
      --cpu or --host_cpu will not affect the target or host platform.
  - Toolchain resolution for cc rules is now enabled via an
    incompatible flag, --incompatible_enable_cc_toolchain_resolution.
    The previous
    flag, --enabled_toolchain_types, is deprecated and will be
    removed.
  - java_(mutable_|)proto_library: removed strict_deps attribute.
  - Python rules will soon reject the legacy "py" struct provider
    (preview by enabling --incompatible_disallow_legacy_py_provider).
    Upgrade rules to use PyInfo instead. See
    [#7298](#7298).
  - java_(mutable_|)proto_library: removed strict_deps attribute.
  - Two changes to native Python rules: 1) `default_python_version`
    and `--force_python` are deprecated; use `python_version` and
    `--python_version` respectively instead. You can preview the
    removal of the deprecated names with
    --incompatible_remove_old_python_version_api. See
    [#7308](#7308). 2) The
    version flag will no longer override the declared version of a
    `py_binary` or `py_test` target. You can preview this new
    behavior with --incompatible_allow_python_version_transitions.
    See [#7307](#7307).

Important changes:

  - There is a new flag available
    `--experimental_java_common_create_provider_enabled_packages`
    that acts as a whitelist for usages of
    `java_common.create_provider`. The constructor will be deprecated
    in Bazel 0.23.
  - [#7024] Allow chaining of the same function type in aquery.
  - Introduces --local_{ram,cpu}_resources, which will take the place
    of --local_resources.
  - [#6930] Add documentation for the aquery command.
  - Incompatible flag `--incompatible_dont_emit_static_libgcc` has
    been flipped (#6825)
  - Incompatible flag `--incompatible_linkopts_in_user_link_flags`
    has been flipped (#6826)
  - Flag --incompatible_range_type is removed.
  - Flag --incompatible_disallow_slash_operator is removed.
  - Flag --incompatible_disallow_conflicting_providers is removed.
  - `--incompatible_disallow_data_transition` is now enabled by
    default
  - Allow inclusion of param files in aquery output
  - [#6985] Add test to verify aquery's behavior for Cpp action
    templates.
  - --incompatible_require_feature_configuration_for_pic was flipped
    (#7007).
  - Also ignore module-info.class in multi-version Jars
  - objc_framework has been deleted. Please refer to
    apple_dynamic_framework_import and apple_static_framework_import
    rules available in
    [rules_apple](https://github.com/bazelbuild/rules_apple/blob/maste
    r/doc/rules-general.md)
  - --test_sharding_strategy=experimental_heuristic is no more
  - objc_bundle_library has been removed. Please migrate to
    rules_apple's
    [apple_resource_bundle](https://github.com/bazelbuild/rules_apple/
    blob/master/doc/rules-resources.md#apple_resource_bundle).
  - You can now use the attribute `aapt_version` or the flag
    `--android_aapt` to pick the aapt version for android_local_test
    tests
  - In --keep_going mode, Bazel now correctly returns a non-zero exit
    code when encountering a package loading error during target
    pattern parsing of patterns like "//foo:all" and "//foo/...".
  - The default value for --incompatible_strict_action_env has been
    flipped to 'false' again, as we discovered breakages for local
    execution users. We'll need some more time to figure out the best
    way to make this work for local and remote execution. Follow
    #7026 for more details.
  - Locally-executed spawns tagged "no-cache" no longer upload their
    outputs to the remote cache.
  - Introduces --host_compiler flag to allow setting a compiler for
    host compilation when --host_crosstool_top is specified.
  - --incompatible_expand_directories is enabled by default
  - [aquery] Handle the case of aspect-on-aspect.
  - Fixed a longstanding bug in the http remote cache where the value
    passed to
    --remote_timeout would be interpreted as milliseconds instead of
    seconds.
  - Enable --incompatible_use_jdk10_as_host_javabase by default, see
    #6661
  - Add --incompatible_use_jdk11_as_host_javabase: makes JDK 11 the
    default --host_javabase for remote jdk
    (#7219)
  - Highlight TreeArtifact in aquery text output.
  - Locally-executed spawns tagged "no-cache" no longer upload their
    outputs to the remote cache.
  - java_common APIs now accept JavaToolchainInfo and JavaRuntimeInfo
    instead of configured targets for java_toolchain and java_runtime
  - cc_common.create_cc_toolchain_config_info is stable and available
    for production use
  - incompatible_use_toolchain_providers_in_java_common: pass
    JavaToolchainInfo and JavaRuntimeInfo providers to java_common
    APIs instead of configured targets
    (#7186)
  - --incompatible_strict_argument_ordering is enabled by default.
  - Bazel now supports reading cache hits from a repository cache,
    even if it doesn't have write access to the cache.
  - Adding arm64e to OSX CROSSTOOL.
  - Ignore package-level licenses on config_setting.
  - Add an optional output_source_jar parameter to java_common.compile
  - --incompatible_disable_objc_provider_resources is now enabled by
    default. This disables ObjcProvider's fields related to resource
    processing.
  - Explicitly set https.protocols and exclude TLSv1.3.
  - Bazel now validates that JAVA_HOME points to a valid JDK and
    falls back to auto-detection by looking up the path of `javac`.
  - Upgrade the embedded JDK version to 11.0.2.
  - Added --incompatible_disable_crosstool_file
    (#7320)
  - --incompatible_disable_objc_provider_resources is now enabled by
    default. This disables ObjcProvider's fields related to resource
    processing.
  - --incompatible_disable_tools_defaults_package has been flipped.
  - For tests that do not generate a test.xml, Bazel now uses a
    separate action to generate one; this results in minor
    differences in the generated test.xml, and makes the generation
    more reliable overall.
  - incompatible_generate_javacommon_source_jar: java_common.compile
    now always generates a source jar, see
    #5824.
  - New incompatible flag
    --incompatible_disallow_struct_provider_syntax removes the
    ability for rule implementation functions to return struct. Such
    functions should return a list of providers instead. Migration
    tracking: #7347

This release contains contributions from many people at Google, as well as Benjamin Peterson, Ed Schouten, erenon, George Gensure, Greg Estren, Igal Tabachnik, Ittai Zeidman, Jannis Andrija Schnitzer, John Millikin, Keith Smiley, Kelly Campbell, Max Vorobev, nicolov, Robin Nabel.
allevato pushed a commit to bazelbuild/rules_swift that referenced this issue Feb 26, 2019
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0

Closes #145.

RELNOTES: None.
PiperOrigin-RevId: 235755436
keith added a commit to keith/rules_apple that referenced this issue Feb 26, 2019
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0
allevato pushed a commit to bazelbuild/rules_swift that referenced this issue Feb 26, 2019
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0

Closes #145.

RELNOTES: None.
PiperOrigin-RevId: 235755436
@davido
Copy link
Contributor

davido commented Mar 3, 2019

Gerrit Code Review seems to be affected:

INFO: Build options --incompatible_allow_python_version_transitions, --incompatible_disable_crosstool_file, --incompatible_disable_expand_if_all_available_in_flag_set, and 2 more have changed, discarding analysis cache.
ERROR: /home/davido/projects/gerrit2/lib/js/BUILD:24:1: in _bower_component rule //lib/js:webcomponentsjs:

/home/davido/projects/gerrit2/tools/bzl/js.bzl:149:12: Returning a struct from a rule implementation function is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disallow_struct_provider_syntax=false . See https://github.com/bazelbuild/bazel/issues/7347 for details.
ERROR: Analysis of target '//:release' failed; build aborted: Analysis of target '//lib/js:webcomponentsjs' failed; build aborted
INFO: Elapsed time: 1.166s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (44 packages loaded, 876 targets configured)

@davido
Copy link
Contributor

davido commented Mar 20, 2019

Now, it seems that Bazel at HEAD (e81d9c9) itself affected:

$ b10 build --all_incompatible_changes :gerrit
INFO: Invocation ID: c81793a2-5e7f-4f02-9b26-a84442e09a4c
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:98:7: 
Current Bazel is not a release version, cannot check for compatibility.
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:99:7: Make sure that you are running at least Bazel 0.22.0.
INFO: Build options --incompatible_allow_python_version_transitions, --incompatible_auto_configure_host_platform, --incompatible_cc_coverage, and 22 more have changed, discarding analysis cache.
ERROR: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_tools/tools/jdk/BUILD:59:1: in java_toolchain_alias rule @bazel_tools//tools/jdk:current_java_toolchain: 


/home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_tools/tools/jdk/java_toolchain_alias.bzl:85:12: Returning a struct from a rule implementation function is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disallow_struct_provider_syntax=false . See https://github.com/bazelbuild/bazel/issues/7347 for details.
ERROR: Analysis of target '//:gerrit' failed; build aborted: Analysis of target '@bazel_tools//tools/jdk:current_java_toolchain' failed; build aborted
INFO: Elapsed time: 1.565s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (80 packages loaded, 588 targets configured)

cloud-robotics-github-robot pushed a commit to googlecloudrobotics/core that referenced this issue Mar 27, 2019
bazelbuild/bazel#7347

The `return struct(...)` form will be removed in a future Bazel version.
This doesn't completely fix the build, since (at least) rules_go
upstream has not been migrated yet.

Change-Id: I527772227c76f74d8b8abb48fbcc76f7890e7d25
GitOrigin-RevId: b416665
@davido
Copy link
Contributor

davido commented Mar 28, 2019

@c-parsons @laurentlb Can you clarify, why Bazel itself is not forward compatible and what is the right course of action here? How I supposed to fix Gerrit Code Review project and its transitive dependency projects, e.g. rules_closure, if Bazel itself is not compatible and build is aborting in Bazel code even before the breakages in Gerrit and rules_closure are reported?

  $ bazel version
  Build label: 0.24.0
  $ bazel build --incompatible_disallow_struct_provider_syntax :headless
INFO: Invocation ID: e51dfceb-c055-4970-8485-e689c8dca66c
ERROR: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_tools/tools/jdk/BUILD:54:1: in java_toolchain_alias rule @bazel_tools//tools/jdk:current_java_toolchain: 


/home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_tools/tools/jdk/java_toolchain_alias.bzl:85:12: Returning a struct from a rule implementation function is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disallow_struct_provider_syntax=false . See https://github.com/bazelbuild/bazel/issues/7347 for details.
ERROR: Analysis of target '//:headless' failed; build aborted: Analysis of target '@bazel_tools//tools/jdk:current_java_toolchain' failed; build aborted
INFO: Elapsed time: 0.156s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

Even on Bazel@HEAD (acc72bb) the relevant piece of the code is:

def _java_toolchain_alias(ctx):
    """An experimental implementation of java_toolchain_alias using toolchain resolution."""
    if java_common.is_java_toolchain_resolution_enabled_do_not_use(ctx = ctx):
        toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"]
    else:
        toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo]
    return struct(
        providers = [toolchain],
        # Use the legacy provider syntax for compatibility with the native rules.
        java_toolchain = toolchain,
    )

@laurentlb
Copy link
Contributor

It seems like this is not ready for migration. Removing the migration labels.

This change is breaking all downstream projects (https://buildkite.com/bazel/bazelisk-plus-incompatible-flags/builds/59), Bazel itself is not compatible.

@limdor
Copy link
Contributor

limdor commented Mar 30, 2020

What is the status of this topic? This is an issue with bazel at HEAD. If someone wants to use --all_incompatible_changes to be able to do migrations, then --incompatible_disallow_struct_provider_syntax gets also triggered and is failing to build because of the line in java_toolchain_alias. This can be workaround with --incompatible_disallow_struct_provider_syntax=false but it is not really a nice option.

The other option in case that this takes time to be fixed would be to remove --incompatible_disallow_struct_provider_syntax from --all_incompatible_changes, would that be an option?

@c-parsons
Copy link
Contributor Author

Hello,

Apologies that this issue fell off my radar.

Re: Coverage:
https://docs.bazel.build/versions/master/skylark/rules.html#code-coverage-instrumentation
You should now be able to use this for modern coverage-related provider.

Re: java_toolchain_alias.bzl: I'll look into getting this fixed.

Re: incompatible flag, and --all_incompatible_changes, I would suggest you use the workaround you've mentioned, --all_incompatible_changes --incompatible_disallow_struct_provider_syntax=false, if you are blocked on the latter flag. It's not ideal, but we generally don't have infrastructure for removing --incompatible_ flags from the all_incompatible_changes set. The far better approach here would be to resolve any blockers of incompatible_disallow_struct_provider_syntax.

alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 17, 2020
…o() provider.

This is the beginning of removing the legacy providers, per bazelbuild/bazel#7347

See https://docs.bazel.build/versions/master/skylark/rules.html#migrating-from-legacy-providers:
"
The fields files, runfiles, data_runfiles, default_runfiles, and executable correspond to the same-named fields of DefaultInfo. It is not allowed to specify any of these fields while also returning a DefaultInfo modern provider.
"

PiperOrigin-RevId: 264941716
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 17, 2020
This is the beginning of removing the legacy providers, per bazelbuild/bazel#7347

See https://docs.bazel.build/versions/master/skylark/rules.html#migrating-from-legacy-providers:
"The field output_groups takes a struct value and corresponds to an
OutputGroupInfo."

PiperOrigin-RevId: 265162279
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 17, 2020
…gacy provider

This is the part of removing the legacy providers, per bazelbuild/bazel#7347

Depends on bazelbuild#1052

PiperOrigin-RevId: 265167694
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 18, 2020
…o() provider.

This is the beginning of removing the legacy providers, per bazelbuild/bazel#7347

See https://docs.bazel.build/versions/master/skylark/rules.html#migrating-from-legacy-providers:
"
The fields files, runfiles, data_runfiles, default_runfiles, and executable correspond to the same-named fields of DefaultInfo. It is not allowed to specify any of these fields while also returning a DefaultInfo modern provider.
"

PiperOrigin-RevId: 264941716
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 18, 2020
This is the beginning of removing the legacy providers, per bazelbuild/bazel#7347

See https://docs.bazel.build/versions/master/skylark/rules.html#migrating-from-legacy-providers:
"The field output_groups takes a struct value and corresponds to an
OutputGroupInfo."

PiperOrigin-RevId: 265162279
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Oct 18, 2020
…gacy provider

This is the part of removing the legacy providers, per bazelbuild/bazel#7347

Depends on bazelbuild#1052

PiperOrigin-RevId: 265167694
@brandjon brandjon added team-Build-Language P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed team-Starlark labels Feb 17, 2021
@brandjon
Copy link
Member

brandjon commented Feb 17, 2021

Do I understand correctly that flipping this flag is sufficient to ensure that legacy struct providers are not used in a build? I.e., that you can't return "mystruct_provider" = struct(...) from a rule implementation function, and because of this, you also can't access mydep.mystruct_provider?

Presumably there might be some native rules that still have struct providers, and those would all have to be eliminated before we could delete the legacy code path for creating and reading structs in transitive info collections.

I'd love to be able to delete legacy structs altogether this year.

@brandjon
Copy link
Member

Do I understand correctly that flipping this flag is sufficient to ensure that legacy struct providers are not used in a build?

Nm, just saw that #9014 is also needed.

@brandjon brandjon added untriaged team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Build-Language labels Nov 4, 2022
@comius comius self-assigned this Feb 13, 2023
@comius comius added P2 We'll consider working on this in future. (Assignee optional) and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) incompatible-change Incompatible/breaking change untriaged labels Feb 13, 2023
comius added a commit to comius/grpc that referenced this issue Feb 13, 2023
ananda1066 pushed a commit to grpc/grpc that referenced this issue Feb 15, 2023
Struct providers were deprecated
bazelbuild/bazel#7347

release notes: no
XuanWang-Amos pushed a commit to XuanWang-Amos/grpc that referenced this issue May 1, 2023
Struct providers were deprecated
bazelbuild/bazel#7347

release notes: no
wanlin31 pushed a commit to grpc/grpc that referenced this issue May 18, 2023
Struct providers were deprecated
bazelbuild/bazel#7347

release notes: no
tymurmustafaiev pushed a commit to tymurmustafaiev/rules_swift that referenced this issue Jul 19, 2023
This fixes an incompatible change detailed here: bazelbuild/bazel#7347

This relies on bazel 0.23.0

Closes bazelbuild#145.

RELNOTES: None.
PiperOrigin-RevId: 235755436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: process
Projects
None yet
Development

No branches or pull requests

10 participants