CPack DEB generator shlibdeps fails silently if /usr/bin/file is not installed

Bug #1647868 reported by Henning Meyer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cmake (Debian)
Fix Released
Unknown
cmake (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

I use CPack to build a debian package

I use CPACK_DEBIAN_PACKAGE_SHLIBDEPS to let dpkg-shlibdeps figure out shared library dependencies

this only works when the package "file" is installed and fails silently otherwise

"file" is not a package dependency of the cmake package

this bug report is about the packaging dependency, not that cpack silently fails, which should be fixed upstream

How to reproduce

Source File: main.cxx

#include <iostream>
int main(int,char**) {
std::cout << "Hello\n";
return 0;
}

CMakeList.txt:
cmake_minimum_required(VERSION 2.6)

PROJECT(Hello)

ADD_EXECUTABLE(hello main.cxx)
INSTALL(TARGETS hello DESTINATION hello)

SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Hello Kitty") #required
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
INCLUDE(CPack)

commands to trigger
apt install cmake
cmake .
make package
dpkg -I Hello-0.1.1-Linux.deb | grep Depends

expected output:
Depends: libc6 (>= 2.2.5), libstdc++6 (>= 4.1.1)

actual output of grep if /usr/bin/file is not installed is empty (missing Depends line)

affects Ubuntu version: Ubuntu 16.04 (probably all others too)
affects cmake version: 3.5.1-1ubuntu1

Work-around: apt install file (almost everyone has that installed, but minimal docker containers for package building do not)

suggested solution: make the cmake package depend on the file package

Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

Forwarding to Debian

Changed in cmake (Ubuntu):
status: New → Confirmed
Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

please forward upstream the "silently fails" bug, I should have found the corresponding code in the Debian bug report.

Revision history for this message
Henning Meyer (henning.meyer) wrote :

Yes, I will report this in cmake upstream later today

Revision history for this message
Henning Meyer (henning.meyer) wrote :

I have described the issue on the <email address hidden> mailing list as follows:

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.

Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

thanks, I think an issue might be better, rather than a mail list post...

Revision history for this message
Henning Meyer (henning.meyer) wrote :

Good point:

I have opened issue #16486 and will create a merge request

https://gitlab.kitware.com/cmake/cmake/issues/16486

Revision history for this message
Henning Meyer (henning.meyer) wrote :

the "silent failure" issue has been fixed in cmake upstream:

https://gitlab.kitware.com/cmake/cmake/commit/e326d8cf3eb2ac3f98fe5b4783b35c6141c006a9

Changed in cmake (Debian):
status: Unknown → New
Changed in cmake (Debian):
status: New → Fix Released
Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

Marking as fix released because I'll sync for next AA series

Changed in cmake (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.