get_filename_component: Fix bug where CACHE was ignored.

If PROGRAM_ARGS is provided to get_filename_component, fix bug where the
command failed to honor the CACHE argument.

Added test cases to RunCMake.get_filename_component that fail when the
bug is not fixed to prevent regressions.

Signed-off-by: James Johnston <johnstonj.public@codenest.com>
This commit is contained in:
James Johnston 2015-08-05 00:33:59 -04:00
parent 38ed5866ed
commit d035e9687a
2 changed files with 34 additions and 2 deletions

View File

@ -24,7 +24,7 @@ bool cmGetFilenameComponentCommand
// Check and see if the value has been stored in the cache
// already, if so use that value
if(args.size() == 4 && args[3] == "CACHE")
if(args.size() >= 4 && args[args.size() - 1] == "CACHE")
{
const char* cacheValue = this->Makefile->GetDefinition(args[0]);
if(cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue))
@ -111,7 +111,7 @@ bool cmGetFilenameComponentCommand
return false;
}
if(args.size() == 4 && args[3] == "CACHE")
if(args.size() >= 4 && args[args.size() - 1] == "CACHE")
{
if(!programArgs.empty() && !storeArgs.empty())
{

View File

@ -62,6 +62,38 @@ check("CACHE 3" "${test_cache}" "/path/to/other")
list(APPEND cache_vars test_cache)
# Test the PROGRAM component type with CACHE specified.
# 1. Make sure it makes a cache variable in the first place for basic usage:
get_filename_component(test_cache_program_name_1 "/ arg1 arg2" PROGRAM CACHE)
check("PROGRAM CACHE 1 with no args output" "${test_cache_program_name_1}" "/")
list(APPEND cache_vars test_cache_program_name_1)
# 2. Set some existing cache variables & make sure the function returns them:
set(test_cache_program_name_2 DummyProgramName CACHE FILEPATH "")
get_filename_component(test_cache_program_name_2 "/ arg1 arg2" PROGRAM CACHE)
check("PROGRAM CACHE 2 with no args output" "${test_cache_program_name_2}"
"DummyProgramName")
list(APPEND cache_vars test_cache_program_name_2)
# 3. Now test basic usage when PROGRAM_ARGS is used:
get_filename_component(test_cache_program_name_3 "/ arg1 arg2" PROGRAM
PROGRAM_ARGS test_cache_program_args_3 CACHE)
check("PROGRAM CACHE 3 name" "${test_cache_program_name_3}" "/")
check("PROGRAM CACHE 3 args" "${test_cache_program_args_3}" " arg1 arg2")
list(APPEND cache_vars test_cache_program_name_3)
list(APPEND cache_vars test_cache_program_args_3)
# 4. Test that existing cache variables are returned when PROGRAM_ARGS is used:
set(test_cache_program_name_4 DummyPgm CACHE FILEPATH "")
set(test_cache_program_args_4 DummyArgs CACHE STRING "")
get_filename_component(test_cache_program_name_4 "/ arg1 arg2" PROGRAM
PROGRAM_ARGS test_cache_program_args_4 CACHE)
check("PROGRAM CACHE 4 name" "${test_cache_program_name_4}" "DummyPgm")
check("PROGRAM CACHE 4 args" "${test_cache_program_args_4}" "DummyArgs")
list(APPEND cache_vars test_cache_program_name_4)
list(APPEND cache_vars test_cache_program_name_4)
# Test that ONLY the expected cache variables were created.
get_cmake_property(current_cache_vars CACHE_VARIABLES)
get_cmake_property(current_vars VARIABLES)