Excluding .dep package content

I’ve a problem with wanting to exclude content from packages that are pulled in transitively (because I need to get them from a content snap instead). I’m wondering if snapcraft has any tooling to assist in this?

Ideally, something like an option to “don’t stage any files from this package or dependencies”. But there’s no such thing as (by analogy with stage:):

      - -libgl1-mesa-dri
      - -va-driver-all

I can list the files I don’t want explicitly in every part, but that is repetitive, high maintenance and error prone. There’s an example of this approach here:

Any suggestions?

i’d inlude graphics-core-20 as a build-snap … and then create a cleanup part using find to remove all duplicated libs by comparing with /snap/graphics-core-20/current/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}

In theory, that too can break. If a new file is added to the .deb and the consumer snap rebuilds before the supplier update is published to stable then that file won’t be cleaned. OTOH that is going to be rare and,even if it happens, the spurious file unlikely to a problem.

Do you have an example of a “cleanup part”? How does it run at the right time relative to other parts and how does it detect their content?

you make it run only at the prime stage and preferably as the very last thing of the build, that way nothing can change underneath you anymore…

here is an example where i use the gnome-3-28-1804 extension and remove all duplicates from my snap

find . -type f,l -exec rm -f $SNAPCRAFT_PRIME/{} while being in the toplevel of the build-snap is the key line here …

1 Like

Thanks, that saved me time rediscovering some pitfalls.

Since you’re doing almost the same thing with a different content snap default-provider this looks like a generic problem.

It suggests a feature could be usefully added to snapcraft if it is encountered in another usecase. @sergiusens?

You could also use named YAML anchors or aliases, define the set of files you want removed in one part and then have all the stage: stanzas dereference that named anchor/alias and it will expand with the contents of the named one originally.