Skip to content

Commit

Permalink
pkg-config.py: fix IndexError when --variable=prefix is empty (projec…
Browse files Browse the repository at this point in the history
…t-chip#33288)

sometimes (e.g. with openssl-3.3.0) the pkg-config returns just new-line
and prefix[-4] then fails with IndexError.

Fixes:

Command: python3 build/config/linux/pkg-config.py -s recipe-sysroot --system_libdir lib openssl
Returned 1.
stderr:

Traceback (most recent call last):
  File "build/config/linux/pkg-config.py", line 259, in <module>
    sys.exit(main())
             ^^^^^^
  File "build/config/linux/pkg-config.py", line 156, in main
    prefix = GetPkgConfigPrefixToStrip(options, args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "build/config/linux/pkg-config.py", line 102, in GetPkgConfigPrefixToStrip
    if prefix[-4] == '/usr':
       ~~~~~~^^^^
IndexError: string index out of range

This part was originally introduced in pkg-config.py in chromium:
https://chromium.googlesource.com/chromium/src/build/config/+/3df971b0a5e23e51c1c739fc1908caa1d95b8ac8%5E%21/#F1

The -4 typo was fixed in chromium with:
https://chromium.googlesource.com/chromium/src/build/config/+/be2d385088cfb3a9f9f92c1dcb5c39b40fa28271%5E%21/#F0

And prefix isn't set in openssl pkg-config since:
openssl/openssl@2ac569a

Signed-off-by: Martin Jansa <[email protected]>
  • Loading branch information
shr-project authored May 3, 2024
1 parent a8e4344 commit 9ba6d0c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion build/config/linux/pkg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def GetPkgConfigPrefixToStrip(options, args):
# from pkg-config's |prefix| variable.
prefix = subprocess.check_output([options.pkg_config,
"--variable=prefix"] + args, env=os.environ).decode('utf-8')
if prefix[-4] == '/usr':
if prefix[:4] == '/usr':
return prefix[4:]
return prefix

Expand Down

0 comments on commit 9ba6d0c

Please sign in to comment.