Commit Graph

842 Commits

Author SHA1 Message Date
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
Marc Chevrier
7e154ebd59 cmSystemTools::VersionCompare: use std::string for arguments 2021-09-17 11:58:46 +02:00
Lucas SOLTIC
6ef7bfbb64 Xcode: add support for embedding dynamic libraries 2021-09-14 08:39:22 +10:00
Brad King
20fec15204 cmArchiveWrite: Check for construction errors on Open
Also update call sites to report the error.

Issue: #19666
2021-08-20 11:23:20 -04:00
Alex Richardson
115ff6a347 cmELF: Include the ELF parsing code unconditionally
Now that the ELF definitions are provided on all platforms there is no
need to keep the CMake_USE_ELF_PARSER option.
2021-06-24 10:57:51 -04:00
Alex Richardson
0da1540aaa cmELF: Fix check for TagMipsRldMapRel
DT_MIPS_RLD_MAP_REL is a machine-speicific dynamic tag, so other
architectures could re-use the value of 0x70000035 to mean something
else.  Before using DT_MIPS_RLD_MAP_REL, we have to check that the ELF
file is actually has a e_machine of EM_MIPS.
2021-06-24 10:57:51 -04:00
Alex Richardson
2e1149874d cmSystemTools: Support multiple binary formats
This prepares the code to handle both the ELF and XCOFF being enabled by
trying to parse an ELF file first and if that fails falling back to XCOFF.
2021-06-21 09:36:39 -04:00
Kyle Edwards
f73027b182 cmSystemTools: Add SetRPath() method 2021-06-04 08:52:01 -04:00
Kyle Edwards
966f7250df Refactor: Break up logic in cmSystemTools::ChangeRPath() 2021-06-04 08:52:01 -04:00
Marius Messerschmidt
bceb8e2ed2 cmMessenger: Pass title inside a metadata structure 2021-05-19 09:06:27 -04:00
Brad King
5b3a71a83f cmSystemTools: Adopt RelativeIfUnder helper
This returns a relative path if it does not start in `../`.
2021-05-17 10:02:16 -04:00
Brad King
d7522b8f86 cmSystemTools: Improve CreateLink and CreateSymlink error codes
In commit 7f89053953 (cmSystemTools: Return KWSys Status from CreateLink
and CreateSymlink, 2021-04-15) we just took the `-err` from libuv and
treated it as a POSIX error.  This is accurate on POSIX, but on Windows
does not match the POSIX error codes.

Use `uv_fs_get_system_error` to get the actual system error code.
This requires libuv 1.38 or higher.  Require that for Windows, but
fall back to the previous approach on POSIX.
2021-05-07 08:30:52 -04:00
Brad King
e2ac92681c Merge topic 'nvhpc-warnings'
f881b4e4cc cmCPackDebGenerator: Remove unused local variable
5ad8862318 Source: Convince NVHPC that RAII variables are used
1898f9dd82 cmFileCommand: Remove unused local variable
6a003c6f35 cmSystemTools: Avoid unreachable code warning on NVHPC
16275c7f82 LexerParser: Suppress NVHPC warnings in generated code
cefda16d35 LexerParser: Regenerate parsers with bison 3.7.5

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6049
2021-04-29 09:21:37 -04:00
Brad King
6a003c6f35 cmSystemTools: Avoid unreachable code warning on NVHPC 2021-04-28 10:09:52 -04:00
Orgad Shaneh
ddcd1469e8 MSYS: Add support for running under MSYS runtime environment
Detect MSYS as CYGWIN, with the required adaptations.
2021-04-26 14:27:34 -04:00
Brad King
7f89053953 cmSystemTools: Return KWSys Status from CreateLink and CreateSymlink 2021-04-15 12:40:37 -04:00
Brad King
3ef5dab010 cmSystemTools: Simplify using KWSys Status 2021-04-14 13:14:29 -04:00
Brad King
ec1b6157cb Update CMake code using KWSys to account for Status return values
KWSys as of 2021-04-14 changed the return type of `SystemTools`
operations from `bool` to `Status`.  Update our call sites.
This may improve error reporting accuracy in a few places.
2021-04-14 13:14:09 -04:00
Brad King
7981602368 Merge topic 'openbsd-defines'
317a477283 OpenBSD: Fix system feature definitions

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6000
2021-04-14 11:04:30 -04:00
Rafael Sadowski
317a477283 OpenBSD: Fix system feature definitions
Since commit f034b0f663 (CMake compilation: do not use compiler
extensions, 2020-03-14, v3.18.0-rc1~494^2), some sources explicitly
enable needed system APIs on some platforms using definitions like
`_POSIX_C_SOURCE` and `_XOPEN_SOURCE`.  Drop the definitions for
OpenBSD, which provides the POSIX APIs by default.
2021-04-14 11:02:29 -04:00
Kyle Edwards
ad19da011d Refactor: Add cmSystemTools::GetSystemName()
And use it for CMAKE_HOST_SYSTEM_NAME and CMAKE_SYSTEM_NAME.
2021-03-15 14:41:42 -04:00
Ben Boeckel
100016e9cb cmSystemTools: add utilities to copy a file with error handling 2021-03-09 09:47:26 -05:00