Unable to determine project version info in multipass build environment


#1

I previously use the following override-pull scriptlet to generate the snap version:

	snapcraftctl pull

	upstream_version="$(
		git \
			describe \
			--always \
			--dirty=-d \
			--tags \
		| sed s/^v//
	)"

	packaging_revision="$(
		git \
			-C .. \
			describe \
			--abbrev=4 \
			--always \
			--match nothing \
			--dirty=-d
	)"

	snapcraftctl set-version \
		"${upstream_version}+pkg-${packaging_revision}"

However, when building the snap using the multipass build environment the script fails on the packaging_revision parameter assignment as the parts directory(/root/parts in the multipass VM) no longer reside in the VCS source tree(/root/project in the multipass VM).

Is there any way to get around this without any hacks and workarounds?


#2

Bumping topic…


#3

Here’s my workaround:

    # WORKAROUND:
    #   Allow fetching project revision in multipass build
    #   environment, which uses out-of-tree build and packaging
    #   source tree repo location can't be determined via environment
    #   Unable to determine project version info in multipass build environment - snapcraft - snapcraft.io
    #   https://forum.snapcraft.io/t/unable-to-determine-project-version-info-in-multipass-build-environment/10416
    if test -d /root/project; then
        some_place_under_the_project_repo=/root/project
    else
        some_place_under_the_project_repo=..
    fi

    packaging_revision="$(
        git \
            -C "${some_place_under_the_project_repo}" \
            describe \
            --abbrev=4 \
            --always \
            --match nothing \
            --dirty=-d
    )"

#4

This topic is no longer an issue after Snapcraft exposes the SNAPCRAFT_PROJECT_DIR environment variable since 3.4.1: Release Minor improvements · snapcore/snapcraft