PATH auto extended with stage paths

Bug #2012504 reported by Ondrej Kubik
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Confirmed
Undecided
Unassigned

Bug Description

snapcraft automatically adds <stage>/usr/bin and <stage>/usr/sbin, additionally those paths are added to the beginning.

This would usually work for native builds, but causes problems when running cross builds
e.g. including python in the snap, would make the next part fail, if it tries to use python from the stage directory, which is of the wrong architecture.

As a minimum, this should be avoided if cross-build is detected.

It is still questionable if this should be the default behaviour rather than in control of the snapcraft.yaml

e.g. staging JRE in the snap, vs using JDK from the build environment.

Revision history for this message
Callahan Kovacs (mr-cal) wrote :

Hey Ondrej,

The current behavior for PATH in a core22 snapcraft.yaml is:
- LD_LIBRARY_PATH or PATH are defined, keep user-defined values.
- LD_LIBRARY_PATH or PATH are not defined, set to default values.
- LD_LIBRARY_PATH or PATH are null, do not use default values.

As you mentioned, the default PATH is `$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH`.

(source: https://github.com/snapcore/snapcraft/blob/71ed1a3698575d9b6a102a3b70dc497ecf88dca3/snapcraft/meta/snap_yaml.py#L443)

If I understand correctly, are you suggesting that when cross-building, snapcraft should not automatically use the default PATH above?

Revision history for this message
Ondrej Kubik (ondrak) wrote :

we might be talking two different things :)

I mean PATH used while building the part (not PATH set in generated snap.yaml, that works fine)

When part is built, path for the build is auto-extended with stage/usr/bin and stage/usr/sbin
If part is using plugin, you can see this easily by checking files:
core20: parts/<part name>/run/build.sh
core22: parts/<part name>/run/environment.sh

Double checking now, there is not even consistency between core20 and core22
core20 prepends: /stage/usr/bin and /stage/usr/sbin
while core22 only prepends: /stage/usr/bin

cheers
O.

Revision history for this message
Callahan Kovacs (mr-cal) wrote :

Yes, I misunderstood you!

I see what you're talking about now. Here's where craft-parts prepends the build environment's PATH with existing bin directories:
- https://github.com/canonical/craft-parts/blob/4f305249a87e861d182f1525a758452dc5a0df2e/craft_parts/executor/environment.py#L95
- https://github.com/canonical/craft-parts/blob/4f0645b70b64ffcc3db45fa105de020b36308c24/craft_parts/utils/os_utils.py#L75

I agree that staged bin directories shouldn't be appended to the build environment's PATH when cross-compiling.

Changed in snapcraft:
status: New → Confirmed
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.