[clang-tools-extra] r188533 - Use -std=c++11 when no compilation database is provided
Ariel J. Bernal
ariel.j.bernal at intel.com
Thu Aug 15 21:40:44 PDT 2013
Author: ajbernal
Date: Thu Aug 15 23:40:44 2013
New Revision: 188533
URL: http://llvm.org/viewvc/llvm-project?rev=188533&view=rev
Log:
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.
Modified:
clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
clang-tools-extra/trunk/docs/MigratorUsage.rst
clang-tools-extra/trunk/docs/cpp11-migrate.rst
Modified: clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp?rev=188533&r1=188532&r2=188533&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp Thu Aug 15 23:40:44 2013
@@ -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.
Modified: clang-tools-extra/trunk/docs/MigratorUsage.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/MigratorUsage.rst?rev=188533&r1=188532&r2=188533&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/MigratorUsage.rst (original)
+++ clang-tools-extra/trunk/docs/MigratorUsage.rst Thu Aug 15 23:40:44 2013
@@ -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/
Modified: clang-tools-extra/trunk/docs/cpp11-migrate.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/cpp11-migrate.rst?rev=188533&r1=188532&r2=188533&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/cpp11-migrate.rst (original)
+++ clang-tools-extra/trunk/docs/cpp11-migrate.rst Thu Aug 15 23:40:44 2013
@@ -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
More information about the cfe-commits
mailing list