New source type proposal: "file"

Snapcraft currently supports the following source types, all of which are fairly self-explanatory:

  • bzr
  • git
  • hg/mercurial
  • svn/subversion
  • tar
  • zip

None of these cover the use-case of downloading a single file, as is the case when downloading a single script, or in my particular case, a single rosinstall file.

I’m proposing we add another source type tentatively called “file.” Its usage would look something like this:

# ...
parts:
  plugin: catkin
  source: https://raw.github.com/pal-robotics/pal-ros-pkg/master/reemc-sim-indigo.rosinstall
  source-type: file
  # ...

Any thoughts/objections/better naming skills?

2 Likes

How would you use it? Can you mock what it would look like in YAML?

I updated the original post with an example. Not the best admittedly since you could just clone the whole repo, but obviously these aren’t always on github.

According to https://docs.snapcraft.io/build-snaps/syntax#source-type, a “file” source-type still hasn’t been added.

Is there a recommended alternative? I’m trying to retrieve a shell script off of S3.

While there is currently no file plugin you can work-around this with a prepare scriptlet:

parts:
  your-part:
    plugin: nil # don't do anything with this part automatically
    prepare: |
      wget https://example.com/file.ext
    install: |
      cp file.ext $SNAPCRAFT_PART_INSTALL/file.ext
      # or you chould execute the file:
      chmod +x file.ext
      ./file.ext # if this is a script it needs to install files to $SNAPCRAFT_PART_INSTALL
1 Like

Here’s how I would try to use such a feature:
syncterm.lst:
source: http://synchro.net/syncterm.lst
source-type: file
plugin: dump
organize:
syncterm.lst: usr/local/etc

Your suggestion produces deprecation warnings:
DEPRECATED: The ‘prepare’ keyword has been replaced by ‘override-build’
See http://snapcraft.io/docs/deprecation-notices/dn7 for more information.
DEPRECATED: The ‘install’ keyword has been replaced by ‘override-build’
See http://snapcraft.io/docs/deprecation-notices/dn9 for more information.

The suggestion was correct in January when I wrote it. The message you received tells you what the problem is with the yaml that I supplied, and gives you guidance on how to fix it.

Replace both the prepare and install steps with override-pull and override-build steps:

parts:
  your-part:
    plugin: nil # don't do anything with this part automatically
    override-pull: |
      wget https://example.com/file.ext
    override-build: |
      cp file.ext $SNAPCRAFT_PART_INSTALL/file.ext
      # or you chould execute the file:
      chmod +x file.ext
      ./file.ext # if this is a script it needs to install files to $SNAPCRAFT_PART_INSTALL
1 Like