Out-of-tree builds with snapcraft

How to instruct snapcraft to create build artifacts outside of source directory? I do not see any command line parameters to specify this.

It is impossible with snapcraft 3.1 - it saves global state to project_config.project._get_global_state_file_path()

Where project_config is returned by some project_loader.

Config object is constructed from project object.


But basically there is no need to wrap project in _config.Config, because it is accessed directly anyway. project object is constructed in cli._options.

There getter for global state path is located in self._parts_dir.

self._part_dir is hardcoded to be present on work_dir/parts, and although work_dir is present in project parameters, I don’t see that it is really passed to constructor.

https://github.com/snapcore/snapcraft/pull/2463 this should fix it. Need to test this somehow.

1 Like

I managed to successfully build snap out of tree.

Build on read-only volume passed successfully, but snap pack step failed, because resulting snap is created in current directory instead of --work-dir. I had to split build step into prime and pack to change path of resulting .snap file.

sudo snap install snapcraft-pr
snapcraft-pr.init 2463
snapcraft-pr 2463 prime --work-dir /tmp/build

cd /tmp/build
snapcraft-pr 2463 pack prime/