From 322c29fefe7fa33f03273136eb5f8b7f5b4df7c0 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 2 Feb 2011 21:11:35 +0000 Subject: [PATCH] clang: Add support for a CC_PRINT_HEADERS environment variable, which mirrors CC_PRINT_OPTIONS and can be used to get some out-of-band information on header usage from a build. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124751 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 7 +++++++ lib/Driver/Driver.cpp | 5 +++-- lib/Driver/Tools.cpp | 5 +++++ tools/driver/driver.cpp | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 98c8c4623a..f01698c816 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -95,6 +95,9 @@ public: /// The file to log CC_PRINT_OPTIONS output to, if enabled. const char *CCPrintOptionsFilename; + /// The file to log CC_PRINT_HEADERS output to, if enabled. + const char *CCPrintHeadersFilename; + /// Whether the driver should follow g++ like behavior. unsigned CCCIsCXX : 1; @@ -108,6 +111,10 @@ public: /// CCPrintOptionsFilename or to stderr. unsigned CCPrintOptions : 1; + /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include + /// information to CCPrintHeadersFilename or to stderr. + unsigned CCPrintHeaders : 1; + private: /// Name to use when calling the generic gcc. std::string CCCGenericGCCName; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index df32eb3a4d..d56b1d2974 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -58,8 +58,9 @@ Driver::Driver(llvm::StringRef _ClangExecutable, DefaultImageName(_DefaultImageName), DriverTitle("clang \"gcc-compatible\" driver"), Host(0), - CCPrintOptionsFilename(0), CCCIsCXX(false), - CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), CCCGenericGCCName("gcc"), + CCPrintOptionsFilename(0), CCPrintHeadersFilename(0), CCCIsCXX(false), + CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), + CCPrintHeaders(false), CCCGenericGCCName("gcc"), CheckInputsExist(true), CCCUseClang(true), CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true), SuppressMissingInputWarning(false) { if (IsProduction) { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 61d1bbe48e..d1d8873c3a 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1127,6 +1127,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_v); Args.AddLastArg(CmdArgs, options::OPT_H); + if (D.CCPrintHeaders) { + CmdArgs.push_back("-header-include-file"); + CmdArgs.push_back(D.CCPrintHeadersFilename ? + D.CCPrintHeadersFilename : "-"); + } Args.AddLastArg(CmdArgs, options::OPT_P); Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index e3797d4495..0b5d2c97a4 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -347,6 +347,11 @@ int main(int argc_, const char **argv_) { if (TheDriver.CCPrintOptions) TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE"); + // Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE. + TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS"); + if (TheDriver.CCPrintHeaders) + TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE"); + // Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a // command line behind the scenes. if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) { -- 2.40.0