[PATCH] D19423: [test-suite] Make unique name generation more robust.
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 11:30:11 PDT 2016
tra created this revision.
tra added reviewers: MatzeB, jmolloy.
tra added a subscriber: llvm-commits.
Using ${name} inside regex leads to issues when file name contains regex metacharacters ('+' is a common offender).
Use get_filename_component() to split off path components instead.
While we're at that, allow using all path components if necessary in order to create unique name.
http://reviews.llvm.org/D19423
Files:
cmake/modules/SingleMultiSource.cmake
Index: cmake/modules/SingleMultiSource.cmake
===================================================================
--- cmake/modules/SingleMultiSource.cmake
+++ cmake/modules/SingleMultiSource.cmake
@@ -24,7 +24,9 @@
get_property(registered_executables GLOBAL PROPERTY registered_executables)
string(REGEX REPLACE ".[cp]+$" "" path ${main_src})
- string(REGEX REPLACE ".*/" "" name ${path})
+ get_filename_component(name ${path} NAME )
+ get_filename_component(dir ${path} DIRECTORY)
+
list(FIND registered_executables ${name} name_idx)
if(${name_idx} EQUAL -1)
@@ -35,17 +37,19 @@
# There is a clash. Rename the target. Each time around the loop pull in
# a new path component.
- foreach(n RANGE 1 4)
- string(REGEX REPLACE ".*/([^/]+/${name})" "\\1" name ${path})
- string(REGEX REPLACE "/" "-" safe_name ${name})
+ while(dir)
+ get_filename_component(next_name ${dir} NAME)
+ get_filename_component(next_dir ${dir} DIRECTORY)
+ set(safe_name "${next_name}-${name}")
+ set(dir ${next_dir})
list(FIND registered_executables ${safe_name} name_idx)
if(${name_idx} EQUAL -1)
set(${new_name} ${safe_name} PARENT_SCOPE)
set_property(GLOBAL APPEND PROPERTY registered_executables ${safe_name})
return()
endif()
- endforeach()
+ endwhile()
message(FATAL_ERROR "Failed to uniquify executable name!")
endfunction()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19423.54681.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160422/7e5c8596/attachment.bin>
More information about the llvm-commits
mailing list