Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson sets PATH rather than WINEPATH in run_exe() #10401

Open
hughsie opened this issue May 16, 2022 · 5 comments
Open

Meson sets PATH rather than WINEPATH in run_exe() #10401

hughsie opened this issue May 16, 2022 · 5 comments

Comments

@hughsie
Copy link
Contributor

hughsie commented May 16, 2022

Describe the bug

I have a subproject that defines a binary:

gcab = executable(
  'gcab',
  install : true,
  ...
)
meson.override_find_program('gcab', gcab)

and defines it in the gcab.wrap file:

[provide]
program_names = gcab

and then a toplevel project (fwupd, but unimportant) that wants to use that binary:

gcab = find_program('gcab')

...which is used like this:

custom_target('foo',
  input : [
    'firmware.bin',
  ],
  output : 'colorhug-als-3.0.2.cab',
  command : [
    gcab, '--create', '--nopath', '@OUTPUT@', '@INPUT@',
  ],
)

...I'm also then using a cross build file, with needs_exe_wrapper = true:

[binaries]
c = '/usr/bin/x86_64-w64-mingw32-gcc'
cpp = '/usr/bin/x86_64-w64-mingw32-g++'
pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
exe_wrapper = '/usr/bin/wine'

[properties]
root = '/usr/x86_64-w64-mingw32/sys-root/mingw'
needs_exe_wrapper = true

[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

It seems I'm not having WINEPATH set, just PATH... e.g. 'WINEPATH': '' and 'PATH': '/usr/x86_64-w64-mingw32/lib:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib/../lib:/usr/libexec/gcc/x86_64-w64-mingw32:/usr/x86_64-w64-mingw32/sys-root/mingw/bin:/usr/lib/gcc/x86_64-w64-mingw32:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/bin:/usr/x86_64-w64-mingw32/sys-root/mingw/lib:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/src:/usr/x86_64-w64-mingw32/bin:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib:/usr/libexec/gcc/x86_64-w64-mingw32/11.2.1:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/libgcab:/usr/lib/ccache:/usr/lib/ccache:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/hughsie/.local/bin:/home/hughsie/bin'...

Expected behavior

I expected wine to be detected and for WINEPATH to be set for the custom_target().

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?

w64-mingw32

  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)

Fedora 36

  • what Python version are you using e.g. 3.8.0

3.10.4

  • what meson --version

git master

  • what ninja --version if it's a Ninja build

1.10.2

@xclaesse
Copy link
Member

Hmm, from a quick test, it works for me. Can you provide exact steps to reproduce, ideally based on a docker image. Alternatively, you can debug that yourself by printing why it's not getting into the condition child_env['WINEPATH'] = mesonlib.get_wine_shortpath(

@hughsie
Copy link
Contributor Author

hughsie commented May 19, 2022

you can debug that yourself by printing why it's not getting into the condition

In run_exe we have:

exe.exe_wrapper = <ExternalProgram 'exe_wrapper' -> ['/usr/bin/wine']>
mesonlib.substring_is_in_list('wine', exe.exe_wrapper.get_command()) -> True

so we take the branch. Then we have:

child_env.get('WINEPATH', '').split(';') -> []
['Z:' + p for p in exe.extra_paths] -> ['Z:/usr/libexec/gcc/x86_64-w64-mingw32', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib', 'Z:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/libgcab', 'Z:/usr/lib/gcc/x86_64-w64-mingw32', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib/../lib', 'Z:/usr/x86_64-w64-mingw32/bin', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/bin', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/lib', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/bin', 'Z:/usr/x86_64-w64-mingw32/lib', 'Z:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/src', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1', 'Z:/usr/libexec/gcc/x86_64-w64-mingw32/11.2.1']

...these are combined into one thing and pushed into mesonlib.get_wine_shortpath() which returns... Nothing! as in an empty string. Debugging this a bit, it seems the following gets executed:

['/usr/bin/wine', 'cmd', '/C', '0dd8a.bat', 'Z:/usr/libexec/gcc/x86_64-w64-mingw32', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib', 'Z:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/libgcab', 'Z:/usr/lib/gcc/x86_64-w64-mingw32', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/lib/../lib', 'Z:/usr/x86_64-w64-mingw32/bin', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1/../../../../x86_64-w64-mingw32/bin', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/lib', 'Z:/usr/x86_64-w64-mingw32/sys-root/mingw/bin', 'Z:/usr/x86_64-w64-mingw32/lib', 'Z:/home/hughsie/Code/fwupd-win32/build-win32/subprojects/gcab/src', 'Z:/usr/lib/gcc/x86_64-w64-mingw32/11.2.1', 'Z:/usr/libexec/gcc/x86_64-w64-mingw32/11.2.1', '']

It seems that the get_wine_shortpath() doesn't work properly. In my case it's not even needed, as if I add this in get_wine_shortpath my build finishes perfectly:

# do we even need to bother shortening the path?
wine_path = ";".join(wine_paths)
if len(wine_path) < 2048:
    return wine_path

I'm not exactly sure what the .bat file trick is doing, but I don't think it works super well with more than one passed in wine_paths: T.Sequence[str] -- the bat file is doing dark magic I know not of. Would my "hack" be permissible upstream? If so, I'd be happy to open a PR.

@eli-schwartz
Copy link
Member

I think it makes sense to short-circuit if we know that getting a shortpath isn't needed. This is in addition to fixing whatever is broken about the bat magic.

@hughsie
Copy link
Contributor Author

hughsie commented May 19, 2022

This is in addition to fixing whatever is broken about the bat magic.

I'm really confused about that; I'm running this in meson:

cmd = winecmd + ['cmd', '/C', getShortPathScript] + wine_paths
wine_path = subprocess.check_output(cmd).decode('utf-8')

and I get zero output. Do it in something like this, and it works perfectly:

import subprocess
wine_paths = ['Z:/usr/libexec/gcc/x86_64-w64-mingw32']
getShortPathScript = "ebc60.bat"
cmd = ["/usr/bin/wine"] + ['cmd', '/C', getShortPathScript] + wine_paths[:1]
print(" ".join(cmd))
wine_path = subprocess.check_output(cmd).decode('utf-8')
print("WINEPATH", wine_path)

It makes no sense. The environment is basically the same in both cases.

@xclaesse
Copy link
Member

xclaesse commented Jun 3, 2022

and I get zero output

Maybe when wine_paths list is too long the BAT script returns success but does not print anything? In #10457 I added a check for empty stdout to print a warning but continue in the hope it goes well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants