mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 03:48:02 +08:00
add_custom_target: Add output checks for custom target byproducts
Use the output checks for byproducts of add_custom_command also for byproducts of add_custom_target.
This commit is contained in:
@@ -168,6 +168,8 @@ set(SRCS
|
|||||||
cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h
|
cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h
|
||||||
cmCacheManager.cxx
|
cmCacheManager.cxx
|
||||||
cmCacheManager.h
|
cmCacheManager.h
|
||||||
|
cmCheckCustomOutputs.h
|
||||||
|
cmCheckCustomOutputs.cxx
|
||||||
cmCLocaleEnvironmentScope.h
|
cmCLocaleEnvironmentScope.h
|
||||||
cmCLocaleEnvironmentScope.cxx
|
cmCLocaleEnvironmentScope.cxx
|
||||||
cmCommandArgumentParserHelper.cxx
|
cmCommandArgumentParserHelper.cxx
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include "cmCheckCustomOutputs.h"
|
||||||
#include "cmCustomCommand.h"
|
#include "cmCustomCommand.h"
|
||||||
#include "cmCustomCommandLines.h"
|
#include "cmCustomCommandLines.h"
|
||||||
#include "cmExecutionStatus.h"
|
#include "cmExecutionStatus.h"
|
||||||
@@ -16,9 +17,6 @@
|
|||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
|
|
||||||
static bool cmAddCustomCommandCommandCheckOutputs(
|
|
||||||
const std::vector<std::string>& outputs, cmExecutionStatus& status);
|
|
||||||
|
|
||||||
bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
@@ -307,9 +305,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the output names and locations are safe.
|
// Make sure the output names and locations are safe.
|
||||||
if (!cmAddCustomCommandCommandCheckOutputs(output, status) ||
|
if (!cmCheckCustomOutputs(output, "OUTPUT", status) ||
|
||||||
!cmAddCustomCommandCommandCheckOutputs(outputs, status) ||
|
!cmCheckCustomOutputs(outputs, "OUTPUTS", status) ||
|
||||||
!cmAddCustomCommandCommandCheckOutputs(byproducts, status)) {
|
!cmCheckCustomOutputs(byproducts, "BYPRODUCTS", status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,29 +385,3 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
return true;
|
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\n\"" + o +
|
|
||||||
"\"\nin 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;
|
|
||||||
}
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "cmCheckCustomOutputs.h"
|
||||||
#include "cmCustomCommandLines.h"
|
#include "cmCustomCommandLines.h"
|
||||||
#include "cmExecutionStatus.h"
|
#include "cmExecutionStatus.h"
|
||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
@@ -205,6 +206,11 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
|
|||||||
return false;
|
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.
|
// Add the utility target to the makefile.
|
||||||
bool escapeOldStyle = !verbatim;
|
bool escapeOldStyle = !verbatim;
|
||||||
cmTarget* target = mf.AddUtilityCommand(
|
cmTarget* target = mf.AddUtilityCommand(
|
||||||
|
36
Source/cmCheckCustomOutputs.cxx
Normal file
36
Source/cmCheckCustomOutputs.cxx
Normal file
@@ -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;
|
||||||
|
}
|
18
Source/cmCheckCustomOutputs.h
Normal file
18
Source/cmCheckCustomOutputs.h
Normal file
@@ -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
|
@@ -1,27 +1,27 @@
|
|||||||
CMake Error at BadByproduct.cmake:2 \(add_custom_command\):
|
CMake Error at BadByproduct.cmake:2 \(add_custom_command\):
|
||||||
add_custom_command called with OUTPUT containing a "#". This character is
|
add_custom_command called with BYPRODUCTS containing a "#". This character
|
||||||
not allowed.
|
is not allowed.
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadByproduct.cmake:3 \(add_custom_command\):
|
CMake Error at BadByproduct.cmake:3 \(add_custom_command\):
|
||||||
add_custom_command called with OUTPUT containing a "<". This character is
|
add_custom_command called with BYPRODUCTS containing a "<". This character
|
||||||
not allowed.
|
is not allowed.
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadByproduct.cmake:4 \(add_custom_command\):
|
CMake Error at BadByproduct.cmake:4 \(add_custom_command\):
|
||||||
add_custom_command called with OUTPUT containing a ">". This character is
|
add_custom_command called with BYPRODUCTS containing a ">". This character
|
||||||
not allowed.
|
is not allowed.
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadByproduct.cmake:5 \(add_custom_command\):
|
CMake Error at BadByproduct.cmake:5 \(add_custom_command\):
|
||||||
add_custom_command called with OUTPUT containing a "<". This character is
|
add_custom_command called with BYPRODUCTS containing a "<". This character
|
||||||
not allowed.
|
is not allowed.
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
1
Tests/RunCMake/add_custom_target/BadByproduct-result.txt
Normal file
1
Tests/RunCMake/add_custom_target/BadByproduct-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
36
Tests/RunCMake/add_custom_target/BadByproduct-stderr.txt
Normal file
36
Tests/RunCMake/add_custom_target/BadByproduct-stderr.txt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
CMake Error at BadByproduct.cmake:2 \(add_custom_target\):
|
||||||
|
add_custom_target called with BYPRODUCTS containing a "#". This character
|
||||||
|
is not allowed.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
|
CMake Error at BadByproduct.cmake:3 \(add_custom_target\):
|
||||||
|
add_custom_target called with BYPRODUCTS containing a "<". This character
|
||||||
|
is not allowed.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
|
CMake Error at BadByproduct.cmake:4 \(add_custom_target\):
|
||||||
|
add_custom_target called with BYPRODUCTS containing a ">". This character
|
||||||
|
is not allowed.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
|
CMake Error at BadByproduct.cmake:5 \(add_custom_target\):
|
||||||
|
add_custom_target called with BYPRODUCTS containing a "<". This character
|
||||||
|
is not allowed.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
|
CMake Error at BadByproduct.cmake:6 \(add_custom_target\):
|
||||||
|
add_custom_target attempted to have a file
|
||||||
|
|
||||||
|
.*/j".*
|
||||||
|
|
||||||
|
in a source directory as an output of custom command.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
6
Tests/RunCMake/add_custom_target/BadByproduct.cmake
Normal file
6
Tests/RunCMake/add_custom_target/BadByproduct.cmake
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
||||||
|
add_custom_target(a BYPRODUCTS "a#" COMMAND b)
|
||||||
|
add_custom_target(c BYPRODUCTS "a<" COMMAND d)
|
||||||
|
add_custom_target(e BYPRODUCTS "a>" COMMAND f)
|
||||||
|
add_custom_target(g BYPRODUCTS "$<CONFIG>/#" COMMAND h)
|
||||||
|
add_custom_target(i BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/j COMMAND k)
|
@@ -1,11 +1,12 @@
|
|||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
run_cmake(CommandExpandsEmpty)
|
run_cmake(BadByproduct)
|
||||||
run_cmake(GeneratedProperty)
|
|
||||||
run_cmake(NoArguments)
|
|
||||||
run_cmake(BadTargetName)
|
run_cmake(BadTargetName)
|
||||||
run_cmake(ByproductsNoCommand)
|
run_cmake(ByproductsNoCommand)
|
||||||
|
run_cmake(CommandExpandsEmpty)
|
||||||
|
run_cmake(GeneratedProperty)
|
||||||
run_cmake(LiteralQuotes)
|
run_cmake(LiteralQuotes)
|
||||||
|
run_cmake(NoArguments)
|
||||||
run_cmake(UsesTerminalNoCommand)
|
run_cmake(UsesTerminalNoCommand)
|
||||||
|
|
||||||
function(run_TargetOrder)
|
function(run_TargetOrder)
|
||||||
|
@@ -278,6 +278,7 @@ CMAKE_CXX_SOURCES="\
|
|||||||
cmCMakePolicyCommand \
|
cmCMakePolicyCommand \
|
||||||
cmCPackPropertiesGenerator \
|
cmCPackPropertiesGenerator \
|
||||||
cmCacheManager \
|
cmCacheManager \
|
||||||
|
cmCheckCustomOutputs \
|
||||||
cmCommand \
|
cmCommand \
|
||||||
cmCommandArgumentParserHelper \
|
cmCommandArgumentParserHelper \
|
||||||
cmCommands \
|
cmCommands \
|
||||||
|
Reference in New Issue
Block a user