mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 05:46:06 +00:00
CompilerInvocation: Move builtin-include-path logic out of CompilerInvocation::CreateFromArgs.
llvm-svn: 91237
This commit is contained in:
parent
85d2f8f875
commit
d613677ec9
@ -82,15 +82,19 @@ public:
|
||||
/// \param Res [out] - The resulting invocation.
|
||||
/// \param ArgBegin - The first element in the argument vector.
|
||||
/// \param ArgEnd - The last element in the argument vector.
|
||||
/// \param Diags - The diagnostic engine to use for errors.
|
||||
static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
|
||||
const char **ArgEnd, Diagnostic &Diags);
|
||||
|
||||
/// GetBuiltinIncludePath - Get the directory where the compiler headers
|
||||
/// reside, relative to the compiler binary (found by the passed in
|
||||
/// arguments).
|
||||
///
|
||||
/// \param Argv0 - The program path (from argv[0]), for finding the builtin
|
||||
/// compiler path.
|
||||
/// \param MainAddr - The address of main (or some other function in the main
|
||||
/// executable), for finding the builtin compiler path.
|
||||
/// \param Diags - The diagnostic engine to use for errors.
|
||||
static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
|
||||
const char **ArgEnd, const char *Argv0,
|
||||
void *MainAddr,
|
||||
Diagnostic &Diags);
|
||||
static std::string GetBuiltinIncludePath(const char *Argv0, void *MainAddr);
|
||||
|
||||
/// toArgs - Convert the CompilerInvocation to a list of strings suitable for
|
||||
/// passing to CreateFromArgs.
|
||||
|
@ -65,6 +65,9 @@ public:
|
||||
/// will be searched following the user and environment includes.
|
||||
std::string BuiltinIncludePath;
|
||||
|
||||
/// Include the compiler builtin includes.
|
||||
unsigned UseBuiltinIncludes : 1;
|
||||
|
||||
/// Include the system standard include search directories.
|
||||
unsigned UseStandardIncludes : 1;
|
||||
|
||||
@ -73,7 +76,8 @@ public:
|
||||
|
||||
public:
|
||||
HeaderSearchOptions(llvm::StringRef _Sysroot = "/")
|
||||
: Sysroot(_Sysroot), UseStandardIncludes(true), Verbose(false) {}
|
||||
: Sysroot(_Sysroot), UseBuiltinIncludes(true),
|
||||
UseStandardIncludes(true), Verbose(false) {}
|
||||
|
||||
/// AddPath - Add the \arg Path path to the specified \arg Group list.
|
||||
void AddPath(llvm::StringRef Path, frontend::IncludeDirGroup Group,
|
||||
|
@ -327,7 +327,13 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
|
||||
CompilerInvocation CI;
|
||||
CompilerInvocation::CreateFromArgs(CI, (const char**) CCArgs.data(),
|
||||
(const char**) CCArgs.data()+CCArgs.size(),
|
||||
Argv0, MainAddr, Diags);
|
||||
Diags);
|
||||
|
||||
// Infer the builtin include path if unspecified.
|
||||
if (CI.getHeaderSearchOpts().UseBuiltinIncludes &&
|
||||
CI.getHeaderSearchOpts().BuiltinIncludePath.empty())
|
||||
CI.getHeaderSearchOpts().BuiltinIncludePath =
|
||||
CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr);
|
||||
|
||||
CI.getFrontendOpts().DisableFree = UseBumpAllocator;
|
||||
return LoadFromCompilerInvocation(CI, Diags, OnlyLocalDecls);
|
||||
|
@ -951,8 +951,8 @@ ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Diagnostic &Diags) {
|
||||
return DashX;
|
||||
}
|
||||
|
||||
static std::string GetBuiltinIncludePath(const char *Argv0,
|
||||
void *MainAddr) {
|
||||
std::string CompilerInvocation::GetBuiltinIncludePath(const char *Argv0,
|
||||
void *MainAddr) {
|
||||
llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr);
|
||||
|
||||
if (!P.isEmpty()) {
|
||||
@ -969,16 +969,16 @@ static std::string GetBuiltinIncludePath(const char *Argv0,
|
||||
return P.str();
|
||||
}
|
||||
|
||||
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
|
||||
const char *Argv0, void *MainAddr) {
|
||||
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
|
||||
using namespace cc1options;
|
||||
Opts.Sysroot = getLastArgValue(Args, OPT_isysroot, "/");
|
||||
Opts.Verbose = Args.hasArg(OPT_v);
|
||||
Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
|
||||
Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
|
||||
// Filled in by clients.
|
||||
//
|
||||
// FIXME: Elimate this.
|
||||
Opts.BuiltinIncludePath = "";
|
||||
// FIXME: Add an option for this, its a slow call.
|
||||
if (!Args.hasArg(OPT_nobuiltininc))
|
||||
Opts.BuiltinIncludePath = GetBuiltinIncludePath(Argv0, MainAddr);
|
||||
|
||||
// Add -I... and -F... options in order.
|
||||
for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F),
|
||||
@ -1262,8 +1262,6 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
|
||||
void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
|
||||
const char **ArgBegin,
|
||||
const char **ArgEnd,
|
||||
const char *Argv0,
|
||||
void *MainAddr,
|
||||
Diagnostic &Diags) {
|
||||
// Parse the arguments.
|
||||
llvm::OwningPtr<OptTable> Opts(createCC1OptTable());
|
||||
@ -1287,8 +1285,7 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
|
||||
ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags);
|
||||
FrontendOptions::InputKind DashX =
|
||||
ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
|
||||
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args,
|
||||
Argv0, MainAddr);
|
||||
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
|
||||
if (DashX != FrontendOptions::IK_AST)
|
||||
ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
|
||||
ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, Diags);
|
||||
|
@ -730,7 +730,7 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
|
||||
else
|
||||
Init.AddDelimitedPaths(HSOpts.CEnvIncPath);
|
||||
|
||||
if (!HSOpts.BuiltinIncludePath.empty()) {
|
||||
if (HSOpts.UseBuiltinIncludes) {
|
||||
// Ignore the sys root, we *always* look for clang headers relative to
|
||||
// supplied path.
|
||||
Init.AddPath(HSOpts.BuiltinIncludePath, System,
|
||||
|
@ -121,8 +121,7 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
|
||||
|
||||
// FIXME: Define the need for this testing away.
|
||||
static int cc1_test(Diagnostic &Diags,
|
||||
const char **ArgBegin, const char **ArgEnd,
|
||||
const char *Argv0, void *MainAddr) {
|
||||
const char **ArgBegin, const char **ArgEnd) {
|
||||
using namespace clang::driver;
|
||||
|
||||
llvm::errs() << "cc1 argv:";
|
||||
@ -150,8 +149,7 @@ static int cc1_test(Diagnostic &Diags,
|
||||
// Create a compiler invocation.
|
||||
llvm::errs() << "cc1 creating invocation.\n";
|
||||
CompilerInvocation Invocation;
|
||||
CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
|
||||
Argv0, MainAddr, Diags);
|
||||
CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd, Diags);
|
||||
|
||||
// Convert the invocation back to argument strings.
|
||||
std::vector<std::string> InvocationArgs;
|
||||
@ -170,8 +168,7 @@ static int cc1_test(Diagnostic &Diags,
|
||||
// same thing.
|
||||
CompilerInvocation Invocation2;
|
||||
CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
|
||||
Invocation2Args.end(), Argv0, MainAddr,
|
||||
Diags);
|
||||
Invocation2Args.end(), Diags);
|
||||
|
||||
// FIXME: Implement CompilerInvocation comparison.
|
||||
if (true) {
|
||||
@ -198,7 +195,7 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
|
||||
if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
|
||||
TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
|
||||
Diagnostic Diags(&DiagClient);
|
||||
return cc1_test(Diags, ArgBegin + 1, ArgEnd, Argv0, MainAddr);
|
||||
return cc1_test(Diags, ArgBegin + 1, ArgEnd);
|
||||
}
|
||||
|
||||
// Initialize targets first, so that --version shows registered targets.
|
||||
@ -210,7 +207,13 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
|
||||
TextDiagnosticBuffer DiagsBuffer;
|
||||
Diagnostic Diags(&DiagsBuffer);
|
||||
CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
|
||||
Argv0, MainAddr, Diags);
|
||||
Diags);
|
||||
|
||||
// Infer the builtin include path if unspecified.
|
||||
if (Clang.getInvocation().getHeaderSearchOpts().UseBuiltinIncludes &&
|
||||
Clang.getInvocation().getHeaderSearchOpts().BuiltinIncludePath.empty())
|
||||
Clang.getInvocation().getHeaderSearchOpts().BuiltinIncludePath =
|
||||
CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr);
|
||||
|
||||
// Honor -help.
|
||||
if (Clang.getInvocation().getFrontendOpts().ShowHelp) {
|
||||
@ -232,7 +235,7 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
|
||||
Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
|
||||
if (!Clang.hasDiagnostics())
|
||||
return 1;
|
||||
|
||||
|
||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
||||
// error handler.
|
||||
llvm::llvm_install_error_handler(LLVMErrorHandler,
|
||||
|
Loading…
x
Reference in New Issue
Block a user