def _update_import_includes(args, spec, header_file_name):
|
# type: (CompilerArgs, syntax.IDLSpec, unicode) -> None
|
"""Update the list of imports with a list of include files for each import with structs."""
|
# This function is fragile:
|
# In order to try to generate headers with an "include what you use" set of headers, the IDL
|
# compiler needs to generate include statements to headers for imported files with structs. The
|
# problem is that the IDL compiler needs to make the following assumptions:
|
# 1. The layout of build vs source directory.
|
# 2. The file naming suffix rules for all IDL invocations are consistent.
|
if not spec.imports:
|
return
|
|
if args.output_base_dir:
|
base_include_h_file_name = os.path.relpath(
|
os.path.normpath(header_file_name), os.path.normpath(args.output_base_dir))
|
else:
|
base_include_h_file_name = os.path.abspath(header_file_name)
|
|
# Normalize to POSIX style for consistency across Windows and POSIX.
|
base_include_h_file_name = base_include_h_file_name.replace("\\", "/")
|
|
# Modify the includes list of the root_doc to include all of its direct imports
|
if not spec.globals:
|
spec.globals = syntax.Global(args.input_file, -1, -1)
|
|
first_dir = base_include_h_file_name.split('/')[0]
|
|
for resolved_file_name in spec.imports.resolved_imports:
|
# Guess: the file naming rules are consistent across IDL invocations
|
include_h_file_name = resolved_file_name.split('.')[0] + args.output_suffix + ".h"
|