no way to differentiate between build-time and run-time env vars in plugins

Bug #1600035 reported by Thomi Richards
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Snapcraft
Triaged
Wishlist
Kyle Fazzari

Bug Description

As far as I can tell, BasePlugin has one method for manipulating environment variables: the env() method.

I have a custom plugin where I need to be able to set certain environment variables at build-time, so I'm setting them in this method like so:

```
    def env(self, root):
        env = super().env(root)
        env.extend([
            'CPPFLAGS="-std=c++11 -I{} $CPPFLAGS"'.format(os.path.join(
                root, 'usr', 'include')),
            'CFLAGS="-std=c11 -I{} $CFLAGS"'.format(os.path.join(
                root, 'usr', 'include')),
        ])

        return env
```

This works fine for building the snap, but I notice that these environment variables are then present in the command wrapper as well, so they're also being set for runtime. Most of the time this won't be a massive issue - setting CPPFLAGS has no effect at run-time, but it's a little surprising, and I can imagine situations where plugin authors will want more control over what's set at build time, and what's set at run-time.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Can you look at the godeps plugin? That has a better mechanism for this. Then `env` method is mostly there for runtime bits only.

Keep in mind we are also going to allow parts to set `environment` and `build-environment` with those keywords allowing more flexibility from a part author point of view (and in some cases avoiding to write a new plugin).

Changed in snapcraft:
status: New → Triaged
importance: Undecided → Wishlist
Changed in snapcraft:
assignee: nobody → Kyle Fazzari (kyrofa)
Kyle Fazzari (kyrofa)
Changed in snapcraft:
assignee: Kyle Fazzari (kyrofa) → nobody
Revision history for this message
林博仁(Buo-ren, Lin) (buo-ren-lin) wrote :

@sergiusens
Will `environment` and `build-environment` keys be implemented? I want to apply custom runtime command search PATH but currently `snapcraftctl` doesn't honor this.

Changed in snapcraft:
milestone: none → 3.0.1
assignee: nobody → Kyle Fazzari (kyrofa)
Changed in snapcraft:
milestone: 3.0.1 → 3.1
tags: added: 19.04
Changed in snapcraft:
milestone: 3.1 → none
tags: removed: 19.04
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.