At the top of each function that requires access to Makefile,
declare an alias `mf = this->Makefile`. Then replace all occurrences
of `this->Makefile->` with `mf.`. The intention is to make following
changes easier to review.
Instead of inheriting from `cmArgumentParser<void>` and binding arguments by
overriding `BindArguments`, define a struct for the arguments and instantiate
a static const parser in the `InitialPass` function of each command. Pass the
argument struct down to all functions that need to access it.
At the top of each function that requires access to arguments,
declare an alias `args = *this`. Then access all arguments with
`args.` rather than `this->`. The intention is to make following
changes easier to review.
Make sure that all classes have a public inherited constructor, protected
data members for the arguments, followed by other private virtual functions.
The intention is to make following changes to have a smaller diff.
KWSys's `CollapseFullPath` no longer maintains global state. The mutual
exclusion added by commit 51676cf655 (Autogen: Split JobEvalCacheT job
into separate moc and uic jobs, 2019-09-12, v3.16.0-rc1~94^2~7) and
commit 53d523f2e1 (autogen: fix race in depfile parsing, 2021-04-15,
v3.20.2~10^2) is no longer needed.
Prior to re-implementing `ToNormalizedPathOnDisk`, its use of KWSys's
`GetActualCaseForPathCached` cached file actual-case lookups to avoid
redundant filesystem access. Add caching to the actual-case lookups we
do for `cm::PathResolver`.
Use `cm::PathResolver`'s `LogicalPath` variant to normalize paths while
preserving symlinks not followed by `..` components. This avoids
needing the KWSys path translation map to preserve symlinks through
`realpath` operations. It also works with symlinks on Windows.
Fixes: #16228
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 1cfc8445570dc46883e84301eb6c31ebc5867826 (master).
Upstream Shortlog
-----------------
Brad King (1):
fdf4f2f8 SystemTools: Fix ReadSymlink for links to absolute paths on Windows
This behavior was removed when we switched to libuv in CMake 3.11.
After backporting new changes from libuv v2, we can restore the
behavior.
Fixes: #20115
Create a `cm::PathResolver` helper to compute normalized paths.
Provide a common implementation with compile-time dispatch to
select details w.r.t. symbolic links, existence, and matching
the on-disk case of existing paths. Later we can use this to
implement:
* `ToNormalizedPathOnDisk`: Normalizes paths while resolving symlinks
only when followed by `..` components. Does not require paths to
exist, but reads on-disk case of paths that do exist (on Windows).
* `GetRealPath`: Normalizes paths while resolving all symlinks.
Requires paths to exist, and reads their on-disk case (on Windows).
* `CollapseFullPath`: Normalizes paths in memory without disk access.
Assumes components followed by `..` components are not symlinks.
Abstract filesystem access through runtime dispatch so that we can test
Windows symbolic link and network path behavior without relying on real
environments. The overhead of runtime dispatch should be insignificant
during real filesystem access.
Issue: #16228
Issue: #17206