mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.53k stars 1.61k forks source link

Results of find_program('some-script") should be consistent, irrespective of value of PATHEXT #4355

Open jon-turney opened 5 years ago

jon-turney commented 5 years ago

test_find_program() (a windows-only test) fails if .py isn't in PATHEXT

C:\meson>py run_unittests.py WindowsTests.test_find_program
F
Stdout:
Program cmd found: YES (C:\WINDOWS\system32\cmd.EXE)
Program cmd.exe found: YES (C:\WINDOWS\system32\cmd.exe)
Program C:\WINDOWS\system32\cmd found: YES (C:\WINDOWS\system32\cmd.exe)
Program C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script found: YES (python C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script)
Program C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script-ext.py found: YES (C:\Users\jon\AppData\Local\Programs\Python\Python36\python.exe C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script-ext.py)
Program test-script-ext found: NO

======================================================================
FAIL: test_find_program (__main__.WindowsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "run_unittests.py", line 3041, in test_find_program
    self.assertTrue(prog.found(), msg='test-script-ext not found in PATH')
AssertionError: False is not true : test-script-ext not found in PATH

Stdout:
Program cmd found: YES (C:\WINDOWS\system32\cmd.EXE)
Program cmd.exe found: YES (C:\WINDOWS\system32\cmd.exe)
Program C:\WINDOWS\system32\cmd found: YES (C:\WINDOWS\system32\cmd.exe)
Program C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script found: YES (python C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script)
Program C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script-ext.py found: YES (C:\Users\jon\AppData\Local\Programs\Python\Python36\python.exe C:\cygwin64\wip\meson\test cases/windows\8 find program\test-script-ext.py)
Program test-script-ext found: NO

----------------------------------------------------------------------
Ran 1 test in 0.059s

FAILED (failures=1)

C:\meson>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\meson>set PATHEXT=%PATHEXT%;.py

C:\meson>py run_unittests.py WindowsTests.test_find_program
.
----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
jon-turney commented 5 years ago

This test case seems a little odd. find_program('foo') will (sometimes) find foo.py on windows, but not on any other platform?

nirbheek commented 5 years ago

Yes, that's how Windows PATH searching works. There's no executable bit, so executables are identified by their extension. The default value for PATHEXT is .COM;.EXE;.BAT;.CMD and if you want python scripts to be identified as executables, you have to append ;.PY to that (the Python installer does this for you).

Of course this is optional, and the reason why the test contains this is just to ensure that this edge-case works (I'm sure some windows-only meson projects will want to assume that find_program('foo') can find foo.py in the correct configuration).

Nothing in Meson depends on it, since we expect people to look for scripts with find_program('foo.py') since that is the cross-platform way of doing it. We can just skip that line of the test if .PY is not in PATHEXT, but we should ensure that at least one of our CI jobs has .PY in PATHEXT.

nirbheek commented 5 years ago

Also, Meson supports looking for scripts with a #!.* python named foo with find_program('foo') through manual listing of directories specified in PATH because a lot of Linux-origin projects tend to install scripts without extensions on all platforms (f.ex., glib).

NNemec commented 5 years ago

As it seems, this issue reappeared. Looking at the build pipeline, This commit did, in fact, address the issue, but then, a few commit later, the same error messages reappeared on the master branch without an accidental revert or a similar obvious reason.

nirbheek commented 5 years ago

Reopening as per https://github.com/mesonbuild/meson/pull/5564#issuecomment-506522689.

brunvonlope commented 5 months ago

Still reproducible in meson 1.4. meson can't find yelp-build(.py) provided by yelp-tools MSYS2 package.

jon-turney commented 5 months ago

I apologise again for the terrible title I chose initially for this issue.

It seems like find_program() should never use PATHEXT on Windows, as that leads to find_program("something") working, when a well formed meson.build should say find_program("something.py"), but making that change would break existing meson.build which happen to work in some places...

eli-schwartz commented 5 months ago

Should people have to specify find_program('foo.exe') on Windows and find_program('foo') on Linux?

eli-schwartz commented 5 months ago

Still reproducible in meson 1.4. meson can't find yelp-build(.py) provided by yelp-tools MSYS2 package.

The msys2 package list at packages.msys2.org lists that it provides a file called usr/bin/yelp-build with no extension, not even a .py extension. Is this correct?

brunvonlope commented 5 months ago

@eli-schwartz Yes. There is no .py extension.

eli-schwartz commented 5 months ago

In that case I'm not sure I understand the problem. At least this isn't related to PATHEXT.

jon-turney commented 5 months ago

Should people have to specify find_program('foo.exe') on Windows andfind_program('foo')` on Linux?

You're quite right. Perhaps I mean "find_program() shouldn't use an unspecified, non-default value of PATHEXT inherited from the environment"?