1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-05-10 15:12:19 +08:00

79 Commits

Author SHA1 Message Date
Brad King
e388ed687a execute_process: Improve invocation of .cmd/.bat with spaces
Extend the fix from commit 74c9d40876 (execute_process: Fix invocation
of .cmd/.bat with spaces, 2025-01-31) to work without relying on
conversion to a "short path", which may not exist.  Instead, extending
the `cmd /c` wrapper to `cmd /c call` seems to support spaces directly.

Suggested-by: Alexandru Croitor <alexandru.croitor@qt.io>
Fixes: #26655
2025-02-10 19:44:19 -05:00
Brad King
74c9d40876 execute_process: Fix invocation of .cmd/.bat with spaces
The `CreateProcessW` documentation states "to run a batch file, you must
start the command interpreter".  Use `cmd /c the.bat` to run batch files.
Also, use a "short path" to the `.bat` file if needed to avoid spaces.

Previously this worked in some cases only due to undocumented behavior
of `CreateProcessW` when given a `.bat` file.

Fixes: #26655
2025-02-03 09:13:26 -05:00
Kitware Robot
0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00
Martin Duffy
3ece058d97 execute_process: Allow setting default COMMAND_ERROR_IS_FATAL value
Issue: #26576
2025-01-15 11:12:34 -05:00
Brad King
ee5a6f3aec Merge topic 'execute_process-OUTPUT_FILE-cloexec'
60af429c5d execute_process: Restore CLOEXEC on OUTPUT_FILE and ERROR_FILE descriptors

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Bertrand Bellenot <bertrand.bellenot@cern.ch>
Merge-request: !10014
2024-11-21 08:24:20 -05:00
Brad King
60af429c5d execute_process: Restore CLOEXEC on OUTPUT_FILE and ERROR_FILE descriptors
Since commit 5420639a8d (cmExecuteProcessCommand: Replace cmsysProcess
with cmUVProcessChain, 2023-06-01, v3.28.0-rc1~138^2~8), the descriptors
for the `OUTPUT_FILE` and `ERROR_FILE` leak to child processes.

With `ExternalProject` + `INSTALL_COMMAND` + `LOG_INSTALL`, the logging
wrapper script leaks the log files' descriptors to the native build
tool.  If they happen to match the `make` job server's pipe fds, e.g.,
with GNU `make` <= 4.3, then the build fails with an error like:

    gmake[4]: *** read jobs pipe: Bad file descriptor.  Stop.

Fixes: #26398
2024-11-20 06:16:11 -05:00
Brad King
20f059d025 execute_process: Warn on unknown ENCODING value 2024-09-17 09:20:58 -04:00
Brad King
e782811cfe execute_process: Change default ENCODING to UTF-8
Windows is heading toward making UTF-8 the preferred MBCS.  As CMake's
internal encoding, `UTF-8` is effectively equivalent to `NONE`, which
was CMake's behavior prior to 3.15's accidental change to `AUTO`.
Behavior of `ENCODING UTF-8` is independent of CMake's internal
encoding, making it in principle a better default than `NONE`.

Add policy CMP0176 for compatibility and to document the default's
history.

Fixes: #26262
2024-09-16 06:37:46 -04:00
Brad King
9a4533405b cmExecuteProcessCommand: Explicitly ignore unknown ENCODING values
The logic did this implicitly before.  Make it easier to follow.
2024-09-16 06:37:15 -04:00
Brad King
b11c8c45f9 Merge topic 'cmuvprocesschain'
adb3e13d32 cmUVProcessChain: Tolerate fileno() of invalid FILE stream
b6e4e4babc cmUVProcessChain: Simplify SetExternalStream usage
116bb2b70f cmUVProcessChain: Simplify builder initialization
d32c30906a Tests: Add missing include in testUVProcessChainHelper on Windows

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9181
2024-01-25 10:40:02 -05:00
Brad King
b6e4e4babc cmUVProcessChain: Simplify SetExternalStream usage
It is commonly called with the `fileno()` of a `FILE*` stream,
so accept the latter directly.
2024-01-24 16:59:49 -05:00
Brad King
d9d9326e14 Source: Avoid out-of-range inputs to std::isspace()
`isspace` takes `int` but documents that the value must be representable
by `unsigned char`, or be EOF.  Use a wrapper to cast to `unsigned char`
to avoid sign extension while converting to `int`.  This generalizes the
fix from commit 5e8c176e2a (cmExecuteProcessCommand: Cast c to unsigned
char before cast to int, 2024-01-05) to other `isspace` call sites.

This was detected by assertions in the MSVC standard library while
processing UTF-8 text.

Issue: #25561
2024-01-17 10:17:06 -05:00
leha-bot
5e8c176e2a cmExecuteProcessCommand: Cast c to unsigned char before cast to int
As the 'char' type may be either signed, or unsigned, there are some
clashes between C Standard library functions and actual characters while
casting it to int directly. In case the 'char' type was signed, the
casted to int result value may be extended to full negative digit which
may be out of range of isspace() function (e.g. , for MSVC
implementation, which checks it for '> -1', and throwing an assertion
failure on fail).

Fixes: #25561
2024-01-05 14:36:43 -05:00
Kyle Edwards
35f031e3b2 execute_process(): Restore opening files relative to WORKING_DIRECTORY
Prior to 5420639a, execute_process() would open INPUT_FILE, OUTPUT_FILE,
and ERROR_FILE relative to the WORKING_DIRECTORY argument if it was
provided. Restore this behavior for backwards compatibility.

Fixes: #25338
2023-10-16 12:23:41 -04:00
Kyle Edwards
5420639a8d cmExecuteProcessCommand: Replace cmsysProcess with cmUVProcessChain 2023-08-29 10:51:30 -04:00
Marc Chevrier
45f17e5a85 cmList: Add container conversion to string 2023-06-22 15:44:17 +02:00
Brad King
e56108f629 cmExecuteProcessCommand: Report keyword errors via argument parser results 2022-07-22 10:32:24 -04:00
Brad King
1ee5a4a548 cmArgumentParser: Avoid allocating copies of keyword strings 2022-07-05 16:34:57 -04:00
FeRD (Frank Dana)
98a10290a8 cmSystemTools: Fix 'ErrorOccurred' spelling
Rename the booleans 's_ErrorOccured' and 's_FatalErrorOccured' to
's_ErrorOccurred' and 's_FatalErrorOccurred', respectively.

Rename the getters and setters to 'Get[Fatal]ErrorOccurred' and
'Set[Fatal]ErrorOccurred', and fix all uses across the codebase.
2022-06-13 09:05:24 -04:00
Sean McBride
5ba6e8ac59 Source: Replace most calls to sprintf with snprintf 2021-10-25 18:23:13 -04:00
Ben Boeckel
cdfc4e3195 clang-tidy: fix readability-qualified-auto warnings 2021-01-27 08:45:45 -05:00
Asit Dhal
e5a4ffaad1 execute_process: Improve COMMAND_ERROR_IS_FATAL error capture scenarios
1.  COMMAND_ERROR_IS_FATAL ANY will capture errors if the exit code is
    non zero, there is a timeout or an abnormal exit.

2.  COMMAND_ERROR_IS_FATAL LAST
    will capture if only the last process has an exit code non zero, there
    is a timeout or an abnormal exit.

Fixes: #21562
2020-12-10 06:09:59 -05:00
Asit Dhal
116a427eb1 execute_process: add options for fatal errors on subprocess failure
Fixes: #19930
2020-10-01 17:07:44 +02:00
Marc Chevrier
8d4a9ee398 Refactoring: rename "cm_static_string_view.hxx" as <cmext/string_view> 2020-04-30 09:53:27 +02:00
Cristian Adam
6ec274b002 execute_process: Add ECHO_(OUTPUT|ERROR)_VARIABLE options
Fixes: #20378
2020-02-24 14:44:14 +01:00
Marc Chevrier
f7d12609f0 Refactoring: use append functions from cmext/algorithm 2019-12-17 10:44:02 +01:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Regina Pfeifer
f30523d090 clang-tidy: modernize-deprecated-headers 2019-09-16 10:11:13 -04:00
Gabor Bencze
3e5eb45ec1 cmCommand refactor: cmExecuteProcessCommand 2019-08-20 14:42:19 -04:00
Sebastian Holtermann
f71f7ce3f0 cmStringAlgorithms: Move string functions to the new cmStringAlgorithms.h
This adds the `cmStringAlgorithms.h` header and moves all string functions
from `cmAlgorithms.h` to `cmStringAlgorithms.h`.
2019-07-29 21:13:56 +02:00
Sebastian Holtermann
e91bfe440c cmMakefile: Let AddDefinition accept a value as cm::string_view
This changes `cmMakefile::AddDefinition` to take a `cm::string_view` as value
argument instead of a `const char *`.

Benefits are:
- `std::string` can be passed to `cmMakefile::AddDefinition` directly without
  the `c_str()` plus string length recomputation fallback.
- Lengths of literals passed to `cmMakefile::AddDefinition` can be computed at
  compile time.

In various sources uses of `cmMakefile::AddDefinition` are adapted to avoid
`std::string::c_str` calls and the `std::string` is passed directly.
Uses of `cmMakefile::AddDefinition`, where a `nullptr` `const char*` might
be passed to `cmMakefile::AddDefinition` are extended with `nullptr` checks.
2019-07-24 11:11:25 +02:00
Marc Chevrier
1591f138f1 modernize: manage cmCommand instances using unique_ptr. 2019-07-14 15:37:30 +02:00
Brad King
71fbebd1dc IWYU: Fix handling of <memory> standard header
An old workaround for `std::allocator_traits<>::value_type` lints from
IWYU on `std::vector<>` usage breaks IWYU's handling of `<memory>`.
Convert the workaround to use the same approach we already use for a
workaround of `std::__decay_and_strip<>::::__type` lints.  Then update
the `<memory>` inclusions to follow the now-correct IWYU lints.
2019-07-10 11:48:56 -04:00
Sebastian Holtermann
006229278b Use cmAppend to append ranges to std::vector instances 2019-05-23 16:19:49 +02:00
Bill Hoffman
044dcf9f8d execute_process: Add option to echo command lines
Add COMMAND_ECHO option to the execute_process command. This will allow
execute_process to show the command it will run. Also add a cmake variable
CMAKE_EXECUTE_PROCESS_COMMAND_ECHO. Both the option and the variable can
be set to one of the following: STDERR|STDOUT|NONE. The command will be
printed to stderr or stdout or not at all.

Fixes: #18933
2019-04-19 13:32:08 -04:00
Brad King
d350fb6889 execute_process: Manage KWSys Process lifetime with unique_ptr 2019-04-19 13:32:08 -04:00
Regina Pfeifer
b783e62533 cmExecuteProcessCommand: Port to cmArgumentParser 2019-04-04 13:24:40 -04:00
Artur Ryt
f3534386b5 Prefer front/back/data over dereferencing begin/rbegin iter
Changed for sequenced containers: vector, list, string and array
2019-02-06 10:43:16 -05:00
Brad King
4b017d579d Merge topic 'Wcomma'
5ff7fb592e Fixed all but one clang -Wcomma warning

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2828
2019-01-22 09:38:30 -05:00
Brad King
cb7fbf1dbb Merge topic 'stdout-string'
3132ea801c cmSystemTools: Stdout(),Stderr() accept std::string argument

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2829
2019-01-22 09:32:58 -05:00
Vitaly Stakhovsky
3132ea801c cmSystemTools: Stdout(),Stderr() accept std::string argument 2019-01-20 00:03:35 -05:00
Regina Pfeifer
ef61997b1b clang-tidy: Use emplace 2019-01-17 13:12:02 -05:00
Sean McBride
5ff7fb592e Fixed all but one clang -Wcomma warning 2019-01-11 20:48:19 -05:00
Pavel Solodovnikov
653b894683 Reduce raw string pointers usage.
* Change some functions to take `std::string` instead of
  `const char*` in the following classes: `cmMakeFile`, `cmake`,
  `cmCoreTryCompile`, `cmSystemTools`,  `cmState`, `cmLocalGenerator`
  and a few others.
* Greatly reduce using of `const char*` overloads for
  `cmSystemTools::MakeDirectory` and `cmSystemTools::RelativePath`.
* Remove many redundant `c_str()` conversions throughout the code.
2018-01-31 18:23:03 +03:00
Pavel Solodovnikov
7d5095796a Meta: modernize old-fashioned loops to range-based for.
Changes done via `clang-tidy` with some manual fine-tuning
for the variable naming and `auto` type deduction
where appropriate.
2017-09-12 16:22:47 +03:00
Daniel Pfeifer
2b4c32c95f clang-format: format all code as Cpp11 2017-08-30 11:07:05 -04:00
Daniel Pfeifer
190e3825d4 Replace C-style casts 2017-08-27 09:58:46 +02:00
Daniel Pfeifer
5962db4389 Use C++11 nullptr 2017-08-24 23:39:47 +02:00
Adam Weisi
d6051ca39e execute_process: Add option to get results of every child
Add a `RESULTS_VARIABLE` option to get the results of all children
in a pipeline of one or more `COMMAND`s.
2017-06-10 08:03:06 -04:00
Daniel Pfeifer
1d829c862c Use quotes for non-system includes
Automate with:

git grep -l '#include <cm_' -- Source \
  | xargs sed -i 's/#include <\(cm_.*\)>/#include "\1"/g'

git grep -l '#include <cmsys/' -- Source \
  | xargs sed -i 's/#include <\(cmsys\/.*\)>/#include "\1"/g'

git grep -l '#include <cm[A-Z]' -- Source \
  | xargs sed -i 's/#include <\(cm[A-Z].*\)>/#include "\1"/g'
2017-04-11 22:35:21 +02:00