Repository: mesonbuild/meson

Issue:
Installing generated manpages crashes on OS X
Hi,

My project generates manpages using pandoc, and installs them.  This apparently fails with recent meson because meson tries to run install-name-tool on them.

Thus, from one travis run, I see:
```
Installing src/path-graph to /Users/travis/bali-phy/bin/path-graph
Installing doc/bali-phy.1 to /Users/travis/bali-phy/share/man/man1/bali-phy.1
Traceback (most recent call last):
  File "/usr/local/Cellar/meson/0.46.0/libexec/bin/meson", line 26, in <module>
    sys.exit(main())
  File "/usr/local/Cellar/meson/0.46.0/libexec/bin/meson", line 23, in main
    return mesonmain.run(sys.argv[1:], launcher)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 308, in run
    sys.exit(run_script_command(args[1:]))
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 257, in run_script_command
    return cmdfunc(cmdargs)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/scripts/meson_install.py", line 390, in run
    do_install(datafilename)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/scripts/meson_install.py", line 216, in do_install
    install_targets(d)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/scripts/meson_install.py", line 371, in install_targets
    depfixer.fix_rpath(outname, install_rpath, False)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/scripts/depfixer.py", line 391, in fix_rpath
    fix_darwin(fname, new_rpath)
  File "/usr/local/lib/python3.6/site-packages/mesonbuild/scripts/depfixer.py", line 376, in fix_darwin
    subprocess.check_call(['install_name_tool', '-add_rpath', new_rpath, fname])
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 286, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1275, in _execute_child
    restore_signals, start_new_session, preexec_fn)
TypeError: expected str, bytes or os.PathLike object, not NoneType
FAILED: meson-install 
/usr/local/opt/python/bin/python3.6 /usr/local/Cellar/meson/0.46.0/libexec/bin/meson --internal install /Users/travis/build/bredelings/BAli-Phy/build/meson-private/install.dat
ninja: build stopped: subcommand failed.
The command "ninja -C build install" exited with 1.
```


Discussion:
I also see the above stack trace on my friend's Mac.

Interestingly, one a _different_ travis build in the same matrix, I see the following for each man page:
```
[1/2] Installing files.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: '/Users/travis/bali-phy/share/man/man1/bali-phy.1': The file was not recognized as a valid object file
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: '/Users/travis/bali-phy/share/man/man1/model_P.1': The file was not recognized as a valid object file
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: '/Users/travis/bali-phy/share/man/man1/statreport.1': The file was not recognized as a valid object file
... 
Installing src/path-graph to /Users/travis/bali-phy/bin/path-graph
Installing doc/bali-phy.1 to /Users/travis/bali-phy/share/man/man1/bali-phy.1
Installing doc/model_P.1 to /Users/travis/bali-phy/share/man/man1/model_P.1
...
```

This build completed, although it complained.  The build that completed was with xcode 8.3, and the builds that failed were with xcode 7.3 and 9.2.
The `meson.build` file says:

```meson
pandoc = find_program('pandoc', required: false)

if pandoc.found()
  foreach prog : all_progs+['bp-analyze']
    markdown = files('man/'+prog+'.md')
    manpage = prog+'.1'
    custom_target(manpage,command:[pandoc,'-s','-t','man',markdown], output:manpage, capture: true, install: true, install_dir: join_paths(get_option('mandir'),'man1'))
  endforeach
...
```

Resolving patch:
diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
--- a/mesonbuild/scripts/depfixer.py
+++ b/mesonbuild/scripts/depfixer.py
@@ -347,7 +347,9 @@ def fix_elf(fname, new_rpath, verbose=True):
             e.fix_rpath(new_rpath)
 
 def get_darwin_rpaths_to_remove(fname):
-    out = subprocess.check_output(['otool', '-l', fname], universal_newlines=True)
+    out = subprocess.check_output(['otool', '-l', fname],
+                                  universal_newlines=True,
+                                  stderr=subprocess.DEVNULL)
     result = []
     current_cmd = 'FOOBAR'
     for line in out.split('\n'):
@@ -371,9 +373,13 @@ def fix_darwin(fname, new_rpath):
         return
     try:
         for rp in rpaths:
-            subprocess.check_call(['install_name_tool', '-delete_rpath', rp, fname])
-        if new_rpath != '':
-            subprocess.check_call(['install_name_tool', '-add_rpath', new_rpath, fname])
+            subprocess.check_call(['install_name_tool', '-delete_rpath', rp, fname],
+                                  stdout=subprocess.DEVNULL,
+                                  stderr=subprocess.DEVNULL)
+        if new_rpath:
+            subprocess.check_call(['install_name_tool', '-add_rpath', new_rpath, fname],
+                                  stdout=subprocess.DEVNULL,
+                                  stderr=subprocess.DEVNULL)
     except Exception as e:
         raise
         sys.exit(0)


Test patch: