Merge topic 'generator-expression-bug-fixes'

7aa9927 GenEx: Don't use std::vector::at(int).
78e54b9 GenEx: Add tests for "0" and "1" expressions with literal commas.
d729e8b GenEx: Add test for $<BOOL:> with empty parameter.
354face GenEx: Ensure that the empty CONFIGURATION can be used conditionally.
8b3b88a GenEx: Validate target and property names.
b3d8f5d GenEx: Parse comma after colon tokens specially
a4985a9 GenEx: Report actual target name not found, not "0" each time.
d70650d GenEx: Return after error reported.
4801eb6 GenEx: It is not an error to specify an empty parameter
This commit is contained in:
Brad King 2012-10-09 08:40:07 -04:00 committed by CMake Topic Stage
commit 53c2dada1c
37 changed files with 260 additions and 15 deletions

View File

@ -173,7 +173,7 @@ static const struct StrEqualNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent *,
cmGeneratorExpressionDAGChecker *) const
{
return *parameters.begin() == parameters.at(1) ? "1" : "0";
return *parameters.begin() == parameters[1] ? "1" : "0";
}
} strEqualNode;
@ -237,11 +237,6 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const
{
if (!context->Config)
{
return std::string();
}
cmsys::RegularExpression configValidator;
configValidator.compile("^[A-Za-z0-9_]*$");
if (!configValidator.find(parameters.begin()->c_str()))
@ -250,6 +245,11 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
"Expression syntax not recognized.");
return std::string();
}
if (!context->Config)
{
return parameters.front().empty() ? "1" : "0";
}
return *parameters.begin() == context->Config ? "1" : "0";
}
} configurationTestNode;
@ -274,22 +274,69 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"$<TARGET_PROPERTY:...> expression requires one or two parameters");
return std::string();
}
cmsys::RegularExpression nameValidator;
nameValidator.compile("^[A-Za-z0-9_.-]+$");
cmGeneratorTarget* target = context->Target;
std::string propertyName = *parameters.begin();
if (parameters.size() == 2)
{
if (parameters.begin()->empty() && parameters[1].empty())
{
reportError(context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
"target name and property name.");
return std::string();
}
if (parameters.begin()->empty())
{
reportError(context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
"target name.");
return std::string();
}
std::string targetName = parameters.front();
propertyName = parameters[1];
if (!nameValidator.find(targetName.c_str()))
{
if (!nameValidator.find(propertyName.c_str()))
{
::reportError(context, content->GetOriginalExpression(),
"Target name and property name not supported.");
return std::string();
}
::reportError(context, content->GetOriginalExpression(),
"Target name not supported.");
return std::string();
}
target = context->Makefile->FindGeneratorTargetToUse(
parameters.begin()->c_str());
targetName.c_str());
if (!target)
{
cmOStringStream e;
e << "Target \""
<< target
<< targetName
<< "\" not found.";
reportError(context, content->GetOriginalExpression(), e.str());
return std::string();
}
propertyName = parameters.at(1);
}
if (propertyName.empty())
{
reportError(context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:...> expression requires a non-empty property "
"name.");
return std::string();
}
if (!nameValidator.find(propertyName.c_str()))
{
::reportError(context, content->GetOriginalExpression(),
"Property name not supported.");
return std::string();
}
cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,

View File

@ -118,10 +118,16 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
colonToken = this->it;
parameters.resize(parameters.size() + 1);
++this->it;
while (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
{
commaTokens.push_back(this->it);
parameters.resize(parameters.size() + 1);
++this->it;
}
while(this->it->TokenType != cmGeneratorExpressionToken::EndExpression)
{
this->ParseContent(*(parameters.end() - 1));
if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
while (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
{
commaTokens.push_back(this->it);
parameters.resize(parameters.size() + 1);
@ -142,10 +148,6 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
--this->NestingLevel;
++this->it;
}
if (parameters.empty())
{
// ERROR
}
}
if (nestedLevel != this->NestingLevel)

View File

@ -4,7 +4,9 @@ project(GeneratorExpression NONE)
add_custom_target(check ALL
COMMAND ${CMAKE_COMMAND}
-Dtest_0=$<0:nothing>
-Dtest_0_with_comma=$<0:-Wl,--no-undefined>
-Dtest_1=$<1:content>
-Dtest_1_with_comma=$<1:-Wl,--no-undefined>
-Dconfig=$<CONFIGURATION>
-Dtest_and_0=$<AND:0>
-Dtest_and_0_0=$<AND:0,0>
@ -30,6 +32,7 @@ add_custom_target(check ALL
-Dtest_bool_off=$<BOOL:Off>
-Dtest_bool_no=$<BOOL:No>
-Dtest_bool_n=$<BOOL:N>
-Dtest_bool_empty=$<BOOL:>
-Dtest_strequal_yes_yes=$<STREQUAL:Yes,Yes>
-Dtest_strequal_yes_yes_cs=$<STREQUAL:Yes,yes>
-Dtest_strequal_yes_no=$<STREQUAL:Yes,No>
@ -37,6 +40,8 @@ add_custom_target(check ALL
-Dtest_strequal_angle_r=$<STREQUAL:$<ANGLE-R>,$<ANGLE-R>>
-Dtest_strequal_comma=$<STREQUAL:$<COMMA>,$<COMMA>>
-Dtest_strequal_angle_r_comma=$<STREQUAL:$<ANGLE-R>,$<COMMA>>
-Dtest_strequal_both_empty=$<STREQUAL:,>
-Dtest_strequal_one_empty=$<STREQUAL:something,>
-Dtest_angle_r=$<ANGLE-R>
-Dtest_comma=$<COMMA>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake

View File

@ -6,7 +6,9 @@ endmacro()
message(STATUS "config=[${config}]")
check(test_0 "")
check(test_0_with_comma "")
check(test_1 "content")
check(test_1_with_comma "-Wl,--no-undefined")
check(test_and_0 "0")
check(test_and_0_0 "0")
check(test_and_0_1 "0")
@ -31,6 +33,7 @@ check(test_bool_on "1")
check(test_bool_off "0")
check(test_bool_no "0")
check(test_bool_n "0")
check(test_bool_empty "0")
check(test_strequal_yes_yes "1")
check(test_strequal_yes_yes_cs "0")
check(test_strequal_yes_no "0")
@ -38,5 +41,7 @@ check(test_strequal_no_yes "0")
check(test_strequal_angle_r "1")
check(test_strequal_comma "1")
check(test_strequal_angle_r_comma "0")
check(test_strequal_both_empty "1")
check(test_strequal_one_empty "0")
check(test_angle_r ">")
check(test_comma ",")

View File

@ -20,7 +20,7 @@ CMake Error at BadNOT.cmake:1 \(add_custom_target\):
\$<NOT:,>
\$<NOT> parameter must resolve to exactly one '0' or '1' value.
\$<NOT> expression requires exactly one parameter.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,38 @@
CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<STREQUAL>
\$<STREQUAL> expression requires 2 comma separated parameters, but got 0
instead.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<STREQUAL:>
\$<STREQUAL> expression requires 2 comma separated parameters, but got 1
instead.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<STREQUAL:,,>
\$<STREQUAL> expression requires 2 comma separated parameters, but got 3
instead.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<STREQUAL:something,,>
\$<STREQUAL> expression requires 2 comma separated parameters, but got 3
instead.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@ -0,0 +1,6 @@
add_custom_target(check ALL COMMAND check
$<STREQUAL>
$<STREQUAL:>
$<STREQUAL:,,>
$<STREQUAL:something,,>
VERBATIM)

View File

@ -4,3 +4,4 @@ run_cmake(BadCONFIG)
run_cmake(BadOR)
run_cmake(BadAND)
run_cmake(BadNOT)
run_cmake(BadStrEqual)

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>
Target name not supported.

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>
Target name and property name not supported.$

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dProperty>
Property name not supported.$

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:Invali/dProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:foo,Invali/dProperty>
Property name not supported.$

View File

@ -0,0 +1,9 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:foo,Invali/dProperty>")

View File

@ -0,0 +1,7 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:,>
\$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name and
property name.

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:,>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:,ValidProperty>
\$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name.

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:,ValidProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:foo,>
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.

View File

@ -0,0 +1,9 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:foo,>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:>
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:NonExistant,INCLUDE_DIRECTORIES>
Target "NonExistant" not found.$

View File

@ -0,0 +1,7 @@
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
"int main(int, char **) { return 0; }\n")
add_executable(TargetPropertyGeneratorExpressions
"${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
include_directories("$<TARGET_PROPERTY:NonExistant,INCLUDE_DIRECTORIES>")

View File

@ -6,3 +6,12 @@ run_cmake(BadSelfReference3)
run_cmake(BadSelfReference4)
run_cmake(BadSelfReference5)
run_cmake(BadSelfReference6)
run_cmake(BadNonTarget)
run_cmake(BadInvalidName1)
run_cmake(BadInvalidName2)
run_cmake(BadInvalidName3)
run_cmake(BadInvalidName4)
run_cmake(BadInvalidName5)
run_cmake(BadInvalidName6)
run_cmake(BadInvalidName7)
run_cmake(BadInvalidName8)