Snapcraft prime stage doesn't provide the SNAPCRAFT_PART_INSTALL environment in the prime stage

Not sure if this is a bug but it feels like one.

The prime stage doesn’t have the SNAPCRAFT_PART_INSTALL variable avaialble. Attempting to use it in an override-prime section produces the following error:

/bin/bash: line 41: SNAPCRAFT_PART_INSTALL: unbound variable

Perhaps this is deliberate, but it feels like a mistake, since the prime stage " copies the staged files from SNAPCRAFT_PART_INSTALL to the shared SNAPCRAFT_PRIME".

The relevant code:

def get_snapcraft_part_directory_environment(
    part: "PluginHandler", *, step: Optional[steps.Step] = None
) -> Dict[str, str]:
    env = {
        "SNAPCRAFT_PART_SRC": part.part_source_dir,
        "SNAPCRAFT_PART_SRC_WORK": part.part_source_work_dir,
    }

    if step is None or step == steps.BUILD:
        env.update(
            {
                "SNAPCRAFT_PART_BUILD": part.part_build_dir,
                "SNAPCRAFT_PART_BUILD_WORK": part.part_build_work_dir,
                "SNAPCRAFT_PART_INSTALL": part.part_install_dir,
            }
        )

    return env

Should this be amended to provide it to the prime stage?

Thanks.

The stage step that occurs prior to prime will copy the files from $SNAPCRAFT_PART_INSTALL to $SNAPCRAFT_STAGE - which is where Snapcraft will prime files from.

Out of curiosity, what is your use-case for override-prime?

1 Like

Fair enough.

It’s not really my use case to be honest. :slight_smile: It’s MAAS that attempts to use it: Snap build currently fails - Development - Canonical MAAS | Discourse

I’ve raised it as a problem over there, but I thought I should query whether it’s an ommission in snapcraft.

Thanks.

It isn’t, if they need to ship files from parts they should stage them in the first place.

Ah, I see, thanks!

The python3 -m compileall -q . step should be omitted for core20. The python parts are compiled in the build step now (in core & core18, the python plugin skipped the compilation step).

1 Like

MaaS has one corner case where they do need it though. I had already discussed with the MaaS team on how to approach this.

3 Likes

Ok, thanks all. Please consider this topic closed/irrelevant.