1
apps:
  library-sample:
    command: library_sample

parts:
  library:
    source: https://github.com/the/sample.git
    plugin: cmake

When snapcraft runs the cmake install, "library" will be installed on the system (as I would expect). Also, cmake will also produce a test application in a samples folder under the build directory.

I would like to promote the sample (generated by the "part") to be an installed app within the snap package.

How do I use snap YAML to move from a nested directory under the build folder, into the snaps /bin folder?

Zak
  • 12,213
  • 21
  • 59
  • 105
  • To clarify, are you saying that the library makes it into the snap via an install rule, but there is no install rule for the samples? – kyrofa Apr 18 '17 at 22:08
  • Yes. The CMAKE install rule installs the library as it should. The sample is only a sample, and is not intended to be installed with the library. – Zak Apr 18 '17 at 22:17

1 Answers1

2

You can do this by utilizing Snapcraft's scriptlets. Specifically, the install scriptlet. They essentially allow you to modify the behavior of the build process by customizing sections of it. In the build lifecycle step, snapcraft esentially runs cmake && make && make install, but make install doesn't do everything you want it to do. The install scriptlet runs right after make install, so you can do something like this:

parts:
  library:
    source: https://github.com/the/sample.git
    plugin: cmake
    install: |
      cp -r path/to/samples $SNAPCRAFT_PART_INSTALL/

Now clean the build step with snapcraft clean -s build and run snapcraft again. Then the samples directory will end up in the final snap.

kyrofa
  • 1,759
  • 1
  • 14
  • 19
  • After I run `snapcraft prime`, where would I look to see this file to confirm it worked as I expected? – Zak Apr 18 '17 at 22:33
  • To answer my own follow up, you would call `tree prime/` from the root of the snap (i.e. the same place you are probably calling `snapcraft` – Zak Apr 18 '17 at 22:40
  • Will you update your answer to remind people to call `snapcraft clean -s build`? I will give you the check either way, but I would really appreciate it, as this was the true root of my problem. – Zak Apr 18 '17 at 22:42