| # Copyright 2021 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Generates C++ header and source files that with a set of embedded files. |
| # |
| # Example usage: |
| # |
| # Say we have the following GN rule in //camera/directory/BUILD.gn. |
| # |
| # cc_embed_data("my_embedded_target") { |
| # toc_name = "my_embedded_files" |
| # sources = [ |
| # "//camera/directory/subdirectory/file1", |
| # "//camera/directory/subdirectory/file2", |
| # ] |
| # } |
| # |
| # The above GN rule would generate two files at build time: |
| # - ${root_gen_dir}/camera/directory/my_embedded_files_toc.h |
| # - ${root_gen_dir}/camera/directory/my_embedded_files_toc.cc |
| # |
| # A static library libmy_embedded_target.a would be created at build time with |
| # the above generated files. The header file can be included in regular source |
| # files as: |
| # |
| # #include "directory/my_embedded_files_toc.h" |
| # |
| # which would provide a TOC getter function: |
| # |
| # cros::EmbeddedFileToc GetMyEmbeddedFilesToc(); |
| # |
| # The content of the files can be accessed with using the basename of the source |
| # files as keys: |
| # |
| # cros::EmbeddedFileToc toc = GetMyEmbeddedFilesToc(); |
| # base::span<const uint8_t> file1_content = toc.Get("file1"); |
| # base::span<const uint8_t> file2_content = toc.Get("file2"); |
| # |
| # |
| # Parameters: |
| # toc_name: A string used to generate the header and source file names and the |
| # TOC getter function name. If not specified, ${target_name} will be used. |
| # |
| template("cc_embed_data") { |
| forward_variables_from(invoker, [ "toc_name" ]) |
| |
| if (!defined(toc_name)) { |
| toc_name = target_name |
| } |
| |
| action("${toc_name}_gen") { |
| forward_variables_from(invoker, [ "sources" ]) |
| output_header_file = "${target_gen_dir}/${toc_name}_toc.h" |
| output_cc_file = "${target_gen_dir}/${toc_name}_toc.cc" |
| |
| script = "//camera/build/cc_embed_data.py" |
| outputs = [ |
| output_header_file, |
| output_cc_file, |
| ] |
| args = [ |
| "--source-files", |
| string_join(",", rebase_path(sources, root_build_dir)), |
| "--toc-name", |
| toc_name, |
| "--output-header-file", |
| output_header_file, |
| "--output-cc-file", |
| output_cc_file, |
| "--target-base-path", |
| root_gen_dir, |
| ] |
| } |
| |
| config("${target_name}_config") { |
| cflags = [ |
| "-I${root_gen_dir}", |
| "-I${root_gen_dir}/camera", |
| ] |
| } |
| |
| static_library("${target_name}") { |
| sources = get_target_outputs(":${toc_name}_gen") |
| public_configs = [ ":${target_name}_config" ] |
| configs += [ "//camera/build:cros_camera_common" ] |
| deps = [ ":${toc_name}_gen" ] |
| } |
| } |