How to deal with source code that has code in a "snap" directory?

I am currently working on the snapd snap. While doing this work I noticed that snapcraft does not work well when the source code contains a ./snap directory.

In the snapd source tree this ./snap directory contains a bunch of our code that deals with snap packages. However snapcraft has code (in snapcraft/internal/sources/_local.py and snapcraft/internal/pluginhandler/__init__.py) that excludes SNAPCRAFT_FILES which includes the “snap” directory.

So the following:

parts:
  snapd:
    plugin: x-builddeb
    source: .

will not work for snapd because the “./snap” par of the tree is missing in the exported ./parts/snapd/src directory.

For this particular project the “x-builddeb” plugin implements a workaround to unblock but I would love to hear feedback what is the right approach to deal with this. I tried to use “organize” but it seems this happens after pull.

As a strawman it might be nice to be able to tell snapcraft to use e.g. .snapcraft for all the plugin lifecycle directories.

2 Likes

The workaround in the custom snapd plugin stopped working. We still have the problem that our tree has a ./snap directory (which contains code about how to handle snap packages. But that dir name clashes with snapcraft and this causes the build to fail. Right now we cannot release the snapd 2.35.2 snap because of this.

2 Likes

We weighed in on options on IRC (freenode/#snappy):

  • have an ignore pattern (this does not cover this scenario of having a full source tree).
  • provide means to have an alternate snap directory (.snap)
  • have a flag in snap to tell snapcraft it cannot claim ownership of snap (a file snap/.owned)

I am inclined to go with .snap as the way to go, as long as snapcraft.yaml lives in there.

1 Like

I, too, like the idea of using a .snap/ or .snapcraft/ directory instead of snap/. Migrating everything there (plugins, hooks, etc.) would be rough though.

I would really rather have a .snapcraft file that points to a specific location under the source tree that has the actual snapcraft files, this allows custom source tree hierarchy to be possible(or easier): build.snapcraft.io doesn’t allow custom snapcraft.yaml location · Issue #1094 · canonical-websites/build.snapcraft.io