canonical / canonical/craft-application

Pack command output option is inconsistent

Open
#770 1 comment 0 reactions 0 assignees View on GitHub
Status: Triaged Type: Bug
Dominant language
Python
Stars
14
Forks
29
Avg merge
2d 3h
Merged PRs (30d)
12

Description

### Bug Description

The `pack` command offers the `--output` option as the "output directory for created packages." However it actually work in different ways:

- If output is specified as a subdirectory of the project root, it creates artifacts inside the directory (as described in the help message)
- If output is specified as a filename under the project root, it creates the artifact with the specified name.
- If output is specified as a directory or filename outside the project root, the artifact is created inside the build instance and it never appears in the host system.

The application should probably stop with an error instead of failing silently in cases where the artifact disappears, and clarify the `--output` behavior when multiple output artifacts are generated (if a directory is created then it should do the same when a single output artifact is generated). We can also consider deprecating this option in future releases.

### To Reproduce

```shell
$ mkdir /tmp/foo
$ cd /tmp/foo
$ snapcraft init
Go to https://docs.snapcraft.io/the-snapcraft-format/8337 for more information about the snapcraft.yaml format.
Successfully initialised project.
$ snapcraft pack --output=foo
Packed foo
$ mkdir bar
$ snapcraft pack --output=bar
Packed foo_0.1_amd64.snap
$ snapcraft pack --output=/tmp
Packed foo_0.1_amd64.snap
$ ls -l /tmp/foo_0.1_amd64.snap
ls: cannot access '/tmp/foo_0.1_amd64.snap': No such file or directory
$ snapcraft pack --output=/dirname/
Packed dirname
$ ls -l /dirname
ls: cannot access '/dirname': No such file or directory
```

### part yaml

```shell

```

### Relevant log output

```shell
:: 2025-05-23 09:41:29.948 Packing...
:: 2025-05-23 09:41:29.948 Reading snap metadata...
:: 2025-05-23 09:41:29.949 Running linters...
:: 2025-05-23 09:41:29.949 Running linter: classic
:: 2025-05-23 09:41:29.949 Running linter: library
:: 2025-05-23 09:41:29.951 pack_snap: output='/tmp', compression='xz'
:: 2025-05-23 09:41:29.951 pack_snap: check skeleton
:: 2025-05-23 09:41:29.966 Creating snap package...
:: 2025-05-23 09:41:29.966 Pack command: ['snap', 'pack', '--filename', 'foo_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/tmp')]
:: 2025-05-23 09:41:30.026 Packed foo_0.1_amd64.snap
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the documented `snapcraft pack --output` cases from the issue, especially paths inside and outside the project root. Trace the pack command's output handling and define completion around preventing silent disappearance and making directory-versus-filename behavior consistent, including multiple artifacts.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.