Out-of-tree builds with snapcraft


#1

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


Call for testing: snapcraft 3.1
#2

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.

https://github.com/snapcore/snapcraft/blob/63d052f650a8a3de6dce5020b217eb25e908a40e/snapcraft/internal/project_loader/init.py#L47

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.


#3

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


#4

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/