Atom - Snap Store appears to magically place electron launcher

I have been trying to snap up atom myself, just for the heck of learning snapcraft

I successfully snapped it via launchpad for amd64 architectures.

Considering atom is an electron app, I then went about looking for electron-launcher that comes with the store version of atom

When you download the snap from the store, the directory structure is

    ------/
             bin
                 desktop-launch
                 electron-launch

When I look at the snapcraft.yaml file , it has a part called electron-launcher and it basically does nothing, but organize a file.

electron-launch:
    plugin: dump
    source: .
    organize:
      electron-launch: bin/electron-launch

The source for atom, is from

https://github.com/atom/atom/releases/download/v1.19.2/atom-amd64.deb

and that .deb file, does not include an electron-launch file anywhere.

Then, the part stages desktop-gtk2

after:
      - desktop-gtk2
    stage-packages:
      - gconf2
      - libasound2
      - libnotify4
      - libnspr4
      - libnss3
      - libpulse0
      - libxss1
      - libxtst6

I looked at the part structure, and even here, there is no electron-launch file anywhere.

If I download the yaml file, and use snapcraft to build the snap,

it complains

Pulling atom
Downloading ‘atom-amd64.deb’[====================================================================================================================] 100%
Preparing to pull electron-launch
Pulling electron-launch
Preparing to build atom
Building atom
Preparing to build electron-launch
Building electron-launch
Staging atom
Staging electron-launch
Priming desktop-gtk2
Priming atom
Priming electron-launch
[Errno 2] No such file or directory: '/home/sherlock/Documents/Snapstore/atom/prime/bin/electron-launch’

But it seems to be available when I download instead from store? how and
Where is this file coming from?

@wimpress did you make the snap with electron-builder, is this why?

You can find the source for the store atom snap in the snapcrafters github which includes the electron-launch. We often package launchers, which are scripts which we use to setup the environment before launching the application.

2 Likes

Hmm that’s unfortunate because that’s harder to upstream (well, I would think so, since upstream would need to do more than just add one snapcraft.yaml to the repo and setup builds)? Any chance of snapcraft better-supporting multi-line scriptlets in snapcraft.yamls (I guess that could get quite long…)? :stuck_out_tongue:

1 Like

That part isn’t doing nothing, rather it is dumping the files in the directory ., which is the directory one-level up from the one containing the snapcraft.yaml file, into the snap and then renaming the electron-launch file into the bin directory.

The . directory when used as a source: in snapcraft.yaml is relative to the location of snap folder which contains snapcraft.yaml, so your source tree should look like the following:

.      <-- this is the directory which gets copied by the part above - everything below it is copied into the snap
./electron-launch   <-- this is the missing launcher script, which is available in the snapcrafters atom repo
./snap/
./snap/snapcraft.yaml
1 Like

I fail to understand what electron-launch does though. Trying to, but gotta read a lot more on environment variables and wrappers for launchers.

I understand now, that the snap for atom itself, is being manually built and published on store?

I am trying to build it from the github repo, using the instructions the atom guys have posted under linux manual builds.

Hence, I was distraught :smiley: trying to figure out where does the file electron launch get pulled from.

So, I am basically using the node plugin for snapcraft to build atom and generate a debian archive

then I use the dump plugin to prime the app from the debian archive.

This whole case section is just to translate the SNAP_ARCH environment variable which gets setup by snapd when the snap is launched, into the triplet used in directory names, so we can set correct paths to libraries.

#!/bin/sh

if test "$1" = "classic"; then
    shift
    case $SNAP_ARCH in
        amd64)
            TRIPLET="x86_64-linux-gnu"
            ;;
        armhf)
            TRIPLET="arm-linux-gnueabihf"
            ;;
        arm64)
            TRIPLET="aarch64-linux-gnu"
            ;;
        *)
            TRIPLET="$(uname -p)-linux-gnu"
            ;;
    esac

These ensure that the libraries that are bundled inside the snap are in the search order so when the atom binaries are looking for libraries, they find them

    export LD_LIBRARY_PATH=$SNAP/usr/lib:$SNAP/usr/lib/$TRIPLET
    export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/$TRIPLET:$LD_LIBRARY_PATH
fi

This just works around a known issue

# Correct the TMPDIR path for Chromium Framework/Electron to ensure
# libappindicator has readable resources.
export TMPDIR=$XDG_RUNTIME_DIR

Finally this launches the actual launcher snapd creates when the snap is installed, which in turn will launch atom with whatever command line parameters are passed to it.

exec ${SNAP}/bin/desktop-launch $@
1 Like

note that there is a PR pending to fix the library path for non ubuntu distros :wink:

(shameless plug)

1 Like