summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriel J. Bernal <ariel.j.bernal@intel.com>2013-08-16 04:40:44 +0000
committerAriel J. Bernal <ariel.j.bernal@intel.com>2013-08-16 04:40:44 +0000
commit2203559c3e643692ad0dc1abaeb95116d21d8d60 (patch)
tree2708ecd93ef941588310ec631f6e8e5b39392fd2
parent20eb31b9073ebb19cc24f225e1b6bed69de8931c (diff)
downloadbcm5719-llvm-2203559c3e643692ad0dc1abaeb95116d21d8d60.tar.gz
bcm5719-llvm-2203559c3e643692ad0dc1abaeb95116d21d8d60.zip
Use -std=c++11 when no compilation database is provided
Allow the migrator to be used without specifing --. If neither -- nor -p is provided and no compilation database can be detecteded from the first source file path then -std=c++11 is added as the only compiler argument. llvm-svn: 188533
-rw-r--r--clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp36
-rw-r--r--clang-tools-extra/docs/MigratorUsage.rst26
-rw-r--r--clang-tools-extra/docs/cpp11-migrate.rst5
3 files changed, 47 insertions, 20 deletions
diff --git a/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp b/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp
index 9f295417d36..7bff140f370 100644
--- a/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp
+++ b/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -36,6 +36,10 @@ using namespace clang::tooling;
TransformOptions GlobalOptions;
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::opt<std::string> BuildPath(
+ "p", cl::desc("Build Path"), cl::Optional);
+static cl::list<std::string> SourcePaths(
+ cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore);
static cl::extrahelp MoreHelp(
"EXAMPLES:\n\n"
"Apply all transforms on a given file, no compilation database:\n\n"
@@ -227,8 +231,29 @@ int main(int argc, const char **argv) {
TransformManager.registerTransforms();
- // This causes options to be parsed.
- CommonOptionsParser OptionsParser(argc, argv);
+ // Parse options and generate compilations.
+ OwningPtr<CompilationDatabase> Compilations(
+ FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+ cl::ParseCommandLineOptions(argc, argv);
+
+ if (!Compilations) {
+ std::string ErrorMessage;
+ if (BuildPath.getNumOccurrences() > 0) {
+ Compilations.reset(CompilationDatabase::autoDetectFromDirectory(
+ BuildPath, ErrorMessage));
+ } else {
+ Compilations.reset(CompilationDatabase::autoDetectFromSource(
+ SourcePaths[0], ErrorMessage));
+ // If no compilation database can be detected from source then we create
+ // a new FixedCompilationDatabase with c++11 support.
+ if (!Compilations) {
+ std::string CommandLine[] = {"-std=c++11"};
+ Compilations.reset(new FixedCompilationDatabase(".", CommandLine));
+ }
+ }
+ if (!Compilations)
+ llvm::report_fatal_error(ErrorMessage);
+ }
// Since ExecutionTimeDirectoryName could be an empty string we compare
// against the default value when the command line option is not specified.
@@ -284,9 +309,7 @@ int main(int argc, const char **argv) {
I != E; ++I) {
Transform *T = *I;
- if (T->apply(FileStates, OptionsParser.getCompilations(),
- OptionsParser.getSourcePathList()) !=
- 0) {
+ if (T->apply(FileStates, *Compilations, SourcePaths) != 0) {
// FIXME: Improve ClangTool to not abort if just one file fails.
return 1;
}
@@ -315,8 +338,7 @@ int main(int argc, const char **argv) {
}
if (FinalSyntaxCheck)
- if (!doSyntaxCheck(OptionsParser.getCompilations(),
- OptionsParser.getSourcePathList(), FileStates))
+ if (!doSyntaxCheck(*Compilations, SourcePaths, FileStates))
return 1;
// Write results to file.
diff --git a/clang-tools-extra/docs/MigratorUsage.rst b/clang-tools-extra/docs/MigratorUsage.rst
index 3bb6b41bef8..8822db2519f 100644
--- a/clang-tools-extra/docs/MigratorUsage.rst
+++ b/clang-tools-extra/docs/MigratorUsage.rst
@@ -29,24 +29,28 @@ General Command Line Options
Displays the version information of this tool.
-.. option:: -p[=<build-path>]
+.. option:: -p=<build-path>
- ``<build-path>`` is the directory containing a file named
- ``compile_commands.json`` which provides compiler arguments for building each
- source file. CMake can generate this file by specifying
- ``-DCMAKE_EXPORT_COMPILE_COMMANDS`` when running CMake. Ninja_, since v1.2
- can also generate this file with ``ninja -t compdb``. If ``<build-path>`` is
- not provided the ``compile_commands.json`` file is searched for through all
- parent directories.
+ ``<build-path>`` is the directory containing a *compilation databasefile*, a
+ file named ``compile_commands.json``, which provides compiler arguments for
+ building each source file. CMake can generate this file by specifying
+ ``-DCMAKE_EXPORT_COMPILE_COMMANDS`` when running CMake. Ninja_, since v1.2 can
+ also generate this file with ``ninja -t compdb``. If the compilation database
+ cannot be used for any reason, an error is reported.
+
+ This option is ignored if ``--`` is present.
.. option:: -- [args]
Another way to provide compiler arguments is to specify all arguments on the
command line following ``--``. Arguments provided this way are used for
*every* source file.
-
- If ``-p`` is not specified, ``--`` is necessary, even if no compiler
- arguments are required.
+
+ If neither ``--`` nor ``-p`` are specified a compilation database is
+ searched for starting with the path of the first-provided source file and
+ proceeding through parent directories. If no compilation database is found or
+ one is found and cannot be used for any reason then ``-std=c++11`` is used as
+ the only compiler argument.
.. _Ninja: http://martine.github.io/ninja/
diff --git a/clang-tools-extra/docs/cpp11-migrate.rst b/clang-tools-extra/docs/cpp11-migrate.rst
index faed1431de3..f7f47431472 100644
--- a/clang-tools-extra/docs/cpp11-migrate.rst
+++ b/clang-tools-extra/docs/cpp11-migrate.rst
@@ -41,8 +41,9 @@ Migrator.
Before running the Migrator on code you'll need the arguments you'd normally
pass to the compiler. If you're migrating a single file with few compiler
arguments, it might be easier to pass the compiler args on the command line
-after ``--``. If you're working with multiple files or even a single file
-with many compiler args, it's probably best to use a *compilation database*.
+after ``--``. If you don't have any compiler arguments then ``--`` is not needed.
+If you're working with multiple files or even a single file with many compiler
+args, it's probably best to use a *compilation database*.
A `compilation database`_ contains the command-line arguments for multiple
files. If the code you want to transform can be built with CMake, you can
OpenPOWER on IntegriCloud