1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-06-03 12:39:25 +08:00

913 Commits

Author SHA1 Message Date
Brad King
e4d0169107 ctest: Fix spurious build failures with CTEST_USE_LAUNCHERS on Windows
Remove the stdio handle inheritance suppression originally added by
commit f262298bb0 (... do not inherit pipes in child procs for ctest so
it can kill them, 2007-09-11, v2.6.0~1136).  It's not clear what problem
it was trying to solve, was only done in `ctest` and not `cmake`, and
since commit 9c3ffe2474 (BUG: fix problem with stdout and stderr not
showing up in ms dos shells, 2007-09-25, v2.6.0~1066) has not been done
in `ctest` launched under interactive consoles.

Furthermore, the code has been spuriously breaking stdio when `ctest` is
started with both stdout and stderr connected to the same pipe, such as
when `ctest --launch` is used under `ninja`.  This is because it used
`DuplicateHandle` with `DUPLICATE_CLOSE_SOURCE` on the stdout handle and
then the stderr handle.  If the handles are the same, then the stderr
handle becomes invalid in between these operations, leading to
likely-undefined behavior.  Since commit 96b3dd329e
(cmCTestLaunchReporter: Replace cmsysProcess with cmUVProcessChain,
2023-07-26, v3.28.0-rc1~138^2~2) this became more noticeable because
`uv_spawn` performs additional verification on stdio handles.

This could be fixed by instead suppressing inheritance via

    SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0);

However, the functionality no longer seems necessary, so remove it.
2024-06-14 07:32:29 -04:00
Charlotte Koch
4c70e72cae cmSystemTools: Fix compilation on DragonFly BSD
Define `_XOPEN_SOURCE >= 700` to make `gettimeofday()` et al. available.
2024-04-02 17:33:02 -04:00
Brad King
607051f266 MSYS,CYGWIN: Hard-code host system names when built for these runtimes
When CMake is built against the MSYS runtime library, `uname()` returns
a name that depends on the `MSYSTEM` environment variable.  Previously
we truncated `MSYS_...` to just `MSYS`, but outside `MSYSTEM=MSYS`
environments, names like `MINGW64_NT-10.0-22000` were reported.

The latter causes CMake to report an unsupported-platform error, which
users report as an issue when the real problem is that they should be
using a `MSYSTEM=MSYS` environment or a CMake that is not built against
the MSYS runtime.

For our purposes, if CMake is built against the MSYS runtime, the host
platform is always `MSYS`.  Similarly for `CYGWIN`.
2024-02-01 11:48:32 -05:00
Brad King
96010cc968 Ensure stdin, stdout, stderr FILE streams are open on Windows
Extend commit c85524a94a (Ensure stdin, stdout, and stderr pipes are always
open, 2019-05-02, v3.15.0-rc1~171^2) to cover the `stdin`, `stdout`, and
`stderr` FILE streams from `<stdio.h>`.

Issue: #25625
2024-01-25 12:42:12 -05: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
bcbb212df7 Revert use of libuv for process execution for 3.28
Wide use of CMake 3.28.{1,0[-rcN]} has uncovered some hangs and crashes
in libuv SIGCHLD handling on some platforms, particularly in virtualization
environments on macOS hosts.  Although the bug does not seem to be in CMake,
we can restore stability in the CMake 3.28 release series for users of such
platforms by reverting our new uses of libuv for process execution.

Revert implementation changes merged by commit 4771544386 (Merge topic
'replace-cmsysprocess-with-cmuvprocesschain', 2023-09-06, v3.28.0-rc1~138),
but keep test suite updates.

Issue: #25414, #25500, #25562, #25589
2024-01-24 17:10:00 -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
makise-homura
9bc2aba3b4 LCC: get rid of ambiguous assignments of {} for LCC
LCC 1.21 can't determine the exact type of right side
of assignment and so produces an error. Here it is resolved
by an intermediate variable.
2024-01-16 22:11:02 +03:00
Kyle Edwards
c4be9c914b cmSystemTools::RunSingleCommand(): Pass stdin to child process
Fixes: #25383
2023-11-02 10:04:00 -04:00
Kyle Edwards
50a6e78a82 cmSystemTools::RunSingleCommand(): Replace cmsysProcess with cmUVProcessChain
And pass OUTPUT_PASSTHROUGH in one call where it was missing.
2023-08-29 10:51:30 -04:00
Kyle Edwards
49a37d5a97 cmCTestScriptHandler: Replace cmsysProcess with cmUVProcessChain
And update cmSystemTools::WaitForLine() to use cmUVProcessChain.
2023-08-29 10:51:30 -04:00
Ben Boeckel
36bd3d82f8 cmSystemTools: move ComputeCertificateThumbprint to the only consumer
There's no need to have this API on `cmSystemTools` with only a single
consumer.
2023-08-08 14:25:01 -04:00
Ben Boeckel
a4e4daceaf cmSystemTools: remove ComputeFileHash method
No longer used.
2023-08-08 13:24:00 -04:00
Ben Boeckel
4d5198a986 cmSystemTools: remove ComputeStringMD5 method
No longer used.
2023-08-08 13:22:16 -04:00
Brad King
241ee252ce IWYU: Update for Debian 12 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 12.
2023-07-28 09:14:08 -04:00
Kyle Edwards
7050ac56a1 macOS: Add support for linking against .xcframework folders
Issue: #21752
2023-07-26 17:00:01 -04:00
Brad King
acd9636d9d cmSystemTools: Add helpers for reading and parsing PATH env vars 2023-02-23 09:05:59 -05:00
David Gobbi
aa86e8ddfd Remove component size limit for version comparisons
The VersionCompare() function converted version components to
'unsigned long' prior to comparing them.  Any version components
too large for 'unsigned long' were treated as equal to ULONG_MAX.
This impacted operators like VERSION_GREATER, VERSION_LESS, and
VERSION_EQUAL.  The new code does not limit the length of the
version components for valid comparisons.
2023-02-20 12:54:43 -05:00
scivision
7b0a629693 Source: use C++11 nullptr 2023-02-14 14:34:03 -05:00
Kitware Robot
33abef7416 Revise C++ coding style using clang-format-15
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 15.

* 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.

Fixes: #24315
2023-01-18 16:20:47 -05:00
Brad King
efa9eec040 file(COPY_FILE): Add option to retry on Windows if input access fails
On Windows, a file may be inaccessible for a short time after it is
created.  This occurs for various reasons, including indexing, antivirus
tools, and NTFS's asynchronous semantics.  Add an `INPUT_MAY_BE_RECENT`
option to tell CMake that the input file may have been recently created
so that we can retry a few times to read it.
2022-11-17 15:05:07 -05:00
Brad King
fa518188d8 cmSystemTools: Remove unused CopySingleFile overload 2022-11-17 13:27:19 -05:00
Brad King
89b144789d file(COPY_FILE): Report if failure occurred on input or output path
When we know whether a failure was associated with the input or the
output path, include this information in the error message.
2022-11-15 09:28:45 -05:00
Brad King
aba48bd6ac cmSystemTools: Provide quiet link creation methods
Offer variants that let the caller handle error messages.
2022-10-06 14:38:53 -04:00
zhenhaonong
1b64aa68b9 cmSystemTools: Fix encoding of whole-environment lookup on Windows
On Windows, `environ` is encoded by `CP_ACP`, which may be different
from `KWSYS_ENCODING_DEFAULT_CODEPAGE`.  When environment variables
include a unicode character, they may be corrupted.  Use `_wenviron`
instead.
2022-09-23 11:54:24 +08:00
Matthew Woehlke
d1befe5515 cmSystemTools: Add MakeTempDirectory
Add a cross-platform wrapper over mkdtemp. This will allow us to create
guaranteed-unique directories. On POSIX platforms, this is simply a
wrapper over mkdtemp. On Windows, we take a brute-force approach using
C++11's random facilities and relying on attempts to create an existing
directory resulting in an error. (This approach is very possibly how
mkdtemp is implemented internally, and should be suitable for any
platform if needed, although at present it only uses a partial set of
substitution characters since Windows likely implies a case-insensitive
file system.)
2022-09-05 13:19:58 -04:00
Alex Reinking
c9d70a7cc3 cmake -E env: Add --modify flag
When `cmake -E env` is given the `--modify` flag, try to parse the
following argument as an `ENVIRONMENT_MODIFICATION` operation and apply
it to the environment.

This generalizes `--unset=`:

1.  When implementing `ENVIRONMENT_MODIFICATION` features for other CMake
    commands, the `MYVAR=OP:VALUE` strings do not need to be translated
    to OP-specific flags.
2.  This provides a natural and consistent extension point to introduce
    new operations without introducing very many flags.
3.  Users need to learn only one syntax to access the same functionality.

There is one difference between the behavior here as compared to CTest's
interpretation of the `ENVIRONMENT_MODIFICATION` test property.
The `MYVAR=reset:` command when run in `cmake -E env` will reset `MYVAR`
to whatever its value was when `cmake -E env` launched, rather than try
to checkpoint after plain `MYVAR=VALUE` options.  This makes `MYVAR=VALUE`
and `--modify MYVAR=set:VALUE` semantically equivalent.
2022-08-17 12:54:39 -04:00
Alex Reinking
e2854b4fa2 cmCTestRunTest: Implement the ENVIRONMENT test property with EnvDiff too
Going through the same internal API for both `ENVIRONMENT` and
`ENVIRONMENT_MODIFICATION` properties will make it easier to implement
checkpointing for `MYVAR=reset:` more efficiently if the need ever
presents itself.  It also makes the two-stage nature of the environment
mutation clearer in the code itself.
2022-08-15 14:19:16 -04:00
Alex Reinking
bfa1c5285b cmSystemTools: Add EnvDiff class to hold ENVIRONMENT_MODIFICATION logic
Prepare to re-use this logic when enhancing `cmake -E env`.
2022-08-15 14:11:47 -04:00
Brad King
621ea848b0 Merge topic 'windows-symlink-dir'
a4f1c0fac8 Windows: Revert "Prefer junctions for directory symlinks"

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7530
2022-08-02 09:28:49 -04:00
Brad King
a4f1c0fac8 Windows: Revert "Prefer junctions for directory symlinks"
Revert commit 5101d586c4 (Windows: Prefer junctions for directory
symlinks, 2022-02-22, v3.24.0-rc1~575^2).  Junctions do not support
`../` and other non-canonical paths.  Revert their use pending further
investigation.

Fixes: #23781
Issue: #23257
2022-08-01 10:59:20 -04:00
Brad King
7afbfcb184 Merge topic 'refactor-win-ver'
ee047a68f2 cmSystemTools: Factor out method to get Windows OS version

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7509
2022-07-26 09:24:54 -04:00
Brad King
ee047a68f2 cmSystemTools: Factor out method to get Windows OS version
Factor the implementation out of `cmGlobalGenerator`.
2022-07-25 14:27:24 -04:00
Raul Tambre
8eb8d16c19 cmSystemTools: Fix unsetenv() fallback
The fallback path boils down to putenv(). Calling that with a "=" sets the
variable to an empty string.
Use cmSystemTools::UnPutEnv() instead, which correctly handles unsetting
variables on a variety of systems.
2022-06-26 11:50:00 +03:00
Sean McBride
d5694e4623 Source: Replace uses of sprintf with safer snprintf 2022-06-22 08:59:40 -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
Ben Boeckel
9409e5c04f clang-tidy: address readability-container-data-pointer lints 2022-05-24 09:09:43 -04:00
Erin Melucci
ba969ce5fe cmake-presets: add ${pathListSep} macro
Fixes: #23282
2022-05-12 10:37:49 -04:00
Kasper Laudrup
0b7fd783f8 cmake -E tar: Add --touch option
Similar to GNU tar add a --touch option to the tar extract command to
skip extracting the timestamps from the files in the archive
effectively touching them as if they were just created.

Issue: #22746
2022-03-23 14:41:34 +01:00
Sergei Kryvonos
5101d586c4 Windows: Prefer junctions for directory symlinks
Update the approach added by commit afb7f6e4ff (cmake: Add '-E
create_symlink' support on Windows, 2018-06-11, v3.13.0-rc1~75^2) to use
junctions, as suggested [here](https://superuser.com/a/1291446/140450).
This allows them to work under security limitations on Windows.

Fixes: #23257
2022-03-01 08:48:46 -05:00
Brad King
57349a4851 Merge topic 'rpath-unrecognized-format'
643fc46bdc file(RPATH): Restore tolerance of unknown formats if new RPATH is empty
5596cba7dc cmSystemTools: Remove unnecessary mark-as-used casts to void

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6779
2021-12-02 11:45:38 -05:00
Brad King
643fc46bdc file(RPATH): Restore tolerance of unknown formats if new RPATH is empty
Since commit 2e1149874d (cmSystemTools: Support multiple binary formats,
2021-06-14, v3.22.0-rc1~575^2) the `file(RPATH_...)` operations fail on
files that are not ELF or XCOFF format.  Previously the RPATH operations
tolerated files of unknown format if the goal was to produce a file with
an empty RPATH.  Restore this tolerance in order to support setting an
empty RPATH on GNU ld scripts.

Fixes: #22963
2021-12-01 12:58:11 -05:00
Brad King
5596cba7dc cmSystemTools: Remove unnecessary mark-as-used casts to void
The `CheckRPath` arguments are always used now.
2021-12-01 12:40:03 -05:00
Rose
6f4727aaa0 Source: Replace C headers with C++ ones
In applicable areas only, of course.
2021-11-02 14:45:29 -04:00
Brad King
efc6c23a47 bootstrap: Do not declare cmSystemTools functions that are not implemented
Convert runtime error messages into compile-time errors.
2021-10-27 12:58:02 -04:00
Brad King
a956be4847 Merge topic 'warnings-cleanup'
7e4e192ce2 Source: fix clang-tidy modernize-redundant-void-arg warning
8d671dd94c Source: fix more -Wmissing-prototypes warnings
1cf14f8c03 Source: fix many -Wmissing-prototypes warnings by marking functions static
319944b3d2 Source: fix some -Wunused-macros warnings
5257d9e71a Source: fix only -Wshorten-64-to-32 warning with explicit cast

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6648
2021-10-27 09:24:54 -04:00
Sean McBride
5ba6e8ac59 Source: Replace most calls to sprintf with snprintf 2021-10-25 18:23:13 -04:00
Sean McBride
1cf14f8c03 Source: fix many -Wmissing-prototypes warnings by marking functions static 2021-10-25 12:27:09 -04:00
Marc Chevrier
59ad7a1c24 Move helpers functions from cmStringAlgorithms.h to cmValue.h
Helpers functions related to cmValue semantic are now part of
cmValue.h header.
2021-09-21 18:11:00 +02:00