[CMake] bug in cpack deb generator if "file" not available

Henning Meyer henning.meyer at dedrone.com
Wed Dec 7 12:51:58 EST 2016


Hi,

the CPack DEB generator executes the file tool to determine whether a
file is executable

this is a snippet from CPackDeb.cmake from cmake gitlab master:

# get file info so that we can determine if file is executable or not
    unset(CPACK_DEB_INSTALL_FILES)
    foreach(FILE_ IN LISTS FILE_PATHS_)
      execute_process(COMMAND file "./${FILE_}"
        WORKING_DIRECTORY "${WDIR}"
        OUTPUT_VARIABLE INSTALL_FILE_)
      list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}")
    endforeach()

    # Only dynamically linked ELF files are included
    # Extract only file name infront of ":"
    foreach(_FILE IN LISTS CPACK_DEB_INSTALL_FILES)
      if(_FILE MATCHES "ELF.*dynamically linked")
        string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}")
        list(APPEND CPACK_DEB_BINARY_FILES "${CMAKE_MATCH_1}")
        set(CONTAINS_EXECUTABLE_FILES_ TRUE)
      endif()
      if(_FILE MATCHES "ELF.*shared object")
        string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}")
        list(APPEND CPACK_DEB_SHARED_OBJECT_FILES "${CMAKE_MATCH_1}")
      endif()
    endforeach()

The problem is that execute_process(COMMAND file) may fail, and if it
does, we do not add the dependencies of that executable to the generated
deb file. This issue happened to us because our continuous integration
system tried building inside a minimal docker image, where /usr/bin/file
was simply not available, but it might fail for other reasons too: for
example strange things in the user's path, open file limit exceeded or
out of memory conditions.

I would therefore much prefer if the above code:
1) uses a variable ${FILE_EXECUTABLE} for the file tool defaulting to
/usr/bin/file similar to the way it uses the variable
${READELF_EXECUTABLE} for the readelf tool
2) checks the return code on every iteration of the foreach() loop, and
calls message(FATAL_ERROR) if it is non-zero.

I would be willing to implement this in a branch.

Regards,
Henning

PS:
I reported this as a packing issue (file is a missing dependency of
cmake) to ubuntu at
https://bugs.launchpad.net/ubuntu/+source/cmake/+bug/1647868



More information about the CMake mailing list