intel / xpumanager

MIT License
95 stars 20 forks source link

Invalid SUSE distribution detection in CMakeLists.txt #52

Closed eero-t closed 9 months ago

eero-t commented 1 year ago

CMakeLists.txt has this:

if(NOT DEFINED CPACK_GENERATOR)
  if(EXISTS "/etc/debian_version")
    set(CPACK_GENERATOR "DEB")
  elseif(EXISTS "/etc/redhat-release")
    set(CPACK_GENERATOR "RPM")
  elseif(EXISTS "/etc/SUSE-brand" OR EXISTS "/etc/SUSE-release")
    set(CPACK_GENERATOR "RPM")
  else()
    set(CPACK_GENERATOR "ZIP")
  endif()
endif()

Which is wrong for both SLES and OpenSuse (base containers). Neither of them includes files named like SUSE* in their /etc directory. Check should be done against the actual needed tooling (dpkg/rpm/zip), or e.g. /etc/os-release contents instead.

As a result of failing to detect that SLES is RPM based, XPUM CmakeLists.txt defaults to ZIP, which also appears to be buggy:

---------Create installation package-----------
CPack: Create package using ZIP
CPack: Install projects
CPack: - Run preinstall target for: xpumanager
CPack: - Install project: xpumanager []
CMake Error at /home/root/xpumanager/build/cmake_install.cmake:182 (file):
  file INSTALL cannot find
  "/home/someuser/xpumanager/daemon/xpum.service.template": No such file or directory.
eero-t commented 1 year ago

/etc/os-release contents for latest SLES:

NAME="SLES"
VERSION="15-SP4"
VERSION_ID="15.4"
PRETTY_NAME="SUSE Linux Enterprise Server 15 SP4"
ID="sles"
ID_LIKE="suse"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:15:sp4"
DOCUMENTATION_URL="https://documentation.suse.com/"

For corresponding SUSE Leap version:

NAME="openSUSE Leap"
VERSION="15.4"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.4"
PRETTY_NAME="openSUSE Leap 15.4"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.4"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
LOGO="distributor-logo-Leap"

For Ubuntu 22.04:

PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

For Ubuntu 20.04:

NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

For ClearLinux:

NAME="Clear Linux OS"
VERSION=1
ID=clear-linux-os
ID_LIKE=clear-linux-os
VERSION_ID=38280
PRETTY_NAME="Clear Linux OS"
ANSI_COLOR="1;35"
HOME_URL="https://clearlinux.org"
SUPPORT_URL="https://clearlinux.org"
BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
PRIVACY_POLICY_URL="http://www.intel.com/privacy"
BUILD_ID=38280

For latest Fedora (38):

NAME="Fedora Linux"
VERSION="38 (Workstation Edition)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f38/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="Workstation Edition"
VARIANT_ID=workstation

For RHEL 8:

NAME="Red Hat Enterprise Linux"
VERSION="8.0 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.0"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.0 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.0:GA"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.0
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.0"
eero-t commented 1 year ago

XPUM actually already parses the os-release file: https://github.com/intel/xpumanager/blob/master/.cmake/os_release_info.cmake

And uses that information right at the start of the main CMake file: https://github.com/intel/xpumanager/blob/master/CMakeLists.txt

So it could be doing STREQUAL / IN_LIST check against ${os_name} (or against ID_LIKE variable in /etc/os-release so that the check is more generic).

Another alternative would be doing just COMMAND check against dpkg & rpm commands, or EXISTS checks for those commands being in /usr/bin/.

See: https://cmake.org/cmake/help/latest/command/if.html

eero-t commented 1 year ago

For some reason COMMAND "rpm" did not work, but this worked fine:

 if(NOT DEFINED CPACK_GENERATOR)
-  if(EXISTS "/etc/debian_version")
+  if(EXISTS "/usr/bin/dpkg")
     set(CPACK_GENERATOR "DEB")
-  elseif(EXISTS "/etc/redhat-release")
+  elseif(EXISTS "/usr/bin/rpm")
     set(CPACK_GENERATOR "RPM")
-  elseif(EXISTS "/etc/SUSE-brand" OR EXISTS "/etc/SUSE-release")
-    set(CPACK_GENERATOR "RPM")
-  else()
+  elseif(EXISTS "/usr/bin/zip")
     set(CPACK_GENERATOR "ZIP")
+  else()
+    message(STATUS "Neither 'dpkg', 'rpm' nor 'zip' found, using CPACK detault.")
   endif()
 endif()

Checking for rpmbuild instead of rpm would be better though, as that's what XPUM actually needs (but complains about it only at the end of the long build)...

taotod commented 9 months ago

Many thanks for submitting this issue. It was fixed in this commit https://github.com/intel/xpumanager/commit/100e4c46ebf075cf1e0e2276895b8f5164400c08#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a