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