Repository: mesonbuild/meson

Issue:
AttributeError: 'NoneType' object has no attribute 'startswith'
I wanted to try out the GIMP’s [ongoing port to Meson](https://gitlab.gnome.org/GNOME/gimp/merge_requests/1). But both with Meson 0.50.1 and 0.51.1 (our Meson improvement patches disabled too), the configuration fails:

```
meson flags: --buildtype=plain         --libdir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/lib --libexecdir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/libexec         --bindir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/bin --sbindir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/sbin         --includedir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/include         --mandir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/share/man --infodir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/share/info         --localedir=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12/share/locale         -Dauto_features=enabled         -Dwrap_mode=nodownload         --prefix=/nix/store/ryk7rpy98pjj8p5nnpdg5wl6xczgndr4-gimp-2.10.12 -Dwebkit=disabled -Dalsa=disabled -Dbug-report-url=https://github.com/NixOS/nixpkgs/issues/new -Dicc-directory=/run/current-system/sw/share/color/icc --libdir=lib --libexecdir=libexec --bindir=bin --sbindir=sbin --includedir=include --mandir=share/man --infodir=share/info --localedir=share/locale
The Meson build system
Version: 0.51.1
Source dir: /build/source
Build dir: /build/source/build
Build type: native build
DEPRECATION: Duplicated values in array option is deprecated. This will become a hard error in the future.
Project name: gimp
Project version: 2.99.1
C compiler for the build machine: /nix/store/hpzj855nkgjvg58nrhq4910sb9q3kss1-gcc-wrapper-7.4.0/bin/cc (gcc 7.4.0 "gcc (GCC) 7.4.0")
C++ compiler for the build machine: /nix/store/hpzj855nkgjvg58nrhq4910sb9q3kss1-gcc-wrapper-7.4.0/bin/c++ (gcc 7.4.0 "g++ (GCC) 7.4.0")
C compiler for the host machine: /nix/store/hpzj855nkgjvg58nrhq4910sb9q3kss1-gcc-wrapper-7.4.0/bin/cc (gcc 7.4.0 "gcc (GCC) 7.4.0")
C++ compiler for the host machine: /nix/store/hpzj855nkgjvg58nrhq4910sb9q3kss1-gcc-wrapper-7.4.0/bin/c++ (gcc 7.4.0 "g++ (GCC) 7.4.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Message: Host os: linux
Compiler for C supports arguments -fdiagnostics-show-option: YES
Compiler for C supports arguments -fno-common: YES
Compiler for C supports arguments -Wformat-security: YES
Compiler for C supports arguments -Winit-self: YES
Compiler for C supports arguments -Wlogical-op: YES
Compiler for C supports arguments -Wmissing-declarations: YES
Compiler for C supports arguments -Wmissing-format-attribute: YES
Compiler for C supports arguments -Wpointer-arith: YES
Compiler for C supports arguments -Wreturn-type: YES
Compiler for C supports arguments -Wtype-limits: YES
Compiler for C supports arguments -Wno-deprecated-declarations -Wdeprecated-declarations: YES
Compiler for C supports arguments -Werror=implicit-function-declaration: YES
Compiler for C supports arguments -Wdeclaration-after-statement: YES
Compiler for C supports arguments -Wold-style-definition: YES
Compiler for C supports arguments -Wno-strict-prototypes -Wstrict-prototypes: YES
Library m found: YES
Library dl found: YES
Found pkg-config: /nix/store/vjznmqrvwiawqy7g2ip6jsycyls0zlfz-pkg-config-0.29.2/bin/pkg-config (0.29.2)
Run-time dependency atk found: YES 2.32.0
Run-time dependency babl found: YES 0.1.72
Run-time dependency cairo found: YES 1.16.0
Run-time dependency dbus-glib-1 found: YES 0.110
Run-time dependency fontconfig found: YES 2.12.6
Run-time dependency freetype2 found: YES 23.1.17
Run-time dependency gdk-pixbuf-2.0 found: YES 2.38.1
Run-time dependency gegl-0.4 found: YES 0.4.17
Run-time dependency gexiv2 found: YES 0.12.0
Run-time dependency gio-2.0 found: YES 2.60.4
Run-time dependency gio-unix-2.0 found: YES 2.60.4
Run-time dependency glib-2.0 found: YES 2.60.4
Run-time dependency gobject-2.0 found: YES 2.60.4
Run-time dependency gmodule-no-export-2.0 found: YES 2.60.4
Run-time dependency gtk+-3.0 found: YES 3.24.10
Run-time dependency harfbuzz found: YES 2.5.3
Run-time dependency lcms2 found: YES 2.9
Run-time dependency libmypaint found: YES 1.3.0
Run-time dependency mypaint-brushes-1.0 found: YES 1.3.0
Run-time dependency pangocairo found: YES 1.43.0
Run-time dependency pangoft2 found: YES 1.43.0
Run-time dependency librsvg-2.0 found: YES 2.44.14
Library socket found: NO
Run-time dependency appstream-glib found: YES 0.7.15
Run-time dependency libarchive found: YES 3.4.0
Has header "backtrace.h" : NO
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libunwind found: NO (tried pkgconfig and cmake)
Run-time dependency x11 found: YES 1.6.7
Run-time dependency xmu found: YES 1.1.3
Run-time dependency xext found: YES 1.3.4
Run-time dependency xfixes found: YES 5.0.3
Has header "X11/Xmu/WinUtil.h" with dependencies xext, xmu: YES
Has header "X11/extensions/shape.h" with dependencies xext, xmu: YES
Checking for function "XmuClientWindow" with dependencies xext, xmu: YES
Checking for function "XShapeGetRectangles" with dependencies xext, xmu: YES
Has header "X11/extensions/shape.h" : YES
Has header "X11/Xmu/WinUtil.h" : YES
Run-time dependency libtiff-4 found: YES 4.0.10
Run-time dependency libjpeg found: YES 2.0.2
Run-time dependency zlib found: YES 1.2.11
Library bz2 found: YES
Run-time dependency liblzma found: YES 5.2.4
Library gs found: YES
Run-time dependency libpng found: YES 1.6.37
Library mng found: YES
Library aa found: YES
Run-time dependency xpm found: YES 3.5.12
Run-time dependency openexr found: YES 2.3.0
Run-time dependency libwebp found: YES 1.0.3
Run-time dependency libwebpmux found: YES 1.0.3
Run-time dependency libwebpdemux found: YES 1.0.3
Run-time dependency libheif found: YES 1.4.0
Dependency webkit2gtk-4.0 skipped: feature webkit disabled
Run-time dependency poppler-glib found: YES 0.74.0
Run-time dependency poppler-data found: YES 0.4.9
Run-time dependency cairo-pdf found: YES 1.16.0
Run-time dependency libwmf found: YES 0.2.12
Run-time dependency libopenjp2 found: YES 2.3.1
Run-time dependency xcursor found: YES 1.2.0
Dependency alsa skipped: feature alsa disabled
Has header "linux/input.h" : YES
Run-time dependency gudev-1.0 found: YES 232
Program xdg-email found: NO
meson.build:726: WARNING: Xdg-email not found, but required at runtime for email sending.
Run-time dependency iso-codes found: YES 3.79
Program perl5 found: NO
Program perl found: YES (/nix/store/syg9s1b9r8gd97g9616zqhj7qqw178s2-perl-5.28.2/bin/perl)
Program python found: YES (/nix/store/xw27ki6hwv00jvvi86j1b3bqaj7k2yhw-python-2.7.16/bin/python)
Traceback (most recent call last):
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/mesonmain.py", line 127, in run
    return options.run_func(options)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/msetup.py", line 240, in run
    app.generate()
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/msetup.py", line 158, in generate
    self._generate(env)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/msetup.py", line 187, in _generate
    intr.run()
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreter.py", line 3917, in run
    super().run()
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 407, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 431, in evaluate_codeblock
    raise e
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 425, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 446, in evaluate_statement
    return self.evaluate_if(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 514, in evaluate_if
    self.evaluate_codeblock(node.elseblock)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 431, in evaluate_codeblock
    raise e
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 425, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 438, in evaluate_statement
    return self.assignment(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 1048, in assignment
    value = self.evaluate_statement(node.value)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 450, in evaluate_statement
    return self.evaluate_comparison(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 529, in evaluate_comparison
    val1 = self.evaluate_statement(node.left)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 440, in evaluate_statement
    return self.method_call(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 783, in method_call
    obj = self.evaluate_statement(invokable)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 436, in evaluate_statement
    return self.function_call(cur)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 773, in function_call
    return func(node, posargs, kwargs)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 285, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 285, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreterbase.py", line 174, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreter.py", line 2326, in func_run_command
    return self.run_command_impl(node, args, kwargs)
  File "/nix/store/8g2q8c5c4227l3sp65z7qfpvi38b6cak-meson-0.51.1/lib/python3.7/site-packages/mesonbuild/interpreter.py", line 2371, in run_command_impl
    if not cmd_path.startswith('..'):
AttributeError: 'NoneType' object has no attribute 'startswith'
```

Building from this commit: https://gitlab.gnome.org/GNOME/gimp/commit/b364ce989ee63ad14d1b2f9c8a1981f5fa3496f7


Discussion:
Here is a minimal reproducible example (Python not in the environment):

```meson
project('test-npe')

pythonmod = import('python')

python = pythonmod.find_installation('python2', required: false)

run_command(python, '-v')
```

Obviously, this is not a correct Meson code but it should still show nice error, not propagate the billion-dollar mistake.

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2388,6 +2388,8 @@ def run_command_impl(self, node, args, kwargs, in_builddir=False):
                 msg = 'Program {!r} was overridden with the compiled executable {!r}'\
                       ' and therefore cannot be used during configuration'
                 raise InterpreterException(msg.format(progname, cmd.description()))
+            if not cmd.found():
+                raise InterpreterException('command {!r} not found or not executable'.format(cmd))
         elif isinstance(cmd, CompilerHolder):
             cmd = cmd.compiler.get_exelist()[0]
             prog = ExternalProgram(cmd, silent=True)
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1389,13 +1389,13 @@ def __exit__(self, *args):
             msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_UNLCK, 1)
         self.lockfile.close()
 
-def relpath(path, start):
+def relpath(path: str, start: str) -> str:
     # On Windows a relative path can't be evaluated for paths on two different
     # drives (i.e. c:\foo and f:\bar).  The only thing left to do is to use the
     # original absolute path.
     try:
         return os.path.relpath(path, start)
-    except ValueError:
+    except (TypeError, ValueError):
         return path
 
 


Test patch: