Bug 15586

Summary: meson.cross file missing from SDKs installed without sudo
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Toni Lammi <toni.lammi>
Component: devtools / tool chainAssignee: Chen Qi <Qi.Chen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: meta.mr.watcher, meta.watcher, randy.macleod, yoann.congal
Version: unspecified   
Target Milestone: 5.1   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Toni Lammi 2024-09-04 07:12:13 UTC
Meson's cross files are not placed in the SDK if the SDK is extracted to a path
that does not require sudo.

This can be easily reproduced by installing
https://downloads.yoctoproject.org/releases/yocto/yocto-5.0.3/toolchain/x86_64/poky-glibc-x86_64-core-image-sato-core2-32-qemux86-toolchain-5.0.3.sh
to two different paths where one requires root permissions for installation
and the other one does not, e.g. /foo and ~/.local/foo.
This can be verified with "find <path>/sysroots -name *.cross 2>/dev/null".

I replicated this with kirkstone with both poky and a custom distro
and with scarthgap with the above toolchain.
Comment 1 Randy MacLeod 2024-09-05 15:26:53 UTC
Toni, 

Thanks for the fairly detailed report. It's good to see people listing the branch used! ;-)

It seems odd and certainly there shouldn't be anything in the SDK that changes if run under sudo. If there is, it's a regression.

Can you document what your host distro is, in case that's something unusual or important. I know that Fedora 40 has some interesting new security policies for example.

Qi, 

Can you please test / debug this issue?
Comment 2 Chen Qi 2024-09-06 02:21:55 UTC
(In reply to Randy MacLeod from comment #1)
> Toni, 
> 
> Thanks for the fairly detailed report. It's good to see people listing the
> branch used! ;-)
> 
> It seems odd and certainly there shouldn't be anything in the SDK that
> changes if run under sudo. If there is, it's a regression.
> 
> Can you document what your host distro is, in case that's something unusual
> or important. I know that Fedora 40 has some interesting new security
> policies for example.
> 
> Qi, 
> 
> Can you please test / debug this issue?

I can do it in October if there's nobody else looking into this issue.
Comment 3 Toni Lammi 2024-09-06 04:32:31 UTC
> Can you document what your host distro is, in case that's something
> unusual or important. I know that Fedora 40 has some interesting
> new security policies for example.

The host distro is Manjaro Linux.

I reran the installer within a Ubuntu 22.04 container and the cross file is where it should.

I guess this is not an issue then since Manjaro is not a supported distro? Though I'm wondering if this will bite the supported distros later.
Comment 4 Randy MacLeod 2024-09-09 14:38:57 UTC
Thanks Qi.

Toni, I've lowered the importance of the defect to medium since 
it seems to only be happening on an unsupported distro. 
We'll see what Qi finds out when he works on this in a few weeks. 

I'm also concerned that we'll eventually encounter this problem on 
a future supported distro so investigating and fixing the issue and 
adding a test case that compares set of files installed with and 
without sudo seems like a good idea to me.
Comment 5 Chen Qi 2024-10-09 02:29:49 UTC
(In reply to Toni Lammi from comment #3)
> > Can you document what your host distro is, in case that's something
> > unusual or important. I know that Fedora 40 has some interesting
> > new security policies for example.
> 
> The host distro is Manjaro Linux.
> 
> I reran the installer within a Ubuntu 22.04 container and the cross file is
> where it should.
> 
> I guess this is not an issue then since Manjaro is not a supported distro?
> Though I'm wondering if this will bite the supported distros later.

Hi Toni,

If you still have the environment, you can check if meson-setup.py is under post-relocate-setup.d/ directory. The cross files should be setup by this script. Maybe you can run this script manually to see if things work.

Regards,
Qi
Comment 6 Toni Lammi 2024-10-09 04:46:36 UTC
> If you still have the environment, you can check if meson-setup.py is under 
> post-relocate-setup.d/ directory. The cross files should be setup by this
> script. Maybe you can run this script manually to see if things work.

That fixes the issue. I also found the real cause for this when testing this.

The reason for missing meson.cross is that my user account has LD_LIBRARY_PATH set. This results in print

```
=================================================
You are about to install the SDK to "/home/user/sdk-test". Proceed [Y/n]? Y
Extracting SDK.............................................................................................done
Setting it up...done
Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH'
but please check why this was set in the first place and that it's safe to unset.
The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set.
For more references see:
  http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80
  http://xahlee.info/UnixResource_dir/_/ldpath.html
/home/user/sdk-test/post-relocate-setup.sh: Failed to source /home/user/sdk-test/environment-setup-armv8a-<distro> with status 1
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /home/user/sdk-test/environment-setup-armv8a-<distro>
```

I wonder if the error here could be a bit clearer? At least the first time I missed the whole message. Also the script exits with 0.
Comment 7 Chen Qi 2024-10-09 08:58:59 UTC
(In reply to Toni Lammi from comment #6)
> > If you still have the environment, you can check if meson-setup.py is under 
> > post-relocate-setup.d/ directory. The cross files should be setup by this
> > script. Maybe you can run this script manually to see if things work.
> 
> That fixes the issue. I also found the real cause for this when testing this.
> 
> The reason for missing meson.cross is that my user account has
> LD_LIBRARY_PATH set. This results in print
> 
> ```
> =================================================
> You are about to install the SDK to "/home/user/sdk-test". Proceed [Y/n]? Y
> Extracting
> SDK..........................................................................
> ...................done
> Setting it up...done
> Your environment is misconfigured, you probably need to 'unset
> LD_LIBRARY_PATH'
> but please check why this was set in the first place and that it's safe to
> unset.
> The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set.
> For more references see:
>   http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80
>   http://xahlee.info/UnixResource_dir/_/ldpath.html
> /home/user/sdk-test/post-relocate-setup.sh: Failed to source
> /home/user/sdk-test/environment-setup-armv8a-<distro> with status 1
> SDK has been successfully set up and is ready to be used.
> Each time you wish to use the SDK in a new shell session, you need to source
> the environment setup script e.g.
>  $ . /home/user/sdk-test/environment-setup-armv8a-<distro>
> ```
> 
> I wonder if the error here could be a bit clearer? At least the first time I
> missed the whole message. Also the script exits with 0.

Got it. Thanks for the detailed info.
I've sent out a patch to oe-core.
https://lists.openembedded.org/g/openembedded-core/message/205342
Comment 8 Chen Qi 2024-10-12 01:48:36 UTC
Merged:

commit a24875260426249ead98b4ea3a1566b45f929905
Author: Chen Qi <Qi.Chen@windriver.com>
Date:   Wed Oct 9 01:56:47 2024 -0700

    toolchain-shar-extract.sh: exit when post-relocate-setup.sh fails
    
    When LD_LIBRARY_PATH is set, post-relocate-setup.sh will fail and
    exit properly. But such failure is ignored and the SDK installation
    will continue and tell user that things succeed. This is misleading.
    So exit immediately if post-relocate-setup.sh fails.
    
    Fixes [Yocto #15586]
    
    (From OE-Core rev: c8e2dcc1f71aa33cc6e56dfdebebbe7ef010c944)
    
    Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
    Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Comment 9 Chen Qi 2024-10-12 01:49:08 UTC
Issue resolved.