Repository: mesonbuild/meson

Issue:
Very counter-intuitive "Cross and native files must not be directories" error
Consider the following:

```c
[0] [akari@navi] [master ← /home/akari/git/cosuzu/build]
 % ls -l
total 0
drwxr-xr-x 6 akari users 122 Jul 12 07:39 native-gcc

[0] [akari@navi] [master ← /home/akari/git/cosuzu/build]
 % file ~/.local/share/meson/cross/llvm-mingw-i686
/home/akari/.local/share/meson/cross/llvm-mingw-i686: ASCII text

[0] [akari@navi] [master ← /home/akari/git/cosuzu/build]
 % meson --cross-file llvm-mingw-i686 ../ llvm-mingw-i686

ERROR: Cross and native files must not be directories

[1] [akari@navi] [master ← /home/akari/git/cosuzu/build]
 % ls -l                                                 
total 0
drwxr-xr-x 5 akari users  63 Jul 12 07:43 llvm-mingw-i686
drwxr-xr-x 6 akari users 122 Jul 12 07:39 native-gcc
```

Perhaps the cross/native file paths should be resolved *before* the build directory is created?


Discussion:
I think it might be better to just emit a warning in this case.

Resolving patch:
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -389,14 +389,17 @@ def __load_config_files(options: argparse.Namespace, scratch_dir: str, ftype: st
         if not filenames:
             return []
 
-        real = []
+        found_invalid = []  # type: typing.List[str]
+        missing = []        # type: typing.List[str]
+        real = []           # type: typing.List[str]
         for i, f in enumerate(filenames):
             f = os.path.expanduser(os.path.expandvars(f))
             if os.path.exists(f):
                 if os.path.isfile(f):
                     real.append(os.path.abspath(f))
+                    continue
                 elif os.path.isdir(f):
-                    raise MesonException('Cross and native files must not be directories')
+                    found_invalid.append(os.path.abspath(f))
                 else:
                     # in this case we've been passed some kind of pipe, copy
                     # the contents of that file into the meson private (scratch)
@@ -410,8 +413,8 @@ def __load_config_files(options: argparse.Namespace, scratch_dir: str, ftype: st
                     # Also replace the command line argument, as the pipe
                     # probably wont exist on reconfigure
                     filenames[i] = copy
-                continue
-            elif sys.platform != 'win32':
+                    continue
+            if sys.platform != 'win32':
                 paths = [
                     os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')),
                 ] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':')
@@ -421,9 +424,14 @@ def __load_config_files(options: argparse.Namespace, scratch_dir: str, ftype: st
                         real.append(path_to_try)
                         break
                 else:
-                    raise MesonException('Cannot find specified {} file: {}'.format(ftype, f))
-                continue
+                    missing.append(f)
+            else:
+                missing.append(f)
 
+        if missing:
+            if found_invalid:
+                mlog.log('Found invalid candidates for', ftype, 'file:', *found_invalid)
+            mlog.log('Could not find any valid candidate for', ftype, 'files:', *missing)
             raise MesonException('Cannot find specified {} file: {}'.format(ftype, f))
         return real
 


Test patch: