• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""TensorFlow Lite Support Library Helper Rules for iOS"""
2
3# When the static framework is built with bazel, the all header files are moved
4# to the "Headers" directory with no header path prefixes. This auxiliary rule
5# is used for stripping the path prefix to the C API header files included by
6# other C API header files.
7def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""):
8    """Create modified header files with the common.h include path stripped out.
9
10    Args:
11      name: The name to be used as a prefix to the generated genrules.
12      hdr_labels: List of header labels to strip out the include path. Each
13          label must end with a colon followed by the header file name.
14      prefix: Optional prefix path to prepend to the header inclusion path.
15    """
16
17    for hdr_label in hdr_labels:
18        hdr_filename = hdr_label.split(":")[-1]
19        hdr_basename = hdr_filename.split(".")[0]
20
21        native.genrule(
22            name = "{}_{}".format(name, hdr_basename),
23            srcs = [hdr_label],
24            outs = [hdr_filename],
25            cmd = """
26            sed 's|#include ".*/\\([^/]\\{{1,\\}}\\.h\\)"|#include "{}\\1"|'\
27            "$(location {})"\
28            > "$@"
29            """.format(prefix, hdr_label),
30        )
31