Re: Proposal for moving part of the snaps launch code into the SDK/CONTENT snap

@SergioCostas In Desktop Team Updates - Monday 15th August 2022 - #5 by SergioCostas you wrote

Proposal for moving part of the snaps launch code into the SDK/CONTENT snap (https://docs.google.com/document/d/148M5xTAB2R83HkV1_8puSoKP7Sm1yW-Eh9cpFYN9WhU/edit?usp=sharing )

This sounds very interesting. Can you share more details (or even the google doc), or is that still top-secret?

I presumed it was accessible… try now.

1 Like

It let me sent you an access request. So something’s changed :slight_smile:

Hm, on my desktop computer, it doesn’t even ask that. It simply displays: “Access denied.”

@SergioCostas Still can’t read it, but I presume it’s about this kind of stuff: https://github.com/snapcore/snapcraft/pull/3798/commits/4acb66c5e6dec03fb46fc4b78fe5e8045045624d

As in: If you add a build snap with the correct name, i.e. gnome-*-sdk, the extension will use this instead of the default one and will call the command chain scripts inside the runtime snap.

Sorry for the delay, I was on vacation. I’ll ask if it is possible to give you access to the document.

2 Likes

Since the document is quite short, I decided to just copy it here:

Abstract

This document proposes to include in the CONTENT snaps (like gnome-42-2204) an extra script to the command-chain, allowing to incorporate changes in the environment variables directly in the snap, without having to send them to the snapcraft project.

Rationale

Modifying the CONTENT snaps (for example gnome-42-2204 snaps) or fixing bugs, usually require adding new environment variables. Currently this requires modifying either the snapcraft and/or the snapcraft-desktop-integration projects to modify the scripts that are included in the snaps, in the command-chain/desktop-launch file. This makes the process cumbersome because doing a change requires updating both the content snap and snapcraft repositories (and thus having to wait for both changes to be accepted), and the rebuild of the CONTENT snap with the new version of snapcraft.

The solution proposed consists in adding an extra, optional, script file in the contents snap itself, that, during launch time, is executed along with the old command chain. This would allow adding new variables to the runtime environment without having to rebuild the snapcraft snap and recompile the contents snap with the new version.

Specification

The contents snapcraft.yaml file would include a piece of code like this in the parts section:

include_script:
    override-prime: |
        craftctl default
        mkdir -p meta/custom-chain
        cp $CRAFT_PROJECT_DIR/custom-chain/run.sh meta/custom-chain/

This will copy the run.sh script into the meta/custom-chain folder of the snap, copied from the custom-chain folder in the project directory. This script is where all the desired custom commands should be added.

Now, a single change should be made in the snapcraft project to implement this, in the desktop/extensions/common/mark-and-exec file: at the end, just before the exec “$@” statement, this piece of code should be added:

if [ -f $SNAP_DESKTOP_RUNTIME/meta/custom-chain/run.sh ]; then
    source $SNAP_DESKTOP_RUNTIME/meta/custom-chain/run.sh
fi

Calling the script with source means that it will be executed inside the current shell; thus any change done by it will be included in the current environment. It also makes the operation much faster, because no new process has to be launched.

That’s all :slight_smile:

2 Likes