Snapcraft implicit source

snapcraft currently has a behavior which can lead to surprises given it is not well known when it does not work and provides a somewhat pleasant experience when it does.

The feature in question is that of, when not specified for a part, an implicit value for source to . (read as, the local directory tree from where snapcraft is running).

This feature is of importance when dealing with collocated sources and a snapcraft project, such that certain plugins like go and nodejs will behave in unexpected ways as they would try to build local assets when maybe the intention was to only use a go-packages or node-packages entry.

The case this was trying to solve was one where backwards compatibility for the copy plugin was being sorted out and detect when rebuilding was necessary.

The reasons for keeping the implicit source behavior does not outweigh the need of just specifying it when needed, so with the introduction of bases we will make it a requirement for the cases where a source is required to be specified and keep it as None for when it is not really required (like when only adding go-packages).


Related bug:
Bug #1776807 “nil plugin shouldn’t pull anything to the srctree” : Bugs : Snapcraft

The workaround is to skip the pull phase using the override-pull scriptlet.

1 Like

It seems that this behaviour is preserved in snaps that doesn’t define a base, is there any technical reasons of doing so?

snapcraft.yaml’s may exist where source was not defined as an intended behavior, we cannot swap the default. The intention is for everyone to start making their way to defining a base, even if that base is eventually core16/core when made available through snapd.

1 Like

If that’s the case, should base become required in the snapcraft.yaml schema for snapcraft 3.0?

1 Like

If you use a base, a new schema is to be followed, in this cases, plugins that requires sources to be defined shall declare it, plugins that do not will have it set to None instead of ..

1 Like

That would break folks not using bases once 3.0 is released to stable (all of sudden snap builds in CI would start failing due to a lack of bases). No, a lack of a base will (for the foreseeable future) effectively use an older version of snapcraft, and the use of bases opts in to the newer snapcraft.

1 Like