-
-
Notifications
You must be signed in to change notification settings - Fork 681
Expand file tree
/
Copy pathflags.bzl
More file actions
96 lines (85 loc) · 3.38 KB
/
flags.bzl
File metadata and controls
96 lines (85 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Values and helpers for pip_repository related flags.
NOTE: The transitive loads of this should be kept minimal. This avoids loading
unnecessary files when all that are needed are flag definitions.
"""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//python/private:common_labels.bzl", "labels")
load(":env_marker_info.bzl", "EnvMarkerInfo")
load(
":pep508_env.bzl",
"create_env",
"os_name_select_map",
"platform_machine_select_map",
"platform_system_select_map",
"sys_platform_select_map",
)
def define_pypi_internal_flags(name):
"""define internal PyPI flags used in PyPI hub repository by pkg_aliases.
Args:
name: not used
"""
_default_env_marker_config(
name = "_pip_env_marker_default_config",
)
def _default_env_marker_config(**kwargs):
_env_marker_config(
os_name = select(os_name_select_map),
sys_platform = select(sys_platform_select_map),
platform_machine = select(platform_machine_select_map),
platform_system = select(platform_system_select_map),
platform_release = select({
"@platforms//os:osx": "USE_OSX_VERSION_FLAG",
"//conditions:default": "",
}),
**kwargs
)
def _env_marker_config_impl(ctx):
env = create_env()
env["os_name"] = ctx.attr.os_name
env["sys_platform"] = ctx.attr.sys_platform
env["platform_machine"] = ctx.attr.platform_machine
# NOTE: Platform release for Android will be Android version:
# https://peps.python.org/pep-0738/#platform
# Similar for iOS:
# https://peps.python.org/pep-0730/#platform
platform_release = ctx.attr.platform_release
if platform_release == "USE_OSX_VERSION_FLAG":
platform_release = _get_flag(ctx.attr._pip_whl_osx_version_flag)
env["platform_release"] = platform_release
env["platform_system"] = ctx.attr.platform_system
# NOTE: We intentionally do not call set_missing_env_defaults() here because
# `env_marker_setting()` computes missing values using the toolchain.
return [EnvMarkerInfo(env = env)]
_env_marker_config = rule(
implementation = _env_marker_config_impl,
attrs = {
"os_name": attr.string(),
"platform_machine": attr.string(),
"platform_release": attr.string(),
"platform_system": attr.string(),
"sys_platform": attr.string(),
"_pip_whl_osx_version_flag": attr.label(
default = labels.PIP_WHL_OSX_VERSION,
providers = [[BuildSettingInfo], [config_common.FeatureFlagInfo]],
),
},
)
def _get_flag(t):
if config_common.FeatureFlagInfo in t:
return t[config_common.FeatureFlagInfo].value
if BuildSettingInfo in t:
return t[BuildSettingInfo].value
fail("Should not occur: {} does not have necessary providers")