BUG: Do not escape shell operators when generating command lines.
- See bug#6868. - Update CustomCommand test to check.
This commit is contained in:
parent
3344ce9197
commit
c7d84b21c6
@ -2544,10 +2544,33 @@ std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
static bool cmLocalGeneratorIsShellOperator(const char* str)
|
||||||
|
{
|
||||||
|
if(strcmp(str, "<") == 0 ||
|
||||||
|
strcmp(str, ">") == 0 ||
|
||||||
|
strcmp(str, "<<") == 0 ||
|
||||||
|
strcmp(str, ">>") == 0 ||
|
||||||
|
strcmp(str, "|") == 0 ||
|
||||||
|
strcmp(str, "&>") == 0 ||
|
||||||
|
strcmp(str, "2>&1") == 0 ||
|
||||||
|
strcmp(str, "1>&2") == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
|
std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
|
||||||
bool forEcho)
|
bool forEcho)
|
||||||
{
|
{
|
||||||
|
// Do not escape shell operators.
|
||||||
|
if(cmLocalGeneratorIsShellOperator(str))
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the flags for the target shell environment.
|
// Compute the flags for the target shell environment.
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if(this->WindowsVSIDE)
|
if(this->WindowsVSIDE)
|
||||||
|
@ -150,6 +150,7 @@ ADD_EXECUTABLE(CustomCommand
|
|||||||
${PROJECT_BINARY_DIR}/wrapped_help.c
|
${PROJECT_BINARY_DIR}/wrapped_help.c
|
||||||
${PROJECT_BINARY_DIR}/generated.c
|
${PROJECT_BINARY_DIR}/generated.c
|
||||||
${PROJECT_BINARY_DIR}/not_included.h
|
${PROJECT_BINARY_DIR}/not_included.h
|
||||||
|
gen_redirect.c # default location for custom commands is in build tree
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add the rule to create generated.c at build time. This is placed
|
# Add the rule to create generated.c at build time. This is placed
|
||||||
@ -191,6 +192,17 @@ ADD_CUSTOM_COMMAND(TARGET CustomCommandUsingTargetTest POST_BUILD
|
|||||||
|
|
||||||
ADD_SUBDIRECTORY(GeneratorInExtraDir)
|
ADD_SUBDIRECTORY(GeneratorInExtraDir)
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Test shell operators in custom commands.
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(tcat tcat.cxx)
|
||||||
|
|
||||||
|
ADD_CUSTOM_COMMAND(OUTPUT gen_redirect.c
|
||||||
|
DEPENDS tcat gen_redirect_in.c
|
||||||
|
COMMAND tcat < ${CMAKE_CURRENT_SOURCE_DIR}/gen_redirect_in.c > gen_redirect.c
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> gen_redirect.c
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Test non-trivial command line arguments in custom commands.
|
# Test non-trivial command line arguments in custom commands.
|
||||||
@ -303,8 +315,8 @@ SET(CHECK_ARGS
|
|||||||
"one|pipe w s"
|
"one|pipe w s"
|
||||||
"#two-pounds# w s"
|
"#two-pounds# w s"
|
||||||
"one#pound w s"
|
"one#pound w s"
|
||||||
~ ` ! @ \# $ % ^ & _ - + = | : "\;" \" ' , . ? "(" ")" { } []
|
~ ` ! @ \# $ % ^ & _ - + = : "\;" \" ' , . ? "(" ")" { } []
|
||||||
# < > << >> &> 2>&1 1>&2
|
# | < > << >> &> 2>&1 1>&2
|
||||||
# \\ # Need to test last to avoid ; escape in list.
|
# \\ # Need to test last to avoid ; escape in list.
|
||||||
# # Make tools need help when this is the last argument.
|
# # Make tools need help when this is the last argument.
|
||||||
)
|
)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
ADD_DEFINITIONS(-DGENERATOR_EXTERN)
|
||||||
|
|
||||||
# add the executable which will be used for generating files
|
# add the executable which will be used for generating files
|
||||||
ADD_EXECUTABLE(generator_extern ../generator.cxx)
|
ADD_EXECUTABLE(generator_extern ../generator.cxx)
|
||||||
SET_TARGET_PROPERTIES(generator_extern PROPERTIES OUTPUT_NAME the_external_generator)
|
SET_TARGET_PROPERTIES(generator_extern PROPERTIES OUTPUT_NAME the_external_generator)
|
||||||
|
5
Tests/CustomCommand/gen_redirect_in.c
Normal file
5
Tests/CustomCommand/gen_redirect_in.c
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#if 1
|
||||||
|
|
||||||
|
int gen_redirect() { return 3; }
|
||||||
|
|
||||||
|
/* endif should be concatenated to generated file */
|
@ -8,8 +8,12 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
FILE *fp = fopen(argv[1],"w");
|
FILE *fp = fopen(argv[1],"w");
|
||||||
|
#ifdef GENERATOR_EXTERN
|
||||||
fprintf(fp,"int generated() { return 3; }\n");
|
fprintf(fp,"int generated() { return 3; }\n");
|
||||||
|
#else
|
||||||
|
fprintf(fp,"extern int gen_redirect(void);\n");
|
||||||
|
fprintf(fp,"int generated() { return gen_redirect(); }\n");
|
||||||
|
#endif
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
11
Tests/CustomCommand/tcat.cxx
Normal file
11
Tests/CustomCommand/tcat.cxx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
while((c = getc(stdin), c != EOF))
|
||||||
|
{
|
||||||
|
putc(c, stdout);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user