[Cmake-commits] [cmake-commits] king committed CMakeLists.txt 1.7 1.8 GetFilenameComponentRealpathTest.cmake.in NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Feb 9 09:23:57 EST 2009


Update of /cvsroot/CMake/CMake/Tests/CMakeTests
In directory public:/mounts/ram/cvs-serv31677/Tests/CMakeTests

Modified Files:
	CMakeLists.txt 
Added Files:
	GetFilenameComponentRealpathTest.cmake.in 
Log Message:
ENH: Add get_filename_component(... REALPATH)

This patch from Philip Lowman creates a REALPATH mode in the
get_filename_component command.  It is like ABSOLUTE, but will also
resolve symlinks (which ABSOLUTE once did but was broken long ago).
See issue #8423.


Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Tests/CMakeTests/CMakeLists.txt,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** CMakeLists.txt	6 Feb 2009 13:33:52 -0000	1.7
--- CMakeLists.txt	9 Feb 2009 14:23:55 -0000	1.8
***************
*** 15,18 ****
--- 15,19 ----
  AddCMakeTest(FindBase "")
  AddCMakeTest(Toolchain "")
+ AddCMakeTest(GetFilenameComponentRealpath "")
  
  SET(GetPrerequisites_PreArgs

--- NEW FILE: GetFilenameComponentRealpathTest.cmake.in ---
set(bindir ${CMAKE_CURRENT_BINARY_DIR})

#
# Test nonexistent REALPATH & ABSOLUTE resolution
#
get_filename_component(nonexistent1 ${bindir}/THIS_IS_A_NONEXISTENT_FILE REALPATH)
get_filename_component(nonexistent2 ${bindir}/THIS_IS_A_NONEXISTENT_FILE ABSOLUTE)
if(NOT nonexistent1 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
    message(FATAL_ERROR "REALPATH is not preserving nonexistent files")
endif()
if(NOT nonexistent2 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
    message(FATAL_ERROR "ABSOLUTE is not preserving nonexistent files")
endif()

#
# Test symbolic link resolution
#
if(UNIX)
    # file1 => file2 => file3 (real)
    file(WRITE ${bindir}/file3 "test file")

    find_program(LN NAMES "ln")
    if(LN)
        # Create symlinks using "ln -s"
        if(NOT EXISTS ${bindir}/file2)
            execute_process(COMMAND ${LN} "-s" "${bindir}/file3" "${bindir}/file2")
        endif()
        if(NOT EXISTS ${bindir}/file1)
            execute_process(COMMAND ${LN} "-s" "${bindir}/file2" "${bindir}/file1")
        endif()

        get_filename_component(file1 ${bindir}/file1 REALPATH)
        get_filename_component(file2 ${bindir}/file2 REALPATH)
        get_filename_component(file3 ${bindir}/file3 REALPATH)

        if(NOT file3 STREQUAL "${bindir}/file3")
            message(FATAL_ERROR "CMake fails resolving REALPATH file file3")
        endif()

        if(NOT file2 STREQUAL "${bindir}/file3")
            message(FATAL_ERROR "CMake fails resolving simple symlink")
        endif()

        if(NOT file1 STREQUAL "${bindir}/file3")
            message(FATAL_ERROR "CMake fails resolving double symlink")
        endif()

        # cleanup
        file(REMOVE ${bindir}/file1)
        file(REMOVE ${bindir}/file2)
        if(EXISTS file1 OR EXISTS file2)
           message(FATAL_ERROR "removal of file1 or file2 failed")
        endif()
    endif(LN)

    file(REMOVE ${bindir}/file3)
endif()



More information about the Cmake-commits mailing list