From 3738ce05a70cf97fc73a07b158a1726f61aed28b Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 16 Nov 2022 14:20:23 -0800 Subject: Add support for a backdoor driver option that enables emitting header usage information in JSON to a file Each line in the file is a JSON object that has the name of the main source file followed by the list of system header files included directly or indirectly from that file. For example: {"source":"/tmp/foo.c", "includes":["/usr/include/stdio.h", "/usr/include/stdlib.h"]} To reduce the amount of data written to the file, only the system headers that are directly included from a non-system header file are recorded. In order to emit the header information in JSON, it is necessary to set the following environment variables: CC_PRINT_HEADERS_FORMAT=json CC_PRINT_HEADERS_FILTERING=only-direct-system The following combination is equivalent to setting CC_PRINT_HEADERS=1: CC_PRINT_HEADERS_FORMAT=textual CC_PRINT_HEADERS_FILTERING=none Differential Revision: https://reviews.llvm.org/D137996 --- clang/lib/Frontend/CompilerInvocation.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 5a8e921..06a8815 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2151,6 +2151,16 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, Opts.ExtraDeps.emplace_back(std::string(Val), EDK_ModuleFile); } + // Check for invalid combinations of header-include-format + // and header-include-filtering. + if ((Opts.HeaderIncludeFormat == HIFMT_Textual && + Opts.HeaderIncludeFiltering != HIFIL_None) || + (Opts.HeaderIncludeFormat == HIFMT_JSON && + Opts.HeaderIncludeFiltering != HIFIL_Only_Direct_System)) + Diags.Report(diag::err_drv_print_header_env_var_combination_cc1) + << Args.getLastArg(OPT_header_include_format_EQ)->getValue() + << Args.getLastArg(OPT_header_include_filtering_EQ)->getValue(); + return Diags.getNumErrors() == NumErrorsBefore; } -- cgit v1.1