From f320a31087c4efc07e7d10b621ec45dd0350c83a Mon Sep 17 00:00:00 2001 From: Carsten Rudolph <18394207+crud89@users.noreply.github.com> Date: Tue, 15 Feb 2022 10:25:53 +0100 Subject: cmake --build: prioritize --resolve-package-references over preset Fixes: #23224 --- Help/manual/cmake-presets.7.rst | 21 ++++++++++----------- Help/manual/cmake.1.rst | 13 ++++++------- Source/cmBuildOptions.h | 18 +++++++++--------- Source/cmGlobalVisualStudio10Generator.cxx | 2 +- Source/cmake.cxx | 3 ++- Source/cmakemain.cxx | 2 +- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 31bd9c0..346e821 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -498,17 +498,16 @@ that may contain the following fields: .. note:: - If this setting is not specified in a preset, CMake will instead - use the setting specified by the ``--resolve-package-references`` - command line parameter. If the command line parameter is not - provided either, an environment-specific cache variable will be - evaluated to decide, if package restoration should be performed. - - When using the Visual Studio generator, package references are - defined using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. - Package references are restored using NuGet. It can be disabled - by setting the ``CMAKE_VS_NUGET_PACKAGE_RESTORE`` variable to - ``OFF``. This can also be done from within a configure preset. + The command line parameter ``--resolve-package-references`` will take + priority over this setting. If the command line parameter is not provided + and this setting is not specified, an environment-specific cache variable + will be evaluated to decide, if package restoration should be performed. + + When using the Visual Studio generator, package references are defined + using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references + are restored using NuGet. It can be disabled by setting the + ``CMAKE_VS_NUGET_PACKAGE_RESTORE`` variable to ``OFF``. This can also be + done from within a configure preset. ``verbose`` diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 7eb7dec..c68e7a9 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -472,16 +472,15 @@ following options: target. When set to ``only``, the packages will be restored, but no build will be performed. When set to ``off``, no packages will be restored. - If the target does not define any package references, this option does - nothing. + If the target does not define any package references, this option does nothing. This setting can be specified in a build preset (using - ``resolvePackageReferences``). In this case, the command line option will - be ignored. + ``resolvePackageReferences``). The preset setting will be ignored, if this + command line option is specified. - If the no command line parameter or preset option is not provided, an - environment-specific cache variable will be evaluated to decide, if package - restoration should be performed. + If no command line parameter or preset option are provided, an environment- + specific cache variable will be evaluated to decide, if package restoration + should be performed. When using the Visual Studio generator, package references are defined using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references diff --git a/Source/cmBuildOptions.h b/Source/cmBuildOptions.h index 58baeef..aa3184e 100644 --- a/Source/cmBuildOptions.h +++ b/Source/cmBuildOptions.h @@ -7,20 +7,20 @@ /** \brief Defines how to resolve packages **/ enum class PackageResolveMode { - /** \brief Defines behavior based on cache variable (e.g. + /** \brief Behavior is defined by preset or cache variable (e.g. CMAKE_VS_NUGET_PACKAGE_RESTORE). This is the default. **/ - FromCacheVariable, + Default, - /** \brief Ignore behavior defined by cache variable and forces packages to - be resolved prior to build. **/ + /** \brief Ignore behavior defined by preset or cache variable and forces + packages to be resolved prior to build. **/ Force, - /** \brief Ignore behavior defined by cache variable and forces packages to - be resolved, but skip the actual build. **/ + /** \brief Ignore behavior defined by preset or cache variable and forces + packages to be resolved, but skip the actual build. **/ OnlyResolve, - /** \brief Ignore behavior defined by cache variable and dont resolve any - packages **/ + /** \brief Ignore behavior defined by preset or cache variable and don't + resolve any packages **/ Disable }; @@ -40,5 +40,5 @@ public: bool Clean = false; bool Fast = false; - PackageResolveMode ResolveMode = PackageResolveMode::FromCacheVariable; + PackageResolveMode ResolveMode = PackageResolveMode::Default; }; diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index a96f6f0..db54b86 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -1222,7 +1222,7 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand( "Studio 2017 and later. You have to manually restore the " "packages using NuGet before building the project."); restorePackages = false; - } else if (restoreMode == PackageResolveMode::FromCacheVariable) { + } else if (restoreMode == PackageResolveMode::Default) { // Decide if a restore is performed, based on a cache variable. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue( diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ef4e37b..e1ba12c 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3356,7 +3356,8 @@ int cmake::Build(int jobs, std::string dir, std::vector targets, buildOptions.Clean = *expandedPreset->CleanFirst; } - if (expandedPreset->ResolvePackageReferences) { + if (buildOptions.ResolveMode == PackageResolveMode::Default && + expandedPreset->ResolvePackageReferences) { buildOptions.ResolveMode = *expandedPreset->ResolvePackageReferences; } diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index f3d5536..0554c3e 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -447,7 +447,7 @@ int do_build(int ac, char const* const* av) bool cleanFirst = false; bool foundClean = false; bool foundNonClean = false; - PackageResolveMode resolveMode = PackageResolveMode::FromCacheVariable; + PackageResolveMode resolveMode = PackageResolveMode::Default; bool verbose = cmSystemTools::HasEnv("VERBOSE"); std::string presetName; bool listPresets = false; -- cgit v0.12 From d92469e57210d6b4e9a2733d3477ae44a6cf9735 Mon Sep 17 00:00:00 2001 From: Carsten Rudolph <18394207+crud89@users.noreply.github.com> Date: Tue, 15 Feb 2022 10:16:38 +0100 Subject: Help: Clarify how package resolve mode is intended to be used Fixes: #23223 --- Help/manual/cmake-presets.7.rst | 7 ++++--- Help/manual/cmake.1.rst | 8 ++++---- Help/release/3.23.rst | 5 ++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 346e821..69d0543 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -479,9 +479,10 @@ that may contain the following fields: An optional string that specifies the package resolve mode. This is allowed in preset files specifying version ``4`` or above. - This field overwrites the ``--resolve-package-references`` command line - parameter. If there are no targets that define package references, this - option does nothing. Valid values are: + Package references are used to define dependencies to packages from + external package managers. Currently only NuGet in combination with the + Visual Studio generator is supported. If there are no targets that define + package references, this option does nothing. Valid values are: ``on`` diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index c68e7a9..f7d4f6b 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -467,10 +467,10 @@ following options: ``--resolve-package-references=`` .. versionadded:: 3.23 - Resolve remote package references (e.g. NuGet packages) before build. - When set to ``on`` (default), packages will be restored before building a - target. When set to ``only``, the packages will be restored, but no build - will be performed. When set to ``off``, no packages will be restored. + Resolve remote package references from external package managers (e.g. NuGet) + before build. When set to ``on`` (default), packages will be restored before + building a target. When set to ``only``, the packages will be restored, but no + build will be performed. When set to ``off``, no packages will be restored. If the target does not define any package references, this option does nothing. diff --git a/Help/release/3.23.rst b/Help/release/3.23.rst index cce936b..b2928db 100644 --- a/Help/release/3.23.rst +++ b/Help/release/3.23.rst @@ -19,7 +19,10 @@ Presets which allows the files to include other files. * :manual:`cmake-presets(7)` gained support for specifying the - ``resolvePackageReferences`` command line option in a build preset. + ``resolvePackageReferences`` command line option in a build preset to control + restoration behavior of package references from external package managers. + Currently this is only supported by the Visual Studio generator to support + restoring packages from NuGet. Other generators ignore this option. Generators ---------- -- cgit v0.12