diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-10 16:08:02 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-10 16:08:02 +0000 |
commit | 1d68c72e55e7b8d667ed68d0f76a2410f3d4047c (patch) | |
tree | 39314478665e3c080e3df6fe4a97609182f089b5 /examples/vndor/constant_gen/defs.bzl | |
parent | 8a99d2b6dff36f04be445f3c5e8f69874da57a04 (diff) | |
parent | ffc082fc7b3bc779251846c063bd127b941a3d52 (diff) | |
download | bazelbuild-rules_license-aml_tz5_341510010.tar.gz |
Snap for 10103804 from ffc082fc7b3bc779251846c063bd127b941a3d52 to mainline-tzdata5-releaseaml_tz5_341510070aml_tz5_341510050aml_tz5_341510010aml_tz5_341510010
Change-Id: Ieb8a9f24f0e3ef156a6c3b87a4fd089823f3df61
Diffstat (limited to 'examples/vndor/constant_gen/defs.bzl')
-rw-r--r-- | examples/vndor/constant_gen/defs.bzl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/vndor/constant_gen/defs.bzl b/examples/vndor/constant_gen/defs.bzl new file mode 100644 index 0000000..518437c --- /dev/null +++ b/examples/vndor/constant_gen/defs.bzl @@ -0,0 +1,58 @@ +# Copyright 2020 Google LLC +# +# 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 +# +# https://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. +"""A trivial rule to turn a string into a C++ constant.""" + +def _constant_gen_impl(ctx): + # Turn text into a C++ constant. + outputs = [ctx.outputs.src_out] + ctx.actions.run( + mnemonic = "GenerateConstant", + progress_message = "Generating %s" % ctx.attr.var, + outputs = outputs, + executable = ctx.executable._generator, + arguments = [ctx.outputs.src_out.path, ctx.attr.var, ctx.attr.text], + ) + return [DefaultInfo(files = depset(outputs))] + +_constant_gen = rule( + implementation = _constant_gen_impl, + attrs = { + "src_out": attr.output(mandatory = True), + "text": attr.string(mandatory = True), + "var": attr.string(mandatory = False), + "_generator": attr.label( + default = Label("@rules_license//examples/vndor/constant_gen:constant_generator"), + executable = True, + allow_files = True, + cfg = "exec", + ), + }, +) + +def constant_gen(name, text, var): + # Generate the code + _constant_gen( + name = name + "_src_", + src_out = name + "_src_.cc", + text = text, + var = var, + applicable_licenses = ["@rules_license//examples/vndor/constant_gen:license_for_emitted_code"], + ) + + # And turn it into a library we can link against + native.cc_library( + name = name, + srcs = [name + "_src_"], + applicable_licenses = ["@rules_license//examples/vndor/constant_gen:license_for_emitted_code"], + ) |