From 5913816ce6b9aa9d318e4cba7984bbc983701d9b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Thu, 21 Nov 2024 16:34:27 -0800 Subject: [PATCH] tests: make some tests compatible with Bazel 9 fix various tests relying on Bazel builtin providers existing (#2433) In Bazel 9, the builtin symbols don't exist. This fixes some tests that fail when those symbols are missing. --- tests/base_rules/base_tests.bzl | 5 ++++- tests/base_rules/py_info/py_info_tests.bzl | 2 +- tests/config_settings/transition/multi_version_tests.bzl | 6 ++++-- tests/py_runtime_pair/py_runtime_pair_tests.bzl | 3 +++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/base_rules/base_tests.bzl b/tests/base_rules/base_tests.bzl index ae298edb4f..3518e6f57a 100644 --- a/tests/base_rules/base_tests.bzl +++ b/tests/base_rules/base_tests.bzl @@ -43,7 +43,7 @@ _produces_builtin_py_info = rule( ) def _produces_py_info_impl(ctx): - return _create_py_info(ctx, BuiltinPyInfo) + return _create_py_info(ctx, PyInfo) _produces_py_info = rule( implementation = _produces_py_info_impl, @@ -86,6 +86,9 @@ def _py_info_propagation_test_impl(env, target, provider_type): info.imports().contains("custom-import") def _test_py_info_propagation_builtin(name, config): + if not BuiltinPyInfo: + rt_util.skip_test(name = name) + return _py_info_propagation_setup( name, config, diff --git a/tests/base_rules/py_info/py_info_tests.bzl b/tests/base_rules/py_info/py_info_tests.bzl index 0f46d12381..4067a59d24 100644 --- a/tests/base_rules/py_info/py_info_tests.bzl +++ b/tests/base_rules/py_info/py_info_tests.bzl @@ -39,7 +39,7 @@ def _provide_py_info_impl(ctx): providers.append(PyInfo(**kwargs)) # Handle Bazel 6 or if Bazel autoloading is enabled - if not config.enable_pystar or PyInfo != BuiltinPyInfo: + if not config.enable_pystar or (BuiltinPyInfo and PyInfo != BuiltinPyInfo): providers.append(BuiltinPyInfo(**{ k: kwargs[k] for k in ( diff --git a/tests/config_settings/transition/multi_version_tests.bzl b/tests/config_settings/transition/multi_version_tests.bzl index 367837b3fb..5805bab32d 100644 --- a/tests/config_settings/transition/multi_version_tests.bzl +++ b/tests/config_settings/transition/multi_version_tests.bzl @@ -49,7 +49,8 @@ def _test_py_test_with_transition(name): def _test_py_test_with_transition_impl(env, target): # Nothing to assert; we just want to make sure it builds env.expect.that_target(target).has_provider(PyInfo) - env.expect.that_target(target).has_provider(BuiltinPyInfo) + if BuiltinPyInfo: + env.expect.that_target(target).has_provider(BuiltinPyInfo) _tests.append(_test_py_test_with_transition) @@ -70,7 +71,8 @@ def _test_py_binary_with_transition(name): def _test_py_binary_with_transition_impl(env, target): # Nothing to assert; we just want to make sure it builds env.expect.that_target(target).has_provider(PyInfo) - env.expect.that_target(target).has_provider(BuiltinPyInfo) + if BuiltinPyInfo: + env.expect.that_target(target).has_provider(BuiltinPyInfo) _tests.append(_test_py_binary_with_transition) diff --git a/tests/py_runtime_pair/py_runtime_pair_tests.bzl b/tests/py_runtime_pair/py_runtime_pair_tests.bzl index e89e080868..f8656977e0 100644 --- a/tests/py_runtime_pair/py_runtime_pair_tests.bzl +++ b/tests/py_runtime_pair/py_runtime_pair_tests.bzl @@ -76,6 +76,9 @@ def _test_basic_impl(env, target): _tests.append(_test_basic) def _test_builtin_py_info_accepted(name): + if not BuiltinPyRuntimeInfo: + rt_util.skip_test(name = name) + return rt_util.helper_target( _provides_builtin_py_runtime_info, name = name + "_runtime",