mgorny updated this revision to Diff 461054. mgorny added a comment. Fix documentation formatting. While at it, fix a doc mistake that referenced `x86_64-cl.cfg` instead of the correct `x86_64-clang-cl.cfg`.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D109621/new/ https://reviews.llvm.org/D109621 Files: clang/docs/UsersManual.rst clang/lib/Driver/Driver.cpp clang/test/Driver/config-file3.c
Index: clang/test/Driver/config-file3.c =================================================================== --- clang/test/Driver/config-file3.c +++ clang/test/Driver/config-file3.c @@ -21,6 +21,10 @@ // RUN: ln -s %clang %t/testdmode/qqq-clang-g++ // RUN: echo "-Wundefined-func-template" > %t/testdmode/qqq-clang-g++.cfg // RUN: echo "-Werror" > %t/testdmode/qqq.cfg +// RUN: ln -s %clang %t/testdmode/clang-g++ +// RUN: ln -s %clang %t/testdmode/clang +// RUN: : > %t/testdmode/default-clang.cfg +// RUN: : > %t/testdmode/default.cfg // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix FULL-NAME // // FULL-NAME: Configuration file: {{.*}}/testdmode/qqq-clang-g++.cfg @@ -41,6 +45,16 @@ // // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg +//--- Invoking clang falls back to default-clang.cfg. +// RUN: %t/testdmode/clang --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT-CLANG +// +// DEFAULT-CLANG: Configuration file: {{.*}}/testdmode/default-clang.cfg + +//--- Invoking clang-g++ falls back to default.cfg. +// RUN: %t/testdmode/clang-g++ --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT +// +// DEFAULT: Configuration file: {{.*}}/testdmode/default.cfg + //--- --no-default-config disables config search. // // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck %s -check-prefix NO-DEFAULT-CONFIG Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -1024,18 +1024,21 @@ } } - if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) { + if (CfgFileName.empty()) { + if (CLOptions && CLOptions->hasArg(options::OPT_no_default_config)) + return false; + // If config file is not specified explicitly, try to deduce configuration // from executable name. For instance, an executable 'armv7l-clang' will - // search for config file 'armv7l-clang.cfg'. - if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty()) + // search for config file 'armv7l-clang.cfg'. If we are called without + // a specific prefix, use e.g. 'default-clang.cfg' instead. + if (!ClangNameParts.TargetPrefix.empty()) CfgFileName = ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix; + else + CfgFileName = "default-" + ClangNameParts.ModeSuffix; } - if (CfgFileName.empty()) - return false; - // Determine architecture part of the file name, if it is present. StringRef CfgFileArch = CfgFileName; size_t ArchPrefixLen = CfgFileArch.find('-'); @@ -1093,9 +1096,9 @@ return readConfigFile(CfgFilePath); // Finally try removing driver mode part: 'x86_64-clang.cfg' -> 'x86_64.cfg'. - if (!ClangNameParts.ModeSuffix.empty() && - !ClangNameParts.TargetPrefix.empty()) { - CfgFileName.assign(ClangNameParts.TargetPrefix); + if (!FileSpecifiedExplicitly && !ClangNameParts.ModeSuffix.empty()) { + CfgFileName.resize(CfgFileName.size() - ClangNameParts.ModeSuffix.size() - + 5); CfgFileName.append(".cfg"); if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS())) return readConfigFile(CfgFilePath); Index: clang/docs/UsersManual.rst =================================================================== --- clang/docs/UsersManual.rst +++ clang/docs/UsersManual.rst @@ -883,7 +883,7 @@ example, to collect options required to tune compilation for particular target, such as -L, -I, -l, --sysroot, codegen options, etc. -The command line option `--config` can be used to specify configuration +The command line option ``--config`` can be used to specify configuration file in a Clang invocation. For example: :: @@ -906,17 +906,19 @@ If no explicit configuration file is specified, Clang searches for a default configuration file following the rules described in the next paragraphs. -To disable this behavior, `--no-default-config` flag can be used. +To disable this behavior, ``--no-default-config`` flag can be used. Another way to specify a configuration file is to encode it in executable name. -For example, if the Clang executable is named `armv7l-clang` (it may be a -symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the -directory where Clang resides. +For example, if the Clang executable is named ``armv7l-clang`` (it may be a +symbolic link to ``clang``), then Clang will search for file ``armv7l.cfg`` +in the directory where Clang resides. If Clang is started via an executable +without target prefix, Clang will use ``default.cfg`` instead. If a driver mode is specified in invocation, Clang tries to find a file specific for the specified mode. For example, if the executable file is named -`x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not found, -looks for `x86_64.cfg`. +``x86_64-clang-cl``, Clang first looks for ``x86_64-clang-cl.cfg`` and if it is +not found, looks for ``x86_64.cfg``. Similarly, for ``clang-cl``, it looks for +``default-clang-cl.cfg`` before trying ``default.cfg``. If the command line contains options that effectively change target architecture (these are -m32, -EL, and some others) and the configuration file starts with an @@ -927,12 +929,12 @@ x86_64-clang -m32 abc.c -causes Clang search for a file `i368.cfg` first, and if no such file is found, -Clang looks for the file `x86_64.cfg`. +causes Clang search for a file ``i368.cfg`` first, and if no such file is found, +Clang looks for the file ``x86_64.cfg``. The configuration file consists of command-line options specified on one or more lines. Lines composed of whitespace characters only are ignored as well as -lines in which the first non-blank character is `#`. Long options may be split +lines in which the first non-blank character is ``#``. Long options may be split between several lines by a trailing backslash. Here is example of a configuration file: @@ -948,19 +950,19 @@ # other config files may be included @linux.options -Files included by `@file` directives in configuration files are resolved +Files included by ``@file`` directives in configuration files are resolved relative to the including file. For example, if a configuration file -`~/.llvm/target.cfg` contains the directive `@os/linux.opts`, the file -`linux.opts` is searched for in the directory `~/.llvm/os`. +``~/.llvm/target.cfg`` contains the directive ``@os/linux.opts``, the file +``linux.opts`` is searched for in the directory ``~/.llvm/os``. -To generate paths relative to the configuration file, the `<CFGDIR>` token may +To generate paths relative to the configuration file, the ``<CFGDIR>`` token may be used. This will expand to the absolute path of the directory containing the configuration file. In cases where a configuration file is deployed alongside SDK contents, the -SDK directory can remain fully portable by using `<CFGDIR>` prefixed paths. +SDK directory can remain fully portable by using ``<CFGDIR>`` prefixed paths. In this way, the user may only need to specify a root configuration file with -`--config` to establish every aspect of the SDK with the compiler: +``--config`` to establish every aspect of the SDK with the compiler: ::
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits