Repository: mesonbuild/meson

Issue:
gmock dependency does not work if prebuilt version is found
Hello all,

I tried running test case `frameworks/3 gmock` and got the following result:

```
The Meson build system
Version: 0.41.0.dev1
Source dir: /home/pauloalvarez/meson/test cases/frameworks/3 gmock
Build dir: /home/pauloalvarez/meson/test cases/frameworks/3 gmock/build
Build type: native build
Project name: gmock test
Native cpp compiler: c++ (gcc 5.4.0)
Build machine cpu family: x86_64
Build machine cpu: x86_64
Dependency GTest found: YES (prebuilt)
Dependency GMock found: YES (prebuilt)
Build targets in project: 1
Traceback (most recent call last):
  File "/home/pauloalvarez/meson/mesonbuild/mesonmain.py", line 307, in run
    app.generate()
  File "/home/pauloalvarez/meson/mesonbuild/mesonmain.py", line 182, in generate
    g.generate(intr)
  File "/home/pauloalvarez/meson/mesonbuild/backend/ninjabackend.py", line 193, in generate
    self.generate_target(t, outfile)
  File "/home/pauloalvarez/meson/mesonbuild/backend/ninjabackend.py", line 444, in generate_target
    elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects)
  File "/home/pauloalvarez/meson/mesonbuild/backend/ninjabackend.py", line 2297, in generate_link
    commands += dep.get_link_args()
  File "/home/pauloalvarez/meson/mesonbuild/compilers.py", line 462, in __iadd__
    raise TypeError('can only concatenate list (not "{}") to list'.format(args))
TypeError: can only concatenate list (not "/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/../../../../lib64/libgmock.so") to list
```

Seems to me that the method find_library of class CCompiler, when it resorts to finding the library file itself, does not return the result as a list, but returns it as a string. When the generator class tries to append it to the command list, the concatenation fails and the error is shown. Indeed, the following patch fixes the error for me:

```diff
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index e7c02b27..a2fca417 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1371,10 +1371,10 @@ class CCompiler(Compiler):
             for suffix in suffixes:
                 trial = os.path.join(d, 'lib' + libname + '.' + suffix)
                 if os.path.isfile(trial):
-                    return trial
+                    return [trial]
                 trial2 = os.path.join(d, libname + '.' + suffix)
                 if os.path.isfile(trial2):
-                    return trial2
+                    return [trial2]
         return None
 
     def thread_flags(self):
```

I am not entirely sure if that is the correct solution though, @jpakkane @nirbheek do you have any ideas?


Discussion:
Sorry for the awful formatting.
Use triple backticks...

Resolving patch:
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1371,10 +1371,10 @@ def find_library(self, libname, env, extra_dirs):
             for suffix in suffixes:
                 trial = os.path.join(d, 'lib' + libname + '.' + suffix)
                 if os.path.isfile(trial):
-                    return trial
+                    return [trial]
                 trial2 = os.path.join(d, libname + '.' + suffix)
                 if os.path.isfile(trial2):
-                    return trial2
+                    return [trial2]
         return None
 
     def thread_flags(self):


Test patch: