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

Cannot create a snap with base:bare in destructive mode #4972

Open nhathaway opened 4 weeks ago

nhathaway commented 4 weeks ago

Bug Description

RuntimeError: cannot determine build-for architecture

in snapcraft.yaml, if you put in:

...
base: bare
type: app
...
architectures:
  - build-on: [amd64, arm64]
    build-for: [arm64]
...

It complains that you should use 'platforms' for the 'bare' base and not 'architectures'.

Bad snapcraft.yaml content:
- 'architectures' keyword is not supported for base 'bare'. Use 'platforms' keyword instead.                                                                                   

If you substitute in 'platforms' for 'architectures':

platforms:
  arm64:
    build-on: [amd64, arm64]
    build-for: arm64

you get the above runtime error.

Looking at /snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/models/project.py, this error message is produced under core22 which is the base for snapcraft itself. But 'platforms' is for core24 and by implication, also for base:bare.

To Reproduce

snapcraft --destructive-mode

Environment

Building in a docker environment with just everything required to run the snapcraft executable.

SNAP=/snap/snapcraft/current
SNAP_VERSION=8.3.2
SNAP_NAME=snapcraft
SNAP_ARCH=arm64
PATH=$SNAP/usr/bin:$PATH

snapcraft.yaml

name: my-name
base: bare
type: app
version: '1.0'
summary: My summary
description: |
  My description.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

platforms:
  arm64:
    build-on: [amd64, arm64]
    build-for: arm64

#architectures:
#  - build-on: [amd64, arm64]
#    build-for: [arm64]

apps:
  my-app:
    command: bin/bash

parts:
  snapcore:
    # See 'snapcraft plugins'
    plugin: dump
    source: mayapp.tar.gz
    source-type: tar

Relevant log output

Traceback (most recent call last):
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/application.py", line 351, in main
    return app.run()
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/application.py", line 179, in run
    return_code = super().run()
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/craft_application/application.py", line 492, in run
    dispatcher = self._get_dispatcher()
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/application.py", line 298, in _get_dispatcher
    raise errors.ClassicFallback()
snapcraft.errors.ClassicFallback

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/snap/snapcraft/current/bin/snapcraft", line 8, in <module>
    sys.exit(main())
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/application.py", line 354, in main
    return cli.run()
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/cli.py", line 260, in run
    _run_dispatcher(dispatcher, global_args)
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/cli.py", line 233, in _run_dispatcher
    dispatcher.run()
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/craft_cli/dispatcher.py", line 487, in run
    return self._loaded_command.run(self._parsed_command_args)
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/commands/core22/lifecycle.py", line 266, in run
    super().run(parsed_args)
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/commands/core22/lifecycle.py", line 139, in run
    parts_lifecycle.run(self.name, parsed_args)
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/parts/lifecycle.py", line 108, in run
    _run_command(
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/parts/lifecycle.py", line 181, in _run_command
    target_arch=project.get_build_for(),
  File "/snap/snapcraft/12379/lib/python3.10/site-packages/snapcraft/models/project.py", line 971, in get_build_for
    raise RuntimeError("cannot determine build-for architecture")
RuntimeError: cannot determine build-for architecture

Additional context

$ ls /snap/ bin/ core22/ snapcraft/

lengau commented 3 weeks ago

Thanks for the report! If you declare a build-base in the snap, does this still occur?

syncronize-issues-to-jira[bot] commented 3 weeks ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3256.

This message was autogenerated

nhathaway commented 3 weeks ago

My docker image is based off Ubuntu 20.04, so if I add 'build-base: core20' and set this:

architectures:

Then snapcraft runs to completion without any runtime errors, albeit just with warnings which I need to get to the bottom of myself now.

lengau commented 3 weeks ago

I think what we need to do here is ensure the existence of build-base gets checked earlier for base: bare so we can provide proper errors.