1""" 2THIS IS THE EXTERNAL-ONLY VERSION OF THIS FILE. G3 HAS ITS OWN. 3 4The macro defined in this file allows us to generate .cpp files for header files. The content 5is a copy of the header file. 6 7This allows us to actually "compile" the header file, which allows tools like IWYU to properly 8analyze a header file on its own. 9 10""" 11 12def generate_cpp_files_for_headers(name, headers): 13 """Generate a filegroup containing generate .cpp files for the given header files 14 15 Args: 16 name: The name of the filegroup to hold the generated files. 17 headers: A list of header files, from this folder), that should have a .cpp file generated 18 for them that includes the header. If a header already has a .cpp file, it should 19 not be in this list. The generated files will not be checked into the Skia repo, 20 they will exist in Bazel's cache folder. 21 """ 22 rules = [] 23 for hdr in headers: 24 cpp = hdr + ".cpp" 25 native.genrule( 26 name = "gen_" + cpp, 27 srcs = headers, 28 outs = ["gen/" + cpp], 29 # Copy the header as the output .cpp file 30 # https://bazel.build/reference/be/make-variables#predefined_genrule_variables 31 # execpath returns the path to the given label relative to the Skia root. 32 cmd = "cp $(execpath :%s) $@" % hdr, 33 cmd_bat = "copy $(execpath :%s) $@" % hdr, 34 ) 35 rules.append(":gen/" + cpp) 36 37 native.filegroup( 38 name = name, 39 srcs = rules, 40 visibility = ["//tools:__pkg__"], 41 ) 42