Snapcraft cmake builds do not respect source-subdir with core20 LXD

I’ve found that the source-subdir is not being used when I attempt a core20 build. I’m running “snapcraft --use-lxd”, snapcraft 4.0.3, lxd 4.1, running on Ubuntu 20.04.

Here’s the relevant configuration, which works for core18:

name: projname
base: core18
parts:
  projname:
    source: https://github.com/electricworry/projname.git
    source-subdir: subdir
    source-depth: 1
    plugin: cmake

This output shows the subdir is being hit correctly:

Building projname 
cmake /root/parts/projname/src/subdir -DCMAKE_INSTALL_PREFIX=
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.13.2 or higher is required.  You are running version 3.10.2

If I change the base to core20 the build fails, unable to find CMakeLists.txt:

Building projname 
+ cmake /root/parts/projname/src
CMake Error: The source directory "/root/parts/projname/src" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
Failed to build 'projname'.

Any ideas about what I can do? Is this likely to be an issue with snapcraft or the core20 image?

I cloned the snapcraft repository and took a look at the code for 4.0.3. I can see that with the new v2 plugins, source-subdir doesn’t seem to be used correctly. In snapcraft/internal/pluginhandler/init.py:

# The working directory for the build depends on the source-subdir
# part property.
self.part_build_work_dir = os.path.join(
    self.part_build_dir, self._part_properties.get("source-subdir", "")
)

This appears to contradict the documentation and the previous v1 behaviour that had it affect the source directory and instead it affects the build directory.

I made a modification and was able to get the old behaviour back. Is this a change to the meaning of source-subdir, or is the current implementation wrong?

@sergiusens @cjp256 got some thoughts on this?

1 Like

Yes, this does seem to be an issue for cmake on core20. Looking into it…

I can see that this was fixed and is available in v4.0.4. Tested and working.

2 Likes