|
| 1 | +# Copyright 2021 The TensorStore Authors |
| 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 | +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") |
| 16 | + |
| 17 | +# TODO: Consider using the bazel --stamp flag: |
| 18 | +# |
| 19 | +# https://bazel.build/docs/user-manual#workspace-status-command |
| 20 | +# --workspace_status_command program would generate key value pairs, |
| 21 | +# which are stored in https://bazel.build/rules/lib/builtins/ctx#version_file |
| 22 | +# |
| 23 | +# Also consider exposing the version as a python __version__.py file. |
| 24 | + |
| 25 | +_TEMPLATE = """ |
| 26 | +// version is auto-generated by tensorstore build. |
| 27 | +
|
| 28 | +#ifndef TENSORSTORE_VERSION |
| 29 | +#define TENSORSTORE_VERSION "{version}" |
| 30 | +#endif // TENSORSTORE_VERSION |
| 31 | +
|
| 32 | +""" |
| 33 | + |
| 34 | +def _tag_release_impl(ctx): |
| 35 | + ctx.actions.write( |
| 36 | + output = ctx.outputs.out, |
| 37 | + content = _TEMPLATE.format(version = ctx.attr.label[BuildSettingInfo].value), |
| 38 | + is_executable = False, |
| 39 | + ) |
| 40 | + return [DefaultInfo(files = depset([ctx.outputs.out]))] |
| 41 | + |
| 42 | +tag_release = rule( |
| 43 | + implementation = _tag_release_impl, |
| 44 | + output_to_genfiles = True, |
| 45 | + attrs = { |
| 46 | + "out": attr.output(mandatory = True, doc = "The output file to write the version to."), |
| 47 | + "label": attr.label(mandatory = True, doc = "The label to tag the release with."), |
| 48 | + }, |
| 49 | +) |
0 commit comments