From cb01b8c8ba1754b40e74d89d2c6dfef5dc8c44d3 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 31 Jan 2019 19:26:14 -0500 Subject: [PATCH] set: warn of extra arguments after ENV value. Fixes: #18842 --- Help/command/set.rst | 9 ++++++++- Source/cmSetCommand.cxx | 8 ++++++++ Tests/RunCMake/set/ExtraEnvValue-stderr.txt | 6 ++++++ Tests/RunCMake/set/ExtraEnvValue.cmake | 1 + Tests/RunCMake/set/RunCMakeTest.cmake | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/set/ExtraEnvValue-stderr.txt create mode 100644 Tests/RunCMake/set/ExtraEnvValue.cmake diff --git a/Help/command/set.rst b/Help/command/set.rst index dd5ea133be..c0e02e2465 100644 --- a/Help/command/set.rst +++ b/Help/command/set.rst @@ -86,7 +86,7 @@ Set Environment Variable .. code-block:: cmake - set(ENV{} ...) + set(ENV{} []) Sets an :manual:`Environment Variable ` to the given value. @@ -95,3 +95,10 @@ Subsequent calls of ``$ENV{}`` will return this new value. This command affects only the current CMake process, not the process from which CMake was called, nor the system environment at large, nor the environment of subsequent build or test processes. + +If no argument is given after ``ENV{}`` or if ```` is +an empty string, then this command will clear any existing value of the +environment variable. + +Arguments after ```` are ignored. If extra arguments are found, +then an author warning is issued. diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index b09e3ca3a0..6bd071cfb1 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -38,6 +38,14 @@ bool cmSetCommand::InitialPass(std::vector const& args, putEnvArg += args[1]; cmSystemTools::PutEnv(putEnvArg); } + // if there's extra arguments, warn user + // that they are ignored by this command. + if (args.size() > 2) { + std::string m = "Only the first value argument is used when setting " + "an environment variable. Argument '" + + args[2] + "' and later are unused."; + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m); + } return true; } diff --git a/Tests/RunCMake/set/ExtraEnvValue-stderr.txt b/Tests/RunCMake/set/ExtraEnvValue-stderr.txt new file mode 100644 index 0000000000..f61f9d287b --- /dev/null +++ b/Tests/RunCMake/set/ExtraEnvValue-stderr.txt @@ -0,0 +1,6 @@ +CMake Warning \(dev\) at ExtraEnvValue.cmake:1 \(set\): + Only the first value argument is used when setting an environment variable. + Argument 'value_2' and later are unused. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/set/ExtraEnvValue.cmake b/Tests/RunCMake/set/ExtraEnvValue.cmake new file mode 100644 index 0000000000..768a6eac2e --- /dev/null +++ b/Tests/RunCMake/set/ExtraEnvValue.cmake @@ -0,0 +1 @@ +set (ENV{sample_key} value_1 value_2) diff --git a/Tests/RunCMake/set/RunCMakeTest.cmake b/Tests/RunCMake/set/RunCMakeTest.cmake index ea63d0bdc4..b3bd0a4807 100644 --- a/Tests/RunCMake/set/RunCMakeTest.cmake +++ b/Tests/RunCMake/set/RunCMakeTest.cmake @@ -4,3 +4,4 @@ run_cmake(ParentScope) run_cmake(ParentPulling) run_cmake(ParentPullingRecursive) run_cmake(UnknownCacheType) +run_cmake(ExtraEnvValue)