From 77754c2cb66d7875e4a46447e3d7015846d93832 Mon Sep 17 00:00:00 2001 From: aignas <240938+aignas@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:12:52 +0900 Subject: [PATCH] fixup the generation of the config settings --- python/private/pypi/config_settings.bzl | 18 ++++++--------- .../render_pkg_aliases_test.bzl | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/python/private/pypi/config_settings.bzl b/python/private/pypi/config_settings.bzl index b08d81f06..9f3f4d4e4 100644 --- a/python/private/pypi/config_settings.bzl +++ b/python/private/pypi/config_settings.bzl @@ -131,17 +131,6 @@ def config_settings( constraint_values.append("@platforms//cpu:" + cpu) suffix += "_" + cpu - if suffix: - # Add python version + platform config settings - _dist_config_setting( - name = suffix.strip("_"), - flag_values = {}, - python_version = python_version, - is_python = is_python, - visibility = visibility, - native = native, - ) - _dist_config_settings( suffix = suffix, plat_flag_values = _plat_flag_values( @@ -159,6 +148,13 @@ def config_settings( ) def _dist_config_settings(*, suffix, plat_flag_values, **kwargs): + if kwargs.get("constraint_values"): + # Add python version + platform config settings + _dist_config_setting( + name = suffix.strip("_"), + **kwargs + ) + flag_values = {_flags.dist: ""} # First create an sdist, we will be building upon the flag values, which diff --git a/tests/pypi/render_pkg_aliases/render_pkg_aliases_test.bzl b/tests/pypi/render_pkg_aliases/render_pkg_aliases_test.bzl index f266d64f9..f5187788e 100644 --- a/tests/pypi/render_pkg_aliases/render_pkg_aliases_test.bzl +++ b/tests/pypi/render_pkg_aliases/render_pkg_aliases_test.bzl @@ -775,6 +775,19 @@ def _test_multiplatform_whl_aliases_filename_versioned(env): _tests.append(_test_multiplatform_whl_aliases_filename_versioned) +def _mock_alias(container): + return lambda name, **kwargs: container.append(name) + +def _mock_config_setting(container): + def _inner(name, flag_values = None, constraint_values = None, **_): + if flag_values or constraint_values: + container.append(name) + return + + fail("At least one of 'flag_values' or 'constraint_values' needs to be set") + + return _inner + def _test_config_settings_exist_legacy(env): aliases = [ whl_alias( @@ -787,12 +800,11 @@ def _test_config_settings_exist_legacy(env): ), ] available_config_settings = [] - mock_rule = lambda name, **kwargs: available_config_settings.append(name) config_settings( python_versions = ["3.11"], native = struct( - alias = mock_rule, - config_setting = mock_rule, + alias = _mock_alias(available_config_settings), + config_setting = _mock_config_setting(available_config_settings), ), target_platforms = [ "linux_aarch64", @@ -846,12 +858,11 @@ def _test_config_settings_exist(env): ), ] available_config_settings = [] - mock_rule = lambda name, **kwargs: available_config_settings.append(name) config_settings( python_versions = ["3.11"], native = struct( - alias = mock_rule, - config_setting = mock_rule, + alias = _mock_alias(available_config_settings), + config_setting = _mock_config_setting(available_config_settings), ), **kwargs )