diff options
author | James Johnston <johnstonj.public@codenest.com> | 2015-08-05 04:33:59 (GMT) |
---|---|---|
committer | James Johnston <johnstonj.public@codenest.com> | 2015-08-06 17:53:34 (GMT) |
commit | d035e9687a2d28e2f64ec3a316f8abea57e49d63 (patch) | |
tree | d17e6d3fab9852d80996ef0909c1aa58421761ac | |
parent | 38ed5866ed212effe0217f193f728ee54ea7378b (diff) | |
download | CMake-d035e9687a2d28e2f64ec3a316f8abea57e49d63.zip CMake-d035e9687a2d28e2f64ec3a316f8abea57e49d63.tar.gz CMake-d035e9687a2d28e2f64ec3a316f8abea57e49d63.tar.bz2 |
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>
-rw-r--r-- | Source/cmGetFilenameComponentCommand.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/KnownComponents.cmake | 32 |
2 files changed, 34 insertions, 2 deletions
diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx index 67f9f2d..13a9afb 100644 --- a/Source/cmGetFilenameComponentCommand.cxx +++ b/Source/cmGetFilenameComponentCommand.cxx @@ -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()) { diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.cmake b/Tests/RunCMake/get_filename_component/KnownComponents.cmake index 1532792..386109f 100644 --- a/Tests/RunCMake/get_filename_component/KnownComponents.cmake +++ b/Tests/RunCMake/get_filename_component/KnownComponents.cmake @@ -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) |