| # Copyright 2022 The Pigweed Authors |
| # |
| # 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. |
| |
| import("//build_overrides/pigweed.gni") |
| |
| import("$dir_pw_third_party/emboss/emboss.gni") |
| |
| template("emboss_cc_library") { |
| assert(defined(invoker.source), "Need source arg for emboss_cc_library") |
| assert( |
| "$dir_pw_third_party_emboss" != "", |
| "\$dir_pw_third_party_emboss must be set to the path of your Emboss installation") |
| source = get_path_info(invoker.source, "file") |
| |
| # The --output-path arg to the embossc script only specifies the |
| # prefix of the path at which the generated header is placed. To this |
| # prefix, the script appends the entire path of the input Emboss source, |
| # which is provided as rebase_path(source, root_build_dir). |
| |
| # rebase_path(source, root_build_dir) will always start with a number |
| # of updirs (e.g. "../../../"). |
| |
| # In order for the compiled header path in the embossc script to resolve |
| # to $target_gen_dir as we desire, we must provide an --output-path arg |
| # that resolves to $target_gen_dir after rebase_path(source, root_build_dir) |
| # is appended to it. To achieve this, we specify output-path to be |
| # $root_gen_dir followed by a number of fake directories needed to cancel |
| # out these starting updirs. |
| compiled_header_path = "$target_gen_dir/" + source + ".h" |
| path_sep = "/" |
| elements = string_split(rebase_path(source, root_build_dir), path_sep) |
| updirs = filter_include(elements, [ ".." ]) |
| |
| fakedirs = [] |
| foreach(element, updirs) { |
| fakedirs += [ "fake" ] |
| } |
| output_path = root_gen_dir + path_sep + string_join(path_sep, fakedirs) |
| |
| action(target_name + "_header") { |
| script = "$dir_pw_third_party/emboss/embossc_runner.py" |
| args = [ |
| rebase_path("$dir_pw_third_party_emboss/embossc", root_build_dir), |
| "--generate", |
| "cc", |
| "--output-path", |
| rebase_path(output_path, root_build_dir), |
| rebase_path(source, root_build_dir), |
| ] |
| inputs = [ |
| source, |
| "$dir_pw_third_party_emboss/embossc", |
| "$dir_pw_third_party_emboss/compiler/back_end/__init__.py", |
| "$dir_pw_third_party_emboss/compiler/back_end/cpp/__init__.py", |
| "$dir_pw_third_party_emboss/compiler/back_end/cpp/emboss_codegen_cpp.py", |
| "$dir_pw_third_party_emboss/compiler/back_end/cpp/generated_code_templates", |
| "$dir_pw_third_party_emboss/compiler/back_end/cpp/header_generator.py", |
| "$dir_pw_third_party_emboss/compiler/back_end/util/__init__.py", |
| "$dir_pw_third_party_emboss/compiler/back_end/util/code_template.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/__init__.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/attribute_checker.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/attributes.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/constraints.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/dependency_checker.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/emboss_front_end.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/error_examples", |
| "$dir_pw_third_party_emboss/compiler/front_end/expression_bounds.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/glue.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/lr1.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/module_ir.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/parser.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/prelude.emb", |
| "$dir_pw_third_party_emboss/compiler/front_end/reserved_words", |
| "$dir_pw_third_party_emboss/compiler/front_end/symbol_resolver.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/synthetics.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/tokenizer.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/type_check.py", |
| "$dir_pw_third_party_emboss/compiler/front_end/write_inference.py", |
| "$dir_pw_third_party_emboss/compiler/util/error.py", |
| "$dir_pw_third_party_emboss/compiler/util/expression_parser.py", |
| "$dir_pw_third_party_emboss/compiler/util/ir_pb2.py", |
| "$dir_pw_third_party_emboss/compiler/util/ir_util.py", |
| "$dir_pw_third_party_emboss/compiler/util/name_conversion.py", |
| "$dir_pw_third_party_emboss/compiler/util/parser_types.py", |
| "$dir_pw_third_party_emboss/compiler/util/simple_memoizer.py", |
| "$dir_pw_third_party_emboss/compiler/util/traverse_ir.py", |
| ] |
| outputs = [ compiled_header_path ] |
| } |
| |
| config("emboss_config") { |
| include_dirs = [ |
| "$dir_pw_third_party_emboss", |
| root_gen_dir, |
| ] |
| } |
| |
| source_set(target_name) { |
| sources = [ compiled_header_path ] |
| deps = [ "$dir_pw_third_party/emboss:cpp_utils" ] |
| public_deps = [ ":" + target_name + "_header" ] |
| public_configs = [ ":emboss_config" ] |
| } |
| } |