blob: 7422608c7236967afec0617a1728113cf48f6c15 [file] [log] [blame]
brandjon22994452019-03-26 13:37:31 -07001# Copyright 2019 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
15"""Utilities for the @bazel_tools//tools/python package.
16
17This file does not access any Python-rules-specific logic, and is therefore
18less likely to be broken by Python-related changes. That in turn means this
19file is less likely to cause bootstrapping issues.
20"""
21
22def _expand_pyversion_template_impl(ctx):
brandjon052167e2019-06-04 16:04:06 -070023 for output, version, strict in [
24 (ctx.outputs.out2, "2", "1"),
25 (ctx.outputs.out3, "3", "1"),
26 (ctx.outputs.out2_nonstrict, "2", "0"),
27 (ctx.outputs.out3_nonstrict, "3", "0"),
28 ]:
29 if output:
30 ctx.actions.expand_template(
31 template = ctx.file.template,
32 output = output,
33 substitutions = {
34 "%VERSION%": version,
35 "%STRICT%": strict,
36 },
37 is_executable = True,
38 )
brandjon22994452019-03-26 13:37:31 -070039
40expand_pyversion_template = rule(
41 implementation = _expand_pyversion_template_impl,
42 attrs = {
43 "template": attr.label(
44 allow_single_file = True,
45 doc = "The input template file.",
46 ),
brandjon052167e2019-06-04 16:04:06 -070047 "out2": attr.output(doc = "The Python 2 strict wrapper."),
48 "out3": attr.output(doc = "The Python 3 strict wrapper."),
49 "out2_nonstrict": attr.output(
50 doc = "The Python 2 non-strict wrapper.",
51 ),
52 "out3_nonstrict": attr.output(
53 doc = "The Python 3 non-strict wrapper.",
54 ),
brandjon22994452019-03-26 13:37:31 -070055 },
56 doc = """\
brandjon052167e2019-06-04 16:04:06 -070057Given the pywrapper template file, generates expansions for both versions of
58Python and both levels of strictness.""",
brandjon22994452019-03-26 13:37:31 -070059)