canonical / snapcraft

Package, distribute, and update any app for Linux and IoT.
https://snapcraft.io
GNU General Public License v3.0
1.18k stars 440 forks source link

Classic confined Python example fails #4251

Open dboddie opened 1 year ago

dboddie commented 1 year ago

Bug Description

This example/test used to work (see the successful Actions builds). Now it fails.

https://github.com/snapcraft-docs/python-ctypes-example

To Reproduce

Environment

Snapcraft running with LXD on Ubuntu 22.10, but also fails on Ubuntu 22.04.

snapcraft.yaml

name: example-python-ctypes
base: core22
version: '0.1'
summary: An example snap for a Python project using ctypes
description: |
  Shows how to create a snap for a Python application that uses ctypes to
  access a system library.

grade: devel
confinement: classic

apps:
  example-python-ctypes:
    # This refers to the installed location of the program at build-time.
    # When the snap is installed, it will be available as example-python-ctypes.
    command: bin/test-ctypes.py

parts:
  example-part:
    source: .
    plugin: python
    # Override the build to perform a normal build then patch ctypes to fix the
    # run-time library paths.
    override-build: |
      snapcraftctl build
      $SNAPCRAFT_PROJECT_DIR/snap/local/patch-ctypes.sh
    # These packages need to be made available so that the build step can patch
    # ctypes.
    stage-packages:
      - libpython3.10-minimal
      - libpython3.10-stdlib
    # This resolves warnings reported by the classic linter for Snapcraft 3.7.
    build-attributes:
      - enable-patchelf

Relevant log output

2023-06-30 18:35:58.701 :: 2023-06-30 16:35:57.764 :: Successfully built test-ctypes
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:57.793 :: Installing collected packages: test-ctypes
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:57.806 :: Successfully installed test-ctypes-0.0.1
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.035 :: + find /root/parts/example-part/install -type f -executable -print0
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.035 :: + xargs -0 sed -i '1 s|^#\!/root/parts/example-part/install/bin/python3.*$|#!/usr/bin/env python3|'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.069 :: ++ set +o
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.069 :: ++ grep errexit
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.071 :: + opts_state='set +o errexit'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.071 :: + set +e
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.071 :: + install_dir=/root/parts/example-part/install/usr/bin
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.071 :: + stage_dir=/root/stage/usr/bin
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.071 :: ++ find /root/parts/example-part/install/usr/bin /root/stage/usr/bin -type f -executable -name 'python3.*' -print -quit
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.073 :: + payload_python=/root/parts/example-part/install/usr/bin/python3.10
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.073 :: + '[' -n /root/parts/example-part/install/usr/bin/python3.10 ']'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + installed_python=/usr/bin/python3.10
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + '[' /usr/bin/python3.10 = /root/parts/example-part/install/usr/bin/python3.10 ']'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + symlink_target=../usr/bin/python3.10
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + '[' -z ../usr/bin/python3.10 ']'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + eval 'set +o errexit'
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: ++ set +o errexit
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.074 :: + ln -sf ../usr/bin/python3.10 /root/parts/example-part/install/bin/python3
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.142 ::
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.142 :: Users are encouraged to replace 'snapcraftctl' with 'craftctl' and use
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.142 :: 'CRAFT_*' environment variables in scriptlets when building snaps based
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.142 :: on core22. Please refer to the core22 migration guide for details.
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.142 :: + /root/project/snap/local/patch-ctypes.sh
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.143 :: + python3 -c import ctypes; print(ctypes.__file__)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.184 :: + CTYPES_INIT=/root/parts/example-part/install/root/parts/example-part/install/usr/lib/python3.10/ctypes/__init__.py
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.184 :: + CTYPES_INIT_ORIG=/root/parts/example-part/install/root/parts/example-part/install/usr/lib/python3.10/ctypes/__init__.py.orig
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.184 :: + python3 -c import site; print(site.__file__)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.194 :: + SITE_PY=/root/parts/example-part/install/root/parts/example-part/install/usr/lib/python3.10/site.py
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.194 :: + [ -f patched/ctypes/__init__.py.orig ]
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.195 :: + echo Patching ctypes...
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.195 :: Patching ctypes...
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.195 :: + patch -s -b /root/parts/example-part/install/root/parts/example-part/install/usr/lib/python3.10/ctypes/__init__.py /root/project/snap/local/patches/ctypes_init.diff
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.196 :: patch: **** Can't reopen file /root/parts/example-part/install/root/parts/example-part/install/usr/lib/python3.10/ctypes/__init__.py : No such file or directory
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.378 'override-build' in part 'example-part' failed with code 2.
2023-06-30 18:35:58.701 :: Review the scriptlet and make sure it's correct.
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383 Traceback (most recent call last):
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/snapcraft/parts/parts.py", line 177, in run
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     aex.execute(action, stdout=stream, stderr=stream)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 304, in execute
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     self._executor.execute(actions, stdout=stdout, stderr=stderr)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 128, in execute
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     self._run_action(act, stdout=stdout, stderr=stderr)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 193, in _run_action
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     handler.run_action(action, stdout=stdout, stderr=stderr)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 172, in run_action
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     state = handler(step_info, stdout=stdout, stderr=stderr)
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 309, in _run_build
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     self._run_step(
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 485, in _run_step
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     step_handler.run_scriptlet(
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/step_handler.py", line 278, in run_scriptlet
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383     raise errors.ScriptletRunError(
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383 craft_parts.errors.ScriptletRunError: 'override-build' in part 'example-part' failed with code 2.
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383 Review the scriptlet and make sure it's correct.
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.383 The above exception was the direct cause of the following exception:
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384 Traceback (most recent call last):
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384   File "/snap/snapcraft/9362/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 302, in _run_command
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384     _run_lifecycle_and_pack(
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384   File "/snap/snapcraft/9362/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 345, in _run_lifecycle_and_pack
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384     lifecycle.run(
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384   File "/snap/snapcraft/9362/lib/python3.8/site-packages/snapcraft/parts/parts.py", line 192, in run
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384     raise errors.PartsLifecycleError(str(err)) from err
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384 snapcraft.errors.PartsLifecycleError: 'override-build' in part 'example-part' failed with code 2.
2023-06-30 18:35:58.701 :: 2023-06-30 16:35:58.384 Review the scriptlet and make sure it's correct.
2023-06-30 18:36:00.072 Failed to execute pack in instance.
2023-06-30 18:36:00.072 Detailed information: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
2023-06-30 18:36:00.073 Traceback (most recent call last):
2023-06-30 18:36:00.073   File "/snap/snapcraft/9362/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 574, in _run_in_provider
2023-06-30 18:36:00.073     instance.execute_run(cmd, check=True, cwd=output_dir)
2023-06-30 18:36:00.073   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
2023-06-30 18:36:00.073     return self.lxc.exec(
2023-06-30 18:36:00.073   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 371, in exec
2023-06-30 18:36:00.073     return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
2023-06-30 18:36:00.073   File "/snap/snapcraft/9362/usr/lib/python3.8/subprocess.py", line 516, in run
2023-06-30 18:36:00.073     raise CalledProcessError(retcode, process.args,
2023-06-30 18:36:00.073 subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-example-python-ctypes-on-amd64-for-amd64-13899806', '--cwd', '/root/project', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'SNAPCRAFT_MANAGED_MODE=1', 'snapcraft', 'pack', '--verbosity=brief', '--build-for', 'amd64']' returned non-zero exit status 1.

Additional context

No response

dboddie commented 1 year ago

Tracked in CRAFT-1852.