| # SPDX-License-Identifier: BSD-3-Clause |
| # Copyright (c) 2025-2025, The OpenROAD Authors |
|
|
| "" |
|
|
| The rules wrap the tcl scripts in a extern c character array. |
| "" |
|
|
| def _tcl_encode_or_impl(ctx): |
| "" |
| "" |
| outfile_name = ctx.attr.out if ctx.attr.out else ctx.attr.name + ".cc" |
| output_file = ctx.actions.declare_file(outfile_name) |
|
|
| args = ctx.actions.args() |
| args.add(ctx.executable._encode_script) |
| args.add_all("--inputs", ctx.files.srcs) |
| args.add("--output", output_file) |
| args.add("--varname", ctx.attr.char_array_name) |
| args.add("--namespace", ctx.attr.namespace) |
|
|
| ctx.actions.run( |
| outputs = [output_file], |
| inputs = ctx.files.srcs, |
| arguments = [args], |
| tools = depset( |
| direct = [ctx.executable._encode_script], |
| transitive = [ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime.files] if ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime and ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime.files else [], |
| ), |
| executable = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime.interpreter, |
| ) |
| return [DefaultInfo(files = depset([output_file]))] |
|
|
| tcl_encode = rule( |
| implementation = _tcl_encode_or_impl, |
| attrs = { |
| "char_array_name": attr.string( |
| doc = "The name of the extern string array value in the generated file.", |
| mandatory = True, |
| ), |
| "namespace": attr.string( |
| doc = "The namespace in the C++ source file generated.", |
| mandatory = True, |
| ), |
| "out": attr.string( |
| doc = "The name of the C++ source file generated by these rules.", |
| ), |
| "srcs": attr.label_list( |
| allow_empty = False, |
| allow_files = [".tcl", ".py"], |
| doc = "Files to be wrapped.", |
| ), |
| "_encode_script": attr.label( |
| default = "//etc:file_to_string.py", |
| executable = True, |
| allow_single_file = [".py"], |
| cfg = "exec", |
| ), |
| }, |
| toolchains = ["@rules_python//python:toolchain_type"], |
| ) |
|
|