Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component does not take snap version when no version provided #5115

Open
stephensp opened this issue Oct 14, 2024 · 0 comments
Open

component does not take snap version when no version provided #5115

stephensp opened this issue Oct 14, 2024 · 0 comments

Comments

@stephensp
Copy link
Contributor

stephensp commented Oct 14, 2024

Bug Description

component does not take snap version when no version provided as is defined by the spec "A component might have an optionally set version. Snapcraft will have mechanisms to set this."

To Reproduce

  1. Build a snap + component when no component version is provided. Component version can be deleted from: https://git.launchpad.net/~portias/+git/kernel-snaps-u24.04/tree/snapcraft.yaml?h=portias/pc-components
  2. The version of the component is <comp_name>.comp instead of <comp_name>.comp

Environment

This reproduces on any environment.

snapcraft.yaml

name: pc-kernel
adopt-info: kernel
grade: stable
summary: Ubuntu generic kernel
description: The Ubuntu generic kernel package as a snap
source-code: https://git.launchpad.net/~canonical-kernel-snaps/canonical-kernel-snaps/+git/kernel-snaps-u24.04
issues: https://bugs.launchpad.net/canonical-kernel-snaps/+filebug?field.tags=pc-kernel
contact: https://answers.launchpad.net/canonical-kernel-snaps/+addquestion
type: kernel
confinement: strict
build-base: core24

platforms:
  amd64:
  arm64:

components:
  nvidia-550-ko:
    type: test
    summary: nvidia 550 kernel objects
    description: nvidia 550 kernel objects
  nouveau:
    type: test
    summary: nouveau kernel module
    description: nouveau kernel module

parts:
  kernel:
    source: https://git.launchpad.net/canonical-kernel-snaps
    source-type: git
    source-branch: main
    plugin: nil

    build-packages:
      - kmod

    stage-packages:
      - linux-image-uc-generic

    override-build: |
      echo BULID

      # Determine version and 'uname -r'
      unamer=$(basename "$CRAFT_PART_INSTALL"/lib/modules/*)
      version="$(apt show linux-image-uc-"$unamer" 2>/dev/null | sed -n 's/^Version: //p' | head -n1)"

      # Set the snap package version
      craftctl set version=$version

      # Update depmod
      /usr/sbin/depmod -b "$CRAFT_PART_INSTALL" "$unamer"

      craftctl default

      # Move nouveau out of the file tree
      find "$CRAFT_PART_INSTALL" -name nouveau.ko.zst -exec mv '{}' "$CRAFT_PART_INSTALL" \;

    # Move nouveau into a dedicated component
    organize:
      nouveau.ko.zst: (component/nouveau)/

    override-stage: |
      echo STAGE

      # Determine 'uname -r'
      unamer=$(basename "$CRAFT_PART_INSTALL"/lib/modules/*)

      # Move modules
      mv "$CRAFT_PART_INSTALL"/lib/modules "$CRAFT_PART_INSTALL"/

      # Copy firmware
      "$CRAFT_PART_SRC"/copy-firmware -m "$CRAFT_PART_INSTALL"/modules/"$unamer" -f "$CRAFT_PART_INSTALL"/lib/firmware \
          "$CRAFT_PART_INSTALL"/_tmp
      # Move the dtbs
      if [ -d "$CRAFT_PART_INSTALL"/lib/firmware/"$unamer" ] ; then
          mv "$CRAFT_PART_INSTALL"/lib/firmware/"$unamer" "$CRAFT_PART_INSTALL"/_tmp/lib/firmware/
      fi
      mv "$CRAFT_PART_INSTALL"/_tmp/lib/firmware "$CRAFT_PART_INSTALL"/

      # Move boot files
      mv "$CRAFT_PART_INSTALL"/boot/System.map-"$unamer" "$CRAFT_PART_INSTALL"/
      mv "$CRAFT_PART_INSTALL"/boot/config-"$unamer" "$CRAFT_PART_INSTALL"/
      mv "$CRAFT_PART_INSTALL"/boot/kernel.efi-"$unamer" "$CRAFT_PART_INSTALL"/kernel.efi

      # Move docs
      mv "$CRAFT_PART_INSTALL"/usr/share/doc "$CRAFT_PART_INSTALL"/

      # Clean up remaining stage package files
      rm -rf "$CRAFT_PART_INSTALL"/{_tmp,boot,lib,usr}

      # Create compat symlink for installing headers on classic
      ln -s /usr/src/linux-headers-"$unamer" "$CRAFT_PART_INSTALL"/modules/"$unamer"/build

      # Create a mountpoint for firmware updates (LP: #2051144)
      mkdir "$CRAFT_PART_INSTALL"/firmware/updates

      craftctl default


  #TODO temporary workaround for nouveau hooks not being in canonical-kernel-snaps repo
  nouveau-scripts:
    source: ./component-hooks
    plugin: nil
    override-build: |
      craftctl default
      cp install.sh remove.sh $CRAFT_PART_INSTALL
      #duplicate install.sh as a post refres hook
      cp install.sh $CRAFT_PART_INSTALL/post-refresh.sh
    organize:
      install.sh: (component/nouveau)/snap/hooks/install
      post-refresh.sh: (component/nouveau)/snap/hooks/post-refresh
      remove.sh: (component/nouveau)/snap/hooks/remove


  files:
    plugin: dump
    source: files

  nvidia-550-ko-comp:
    source: ./component-hooks
    plugin: nil

    stage-packages:
      - binutils
      - make

    override-build: |
      craftctl default
      version="$(craftctl get version)"

      #clean up unnecessary libs
      rm -f -- $CRAFT_PART_INSTALL/usr/lib/$(uname -m)-linux-gnu/libc.so.6
      apt-get download linux-objects-nvidia-550-server-${version%.*}-generic \
          linux-signatures-nvidia-${version%.*}-generic
      for i in `find . -name '*.deb'` ; do dpkg-deb -x $i nvidia-objects ;  done

      mkdir -p $CRAFT_PART_INSTALL/bits
      mv nvidia-objects/lib/modules/*/kernel/nvidia-550srv/bits/* $CRAFT_PART_INSTALL/bits
      # Reuse the install hook as the post-refresh hook
      cp link-and-install.sh $CRAFT_PART_INSTALL/post-refresh.sh
      cp link-and-install.sh $CRAFT_PART_INSTALL/install.sh
      cp remove.sh $CRAFT_PART_INSTALL/remove.sh

    organize:
      bits/: (component/nvidia-550-ko)/bits
      usr/bin: (component/nvidia-550-ko)/bin
      usr/lib: (component/nvidia-550-ko)/lib
      install.sh: (component/nvidia-550-ko)/snap/hooks/install
      post-refresh.sh: (component/nvidia-550-ko)/snap/hooks/post-refresh
      remove.sh: (component/nvidia-550-ko)/snap/hooks/remove

Relevant log output

None.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant