Add support for a backdoor driver option that enables emitting header
authorAkira Hatanaka <ahatanaka@apple.com>
Wed, 16 Nov 2022 22:20:23 +0000 (14:20 -0800)
committerAkira Hatanaka <ahatanaka@apple.com>
Wed, 7 Dec 2022 23:30:19 +0000 (15:30 -0800)
commit3738ce05a70cf97fc73a07b158a1726f61aed28b
tree9eb6899ba3d2924b69b037af42b3ed84453a3203
parent49e75ebd854dee1fcf5729c264f4cfadf76e952d
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
18 files changed:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/HeaderInclude.h [new file with mode: 0644]
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/DependencyOutputOptions.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/HeaderIncludeGen.cpp
clang/test/Preprocessor/Inputs/print-header-json/header0.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/header1.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/header2.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/system/system0.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/system/system1.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/system/system2.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/print-header-json/system/system3.h [new file with mode: 0644]
clang/test/Preprocessor/print-header-json.c [new file with mode: 0644]
clang/tools/driver/driver.cpp