xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/BUILD.bazel (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2021 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
17load("//python:py_binary.bzl", "py_binary")
18load("//python:py_library.bzl", "py_library")
19load("//python:versions.bzl", "print_toolchains_checksums")
20load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable")
21load(":sentinel.bzl", "sentinel")
22load(":stamp.bzl", "stamp_build_setting")
23
24package(
25    default_visibility = ["//:__subpackages__"],
26)
27
28licenses(["notice"])
29
30filegroup(
31    name = "distribution",
32    srcs = glob(["**"]) + [
33        "//python/private/common:distribution",
34        "//python/private/proto:distribution",
35        "//python/private/pypi:distribution",
36        "//python/private/whl_filegroup:distribution",
37        "//tools/build_defs/python/private:distribution",
38    ],
39    visibility = ["//python:__pkg__"],
40)
41
42filegroup(
43    name = "coverage_deps",
44    srcs = ["coverage_deps.bzl"],
45    visibility = ["//tools/private/update_deps:__pkg__"],
46)
47
48# Filegroup of bzl files that can be used by downstream rules for documentation generation
49filegroup(
50    name = "bzl",
51    srcs = glob(["**/*.bzl"]),
52    visibility = ["//python:__pkg__"],
53)
54
55bzl_library(
56    name = "auth_bzl",
57    srcs = ["auth.bzl"],
58    deps = [":bazel_tools_bzl"],
59)
60
61bzl_library(
62    name = "runtime_env_toolchain_bzl",
63    srcs = ["runtime_env_toolchain.bzl"],
64    deps = [
65        ":py_exec_tools_toolchain_bzl",
66        ":toolchain_types_bzl",
67        "//python:py_runtime_bzl",
68        "//python:py_runtime_pair_bzl",
69    ],
70)
71
72bzl_library(
73    name = "bzlmod_enabled_bzl",
74    srcs = ["bzlmod_enabled.bzl"],
75)
76
77bzl_library(
78    name = "config_settings_bzl",
79    srcs = ["config_settings.bzl"],
80    deps = [
81        ":semver_bzl",
82        "@bazel_skylib//lib:selects",
83        "@bazel_skylib//rules:common_settings",
84    ],
85)
86
87bzl_library(
88    name = "coverage_deps_bzl",
89    srcs = ["coverage_deps.bzl"],
90    deps = [
91        ":bazel_tools_bzl",
92        ":version_label_bzl",
93    ],
94)
95
96bzl_library(
97    name = "enum_bzl",
98    srcs = ["enum.bzl"],
99)
100
101bzl_library(
102    name = "envsubst_bzl",
103    srcs = ["envsubst.bzl"],
104)
105
106bzl_library(
107    name = "flags_bzl",
108    srcs = ["flags.bzl"],
109    deps = [
110        ":enum_bzl",
111        "@bazel_skylib//rules:common_settings",
112    ],
113)
114
115bzl_library(
116    name = "full_version_bzl",
117    srcs = ["full_version.bzl"],
118)
119
120bzl_library(
121    name = "internal_config_repo_bzl",
122    srcs = ["internal_config_repo.bzl"],
123    deps = [":bzlmod_enabled_bzl"],
124)
125
126bzl_library(
127    name = "is_standalone_interpreter_bzl",
128    srcs = ["is_standalone_interpreter.bzl"],
129    deps = [
130        ":repo_utils_bzl",
131    ],
132)
133
134bzl_library(
135    name = "normalize_name_bzl",
136    srcs = ["normalize_name.bzl"],
137)
138
139bzl_library(
140    name = "python_bzl",
141    srcs = ["python.bzl"],
142    deps = [
143        ":full_version_bzl",
144        ":python_register_toolchains_bzl",
145        ":pythons_hub_bzl",
146        ":repo_utils_bzl",
147        ":semver_bzl",
148        ":toolchains_repo_bzl",
149        ":util_bzl",
150        "@bazel_features//:features",
151    ],
152)
153
154bzl_library(
155    name = "py_repositories_bzl",
156    srcs = ["py_repositories.bzl"],
157    deps = [
158        ":bazel_tools_bzl",
159        ":internal_config_repo_bzl",
160        "//python/private/pypi:deps_bzl",
161    ],
162)
163
164bzl_library(
165    name = "python_register_toolchains_bzl",
166    srcs = ["python_register_toolchains.bzl"],
167    deps = [
168        ":auth_bzl",
169        ":bazel_tools_bzl",
170        ":bzlmod_enabled_bzl",
171        ":coverage_deps_bzl",
172        ":full_version_bzl",
173        ":internal_config_repo_bzl",
174        ":python_repository_bzl",
175        ":toolchains_repo_bzl",
176        "//python:versions_bzl",
177        "//python/private/pypi:deps_bzl",
178    ],
179)
180
181bzl_library(
182    name = "python_repository_bzl",
183    srcs = ["python_repository.bzl"],
184    deps = [
185        ":auth_bzl",
186        ":repo_utils_bzl",
187        ":text_util_bzl",
188        "//python:versions_bzl",
189    ],
190)
191
192bzl_library(
193    name = "python_register_multi_toolchains_bzl",
194    srcs = ["python_register_multi_toolchains.bzl"],
195    deps = [
196        ":python_register_toolchains_bzl",
197        ":toolchains_repo_bzl",
198        "//python:versions_bzl",
199    ],
200)
201
202bzl_library(
203    name = "pythons_hub_bzl",
204    srcs = ["pythons_hub.bzl"],
205    deps = [
206        ":py_toolchain_suite_bzl",
207    ],
208)
209
210bzl_library(
211    name = "py_cc_toolchain_macro_bzl",
212    srcs = ["py_cc_toolchain_macro.bzl"],
213    deps = [
214        ":py_cc_toolchain_rule_bzl",
215    ],
216)
217
218bzl_library(
219    name = "py_cc_toolchain_rule_bzl",
220    srcs = ["py_cc_toolchain_rule.bzl"],
221    deps = [
222        ":py_cc_toolchain_info_bzl",
223        ":rules_cc_srcs_bzl",
224        ":util_bzl",
225        "@bazel_skylib//rules:common_settings",
226    ],
227)
228
229bzl_library(
230    name = "py_cc_toolchain_info_bzl",
231    srcs = ["py_cc_toolchain_info.bzl"],
232)
233
234bzl_library(
235    name = "py_console_script_binary_bzl",
236    srcs = [
237        "py_console_script_binary.bzl",
238        "py_console_script_gen.bzl",
239    ],
240    visibility = ["//python/entry_points:__pkg__"],
241    deps = [
242        "//python:py_binary_bzl",
243    ],
244)
245
246bzl_library(
247    name = "py_exec_tools_info_bzl",
248    srcs = ["py_exec_tools_info.bzl"],
249)
250
251bzl_library(
252    name = "py_exec_tools_toolchain_bzl",
253    srcs = ["py_exec_tools_toolchain.bzl"],
254    deps = [
255        ":py_exec_tools_info_bzl",
256        ":sentinel_bzl",
257        ":toolchain_types_bzl",
258        "//python/private/common:providers_bzl",
259        "@bazel_skylib//lib:paths",
260        "@bazel_skylib//rules:common_settings",
261    ],
262)
263
264bzl_library(
265    name = "py_executable_info_bzl",
266    srcs = ["py_executable_info.bzl"],
267)
268
269bzl_library(
270    name = "py_interpreter_program_bzl",
271    srcs = ["py_interpreter_program.bzl"],
272    deps = ["@bazel_skylib//rules:common_settings"],
273)
274
275bzl_library(
276    name = "py_package_bzl",
277    srcs = ["py_package.bzl"],
278    visibility = ["//:__subpackages__"],
279)
280
281bzl_library(
282    name = "py_runtime_pair_macro_bzl",
283    srcs = ["py_runtime_pair_macro.bzl"],
284    visibility = ["//:__subpackages__"],
285    deps = [":py_runtime_pair_rule_bzl"],
286)
287
288bzl_library(
289    name = "py_runtime_pair_rule_bzl",
290    srcs = ["py_runtime_pair_rule.bzl"],
291    deps = [
292        "//python:py_runtime_bzl",
293        "//python:py_runtime_info_bzl",
294        "@bazel_skylib//rules:common_settings",
295    ],
296)
297
298bzl_library(
299    name = "py_toolchain_suite_bzl",
300    srcs = ["py_toolchain_suite.bzl"],
301    deps = [
302        ":config_settings_bzl",
303        ":text_util_bzl",
304        ":toolchain_types_bzl",
305        "@bazel_skylib//lib:selects",
306    ],
307)
308
309bzl_library(
310    name = "py_wheel_bzl",
311    srcs = ["py_wheel.bzl"],
312    visibility = ["//:__subpackages__"],
313    deps = [
314        ":py_package_bzl",
315        ":stamp_bzl",
316    ],
317)
318
319bzl_library(
320    name = "reexports_bzl",
321    srcs = ["reexports.bzl"],
322    visibility = [
323        "//:__subpackages__",
324    ],
325    deps = [":bazel_tools_bzl"],
326)
327
328bzl_library(
329    name = "register_extension_info_bzl",
330    srcs = ["register_extension_info.bzl"],
331)
332
333bzl_library(
334    name = "repo_utils_bzl",
335    srcs = ["repo_utils.bzl"],
336)
337
338bzl_library(
339    name = "semver_bzl",
340    srcs = ["semver.bzl"],
341)
342
343bzl_library(
344    name = "sentinel_bzl",
345    srcs = ["sentinel.bzl"],
346)
347
348bzl_library(
349    name = "stamp_bzl",
350    srcs = ["stamp.bzl"],
351    visibility = ["//:__subpackages__"],
352)
353
354bzl_library(
355    name = "text_util_bzl",
356    srcs = ["text_util.bzl"],
357)
358
359bzl_library(
360    name = "toolchains_repo_bzl",
361    srcs = ["toolchains_repo.bzl"],
362    deps = [
363        ":repo_utils_bzl",
364        ":text_util_bzl",
365        "//python:versions_bzl",
366    ],
367)
368
369bzl_library(
370    name = "toolchain_types_bzl",
371    srcs = ["toolchain_types.bzl"],
372)
373
374bzl_library(
375    name = "util_bzl",
376    srcs = ["util.bzl"],
377    visibility = [
378        "//:__subpackages__",
379    ],
380    deps = ["@bazel_skylib//lib:types"],
381)
382
383bzl_library(
384    name = "version_label_bzl",
385    srcs = ["version_label.bzl"],
386)
387
388# @bazel_tools can't define bzl_library itself, so we just put a wrapper around it.
389bzl_library(
390    name = "bazel_tools_bzl",
391    srcs = [
392        # This set of sources is overly broad, but it's the only public
393        # target available across Bazel versions that has all the necessary
394        # sources.
395        "@bazel_tools//tools:bzl_srcs",
396    ],
397)
398
399# @rules_cc does not offer a bzl_library target for @rules_cc//cc:defs.bzl
400bzl_library(
401    name = "rules_cc_srcs_bzl",
402    srcs = ["@rules_cc//cc:bzl_srcs"],
403    deps = [":bazel_tools_bzl"],
404)
405
406# Needed to define bzl_library targets for docgen. (We don't define the
407# bzl_library target here because it'd give our users a transitive dependency
408# on Skylib.)
409exports_files(
410    [
411        "coverage.patch",
412        "repack_whl.py",
413        "py_package.bzl",
414        "py_wheel.bzl",
415        "py_wheel_normalize_pep440.bzl",
416        "reexports.bzl",
417        "stamp.bzl",
418        "util.bzl",
419    ],
420    visibility = ["//:__subpackages__"],
421)
422
423exports_files(
424    ["python_bootstrap_template.txt"],
425    # Not actually public. Only public because it's an implicit dependency of
426    # py_runtime.
427    visibility = ["//visibility:public"],
428)
429
430filegroup(
431    name = "stage1_bootstrap_template",
432    srcs = ["stage1_bootstrap_template.sh"],
433    # Not actually public. Only public because it's an implicit dependency of
434    # py_runtime.
435    visibility = ["//visibility:public"],
436)
437
438filegroup(
439    name = "stage2_bootstrap_template",
440    srcs = ["stage2_bootstrap_template.py"],
441    # Not actually public. Only public because it's an implicit dependency of
442    # py_runtime.
443    visibility = ["//visibility:public"],
444)
445
446filegroup(
447    name = "zip_main_template",
448    srcs = ["zip_main_template.py"],
449    # Not actually public. Only public because it's an implicit dependency of
450    # py_runtime.
451    visibility = ["//visibility:public"],
452)
453
454# NOTE: Windows builds don't use this bootstrap. Instead, a native Windows
455# program locates some Python exe and runs `python.exe foo.zip` which
456# runs the __main__.py in the zip file.
457alias(
458    name = "bootstrap_template",
459    actual = select({
460        ":is_script_bootstrap_enabled": "stage1_bootstrap_template.sh",
461        "//conditions:default": "python_bootstrap_template.txt",
462    }),
463    # Not actually public. Only public because it's an implicit dependency of
464    # py_runtime.
465    visibility = ["//visibility:public"],
466)
467
468# Used to determine the use of `--stamp` in Starlark rules
469stamp_build_setting(name = "stamp")
470
471config_setting(
472    name = "is_script_bootstrap_enabled",
473    flag_values = {
474        "//python/config_settings:bootstrap_impl": "script",
475    },
476)
477
478# This should only be set by analysis tests to expose additional metadata to
479# aid testing, so a setting instead of a flag.
480bool_setting(
481    name = "visible_for_testing",
482    build_setting_default = False,
483    # This is only because it is an implicit dependency by the toolchains.
484    visibility = ["//visibility:public"],
485)
486
487print_toolchains_checksums(name = "print_toolchains_checksums")
488
489# Used for py_console_script_gen rule
490py_binary(
491    name = "py_console_script_gen_py",
492    srcs = ["py_console_script_gen.py"],
493    main = "py_console_script_gen.py",
494    visibility = [
495        "//visibility:public",
496    ],
497)
498
499py_binary(
500    name = "py_wheel_dist",
501    srcs = ["py_wheel_dist.py"],
502    visibility = ["//visibility:public"],
503)
504
505py_library(
506    name = "py_console_script_gen_lib",
507    srcs = ["py_console_script_gen.py"],
508    imports = ["../.."],
509    visibility = [
510        "//tests/entry_points:__pkg__",
511    ],
512)
513
514# The current toolchain's interpreter as an excutable, usable with
515# executable=True attributes.
516current_interpreter_executable(
517    name = "current_interpreter_executable",
518    # Not actually public. Only public because it's an implicit dependency of
519    # py_exec_tools_toolchain.
520    visibility = ["//visibility:public"],
521)
522
523sentinel(
524    name = "sentinel",
525)
526