aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/dependencies/base.py9
-rwxr-xr-xrun_unittests.py20
2 files changed, 26 insertions, 3 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 24d035d..26564f4 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1804,7 +1804,14 @@ class ExternalProgram:
if mesonlib.is_windows():
cmd = self.command[0]
args = self.command[1:]
- self.command = self._search_windows_special_cases(name, cmd) + args
+ # Check whether the specified cmd is a path to a script, in
+ # which case we need to insert the interpreter. If not, try to
+ # use it as-is.
+ ret = self._shebang_to_cmd(cmd)
+ if ret:
+ self.command = ret + args
+ else:
+ self.command = [cmd] + args
else:
all_search_dirs = [search_dir]
if extra_search_dirs:
diff --git a/run_unittests.py b/run_unittests.py
index 2ff2af5..2510fce 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5461,6 +5461,10 @@ class WindowsTests(BasePlatformTests):
prog2 = ExternalProgram('cmd.exe')
self.assertTrue(prog2.found(), msg='cmd.exe not found')
self.assertPathEqual(prog1.get_path(), prog2.get_path())
+ # Find cmd.exe with args without searching
+ prog = ExternalProgram('cmd', command=['cmd', '/C'])
+ self.assertTrue(prog.found(), msg='cmd not found with args')
+ self.assertPathEqual(prog.get_command()[0], 'cmd')
# Find cmd with an absolute path that's missing the extension
cmd_path = prog2.get_path()[:-4]
prog = ExternalProgram(cmd_path)
@@ -5473,9 +5477,9 @@ class WindowsTests(BasePlatformTests):
self.assertTrue(prog.found(), msg='test-script-ext.py not found')
# Finding a script in PATH
os.environ['PATH'] += os.pathsep + testdir
- # Finding a script in PATH w/o extension works and adds the interpreter
- # (check only if `.PY` is in PATHEXT)
+ # If `.PY` is in PATHEXT, scripts can be found as programs
if '.PY' in [ext.upper() for ext in os.environ['PATHEXT'].split(';')]:
+ # Finding a script in PATH w/o extension works and adds the interpreter
prog = ExternalProgram('test-script-ext')
self.assertTrue(prog.found(), msg='test-script-ext not found in PATH')
self.assertPathEqual(prog.get_command()[0], python_command[0])
@@ -5485,6 +5489,18 @@ class WindowsTests(BasePlatformTests):
self.assertTrue(prog.found(), msg='test-script-ext.py not found in PATH')
self.assertPathEqual(prog.get_command()[0], python_command[0])
self.assertPathBasenameEqual(prog.get_path(), 'test-script-ext.py')
+ # Using a script with an extension directly via command= works and adds the interpreter
+ prog = ExternalProgram('test-script-ext.py', command=[os.path.join(testdir, 'test-script-ext.py'), '--help'])
+ self.assertTrue(prog.found(), msg='test-script-ext.py with full path not picked up via command=')
+ self.assertPathEqual(prog.get_command()[0], python_command[0])
+ self.assertPathEqual(prog.get_command()[2], '--help')
+ self.assertPathBasenameEqual(prog.get_path(), 'test-script-ext.py')
+ # Using a script without an extension directly via command= works and adds the interpreter
+ prog = ExternalProgram('test-script', command=[os.path.join(testdir, 'test-script'), '--help'])
+ self.assertTrue(prog.found(), msg='test-script with full path not picked up via command=')
+ self.assertPathEqual(prog.get_command()[0], python_command[0])
+ self.assertPathEqual(prog.get_command()[2], '--help')
+ self.assertPathBasenameEqual(prog.get_path(), 'test-script')
# Ensure that WindowsApps gets removed from PATH
path = os.environ['PATH']
if 'WindowsApps' not in path: