diff options
author | Brad King <brad.king@kitware.com> | 2019-09-26 13:47:41 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-09-26 13:47:51 (GMT) |
commit | df982c4e189c01896db487ec5edfe85d27911007 (patch) | |
tree | fa4cc82d4a051321e7b3b14c130c8d6d45f9f63d /Source | |
parent | 5fa625d611414ac567fd7a6bb5b3b416ea93eca2 (diff) | |
parent | fd3a39461457540157ea9bee2f9ea7620dfd1c7f (diff) | |
download | CMake-df982c4e189c01896db487ec5edfe85d27911007.zip CMake-df982c4e189c01896db487ec5edfe85d27911007.tar.gz CMake-df982c4e189c01896db487ec5edfe85d27911007.tar.bz2 |
Merge topic 'add-custom-target-byproduct-checks'
fd3a394614 add_custom_command: Format files in error message in a single line
a1cc6b4447 add_custom_target: Add output checks for custom target byproducts
cbb861ade8 add_custom_command: Add tests for custom command output checks
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3850
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 40 | ||||
-rw-r--r-- | Source/cmAddCustomTargetCommand.cxx | 6 | ||||
-rw-r--r-- | Source/cmCheckCustomOutputs.cxx | 36 | ||||
-rw-r--r-- | Source/cmCheckCustomOutputs.h | 18 |
5 files changed, 68 insertions, 34 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 8ed7b2f..71a7dbd 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -168,6 +168,8 @@ set(SRCS cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h cmCacheManager.cxx cmCacheManager.h + cmCheckCustomOutputs.h + cmCheckCustomOutputs.cxx cmCLocaleEnvironmentScope.h cmCLocaleEnvironmentScope.cxx cmCommandArgumentParserHelper.cxx diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 35db6a4..94de851 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -5,6 +5,7 @@ #include <sstream> #include <unordered_set> +#include "cmCheckCustomOutputs.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" @@ -16,9 +17,6 @@ #include "cmSystemTools.h" #include "cmTarget.h" -static bool cmAddCustomCommandCommandCheckOutputs( - const std::vector<std::string>& outputs, cmExecutionStatus& status); - bool cmAddCustomCommandCommand(std::vector<std::string> const& args, cmExecutionStatus& status) { @@ -307,9 +305,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, } // Make sure the output names and locations are safe. - if (!cmAddCustomCommandCommandCheckOutputs(output, status) || - !cmAddCustomCommandCommandCheckOutputs(outputs, status) || - !cmAddCustomCommandCommandCheckOutputs(byproducts, status)) { + if (!cmCheckCustomOutputs(output, "OUTPUT", status) || + !cmCheckCustomOutputs(outputs, "OUTPUTS", status) || + !cmCheckCustomOutputs(byproducts, "BYPRODUCTS", status)) { return false; } @@ -322,8 +320,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, // No command for this output exists. status.SetError( - cmStrCat("given APPEND option with output\n\"", output[0], - "\"\nwhich is not already a custom command output.")); + cmStrCat("given APPEND option with output\n ", output[0], + "\nwhich is not already a custom command output.")); return false; } @@ -387,29 +385,3 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, return true; } - -bool cmAddCustomCommandCommandCheckOutputs( - const std::vector<std::string>& outputs, cmExecutionStatus& status) -{ - cmMakefile& mf = status.GetMakefile(); - for (std::string const& o : outputs) { - // Make sure the file will not be generated into the source - // directory during an out of source build. - if (!mf.CanIWriteThisFile(o)) { - std::string e = "attempted to have a file \"" + o + - "\" in a source directory as an output of custom command."; - status.SetError(e); - cmSystemTools::SetFatalErrorOccured(); - return false; - } - - // Make sure the output file name has no invalid characters. - std::string::size_type pos = o.find_first_of("#<>"); - if (pos != std::string::npos) { - status.SetError(cmStrCat("called with OUTPUT containing a \"", o[pos], - "\". This character is not allowed.")); - return false; - } - } - return true; -} diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 9fd1234..b580c43 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -4,6 +4,7 @@ #include <utility> +#include "cmCheckCustomOutputs.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" @@ -205,6 +206,11 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, return false; } + // Make sure the byproduct names and locations are safe. + if (!cmCheckCustomOutputs(byproducts, "BYPRODUCTS", status)) { + return false; + } + // Add the utility target to the makefile. bool escapeOldStyle = !verbatim; cmTarget* target = mf.AddUtilityCommand( diff --git a/Source/cmCheckCustomOutputs.cxx b/Source/cmCheckCustomOutputs.cxx new file mode 100644 index 0000000..7645c88 --- /dev/null +++ b/Source/cmCheckCustomOutputs.cxx @@ -0,0 +1,36 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCheckCustomOutputs.h" + +#include "cmExecutionStatus.h" +#include "cmMakefile.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" + +bool cmCheckCustomOutputs(const std::vector<std::string>& outputs, + cm::string_view keyword, cmExecutionStatus& status) +{ + cmMakefile& mf = status.GetMakefile(); + + for (std::string const& o : outputs) { + // Make sure the file will not be generated into the source + // directory during an out of source build. + if (!mf.CanIWriteThisFile(o)) { + status.SetError( + cmStrCat("attempted to have a file\n ", o, + "\nin a source directory as an output of custom command.")); + cmSystemTools::SetFatalErrorOccured(); + return false; + } + + // Make sure the output file name has no invalid characters. + std::string::size_type pos = o.find_first_of("#<>"); + if (pos != std::string::npos) { + status.SetError(cmStrCat("called with ", keyword, " containing a \"", + o[pos], "\". This character is not allowed.")); + return false; + } + } + + return true; +} diff --git a/Source/cmCheckCustomOutputs.h b/Source/cmCheckCustomOutputs.h new file mode 100644 index 0000000..7c4b3fe --- /dev/null +++ b/Source/cmCheckCustomOutputs.h @@ -0,0 +1,18 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCheckCustomOutputs_h +#define cmCheckCustomOutputs_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <cm/string_view> + +#include <string> +#include <vector> + +class cmExecutionStatus; + +bool cmCheckCustomOutputs(const std::vector<std::string>& outputs, + cm::string_view keyword, cmExecutionStatus& status); + +#endif |