Repository: mesonbuild/meson

Issue:
run_target Permission Denied error should be clearer
Minimal example - 
[folder.zip](https://github.com/mesonbuild/meson/files/1530489/folder.zip)

I ran - `mkdir build && cd build && meson .. && ninja` and everything works. Now I run - `ninja myscript` and it throws errors -

```
[0/1] Running external command myscript.
Traceback (most recent call last):
  File "/usr/bin/meson", line 37, in <module>
    sys.exit(main())
  File "/usr/bin/meson", line 34, in main
    return mesonmain.run(sys.argv[1:], launcher)
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 311, in run
    sys.exit(run_script_command(args[1:]))
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 278, in run_script_command
    return cmdfunc(cmdargs)
  File "/usr/lib/python3.6/site-packages/mesonbuild/scripts/commandrunner.py", line 60, in run
    pc = run_command(src_dir, build_dir, subdir, meson_command, command, arguments)
  File "/usr/lib/python3.6/site-packages/mesonbuild/scripts/commandrunner.py", line 39, in run_command
    return subprocess.Popen(command_array, env=child_env, cwd=cwd)
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/agauniyal/temp/scripts/script.sh'
FAILED: meson-myscript 
/usr/bin/python /usr/bin/meson --internal commandrunner /home/agauniyal/temp/ /home/agauniyal/temp/build '' /usr/bin/python /usr/bin/meson /home/agauniyal/temp/scripts/script.sh
ninja: build stopped: subcommand failed.
```


Discussion:
Your script.sh does not have the right permissions to be executable.
Under *nix a file must be marked as executable to be executed.
If you try to execute your script you will also get a "Permission denied" error.
I recommend you search for a quick introduction on *nix file permissions.

As a quick fix use `chmod u+x script.sh` to change the file permissions. Using `ls -l` you can see that the file permissions change from `-rw-r--r--` to `-rwxr--r--`.
You're right, this is the 3rd time I've missed marking my scripts as executable 😅 
The error should be clearer, and it should not be a traceback.
I agree I was thinking about submitting a pull request about this. Should be easy and would be useful.

Resolving patch:
diff --git a/mesonbuild/scripts/commandrunner.py b/mesonbuild/scripts/commandrunner.py
--- a/mesonbuild/scripts/commandrunner.py
+++ b/mesonbuild/scripts/commandrunner.py
@@ -38,7 +38,10 @@ def run_command(source_dir, build_dir, subdir, meson_command, command, arguments
     try:
         return subprocess.Popen(command_array, env=child_env, cwd=cwd)
     except FileNotFoundError:
-        print('Could not execute command "%s".' % command)
+        print('Could not execute command "%s". File not found.' % command)
+        sys.exit(1)
+    except PermissionError:
+        print('Could not execute command "%s". File not executable.' % command)
         sys.exit(1)
 
 def run(args):


Test patch: