File: utils.bzl

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 85,476 kB
  • sloc: java: 721,710; sh: 55,859; cpp: 35,359; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (59 lines) | stat: -rwxr-xr-x 2,168 bytes parent folder | download | duplicates (4)
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
# Copyright 2019 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.

"""Utilities for the @bazel_tools//tools/python package.

This file does not access any Python-rules-specific logic, and is therefore
less likely to be broken by Python-related changes. That in turn means this
file is less likely to cause bootstrapping issues.
"""

def _expand_pyversion_template_impl(ctx):
    for output, version, strict in [
        (ctx.outputs.out2, "2", "1"),
        (ctx.outputs.out3, "3", "1"),
        (ctx.outputs.out2_nonstrict, "2", "0"),
        (ctx.outputs.out3_nonstrict, "3", "0"),
    ]:
        if output:
            ctx.actions.expand_template(
                template = ctx.file.template,
                output = output,
                substitutions = {
                    "%VERSION%": version,
                    "%STRICT%": strict,
                },
                is_executable = True,
            )

expand_pyversion_template = rule(
    implementation = _expand_pyversion_template_impl,
    attrs = {
        "template": attr.label(
            allow_single_file = True,
            doc = "The input template file.",
        ),
        "out2": attr.output(doc = "The Python 2 strict wrapper."),
        "out3": attr.output(doc = "The Python 3 strict wrapper."),
        "out2_nonstrict": attr.output(
            doc = "The Python 2 non-strict wrapper.",
        ),
        "out3_nonstrict": attr.output(
            doc = "The Python 3 non-strict wrapper.",
        ),
    },
    doc = """\
Given the pywrapper template file, generates expansions for both versions of
Python and both levels of strictness.""",
)