Repository: mesonbuild/meson

Issue:
Error in cross_sizeof when cross compiling with 0.37.0
For example,
```pytb
$ ./meson.py --cross-file cross/ubuntu-mingw.txt test\ cases/common/35\ sizeof/ work\ area/
The Meson build system
Version: 0.37.0
Source dir: /home/elliott/code/meson/test cases/common/35 sizeof
Build dir: /home/elliott/code/meson/work area
Build type: cross build
Project name: sizeof
fixme:winediag:start_process Wine Staging 1.9.22 is a testing version containing experimental patches.
fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org.
Native c compiler: ccache cc (gcc 6.2.1)
Cross c compiler: /usr/bin/i686-w64-mingw32-gcc (gcc 6.2.0)
Native cpp compiler: ccache c++ (gcc 6.2.1)
Cross cpp compiler: /usr/bin/i686-w64-mingw32-g++ (gcc 6.2.0)
Host machine cpu family: x86
Host machine cpu: i686
Target machine cpu family: arm
Target machine cpu: armv7h
Build machine cpu family: x86_64
Build machine cpu: x86_64
Traceback (most recent call last):
  File "/home/elliott/code/meson/mesonbuild/mesonmain.py", line 289, in run
    app.generate()
  File "/home/elliott/code/meson/mesonbuild/mesonmain.py", line 177, in generate
    intr.run()
  File "/home/elliott/code/meson/mesonbuild/interpreter.py", line 2215, in run
    super().run()
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 124, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 145, in evaluate_codeblock
    raise e
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 139, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 152, in evaluate_statement
    return self.assignment(cur)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 547, in assignment
    value = self.evaluate_statement(node.value)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 154, in evaluate_statement
    return self.method_call(cur)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 399, in method_call
    return obj.method_call(method_name, self.flatten(args), kwargs)
  File "/home/elliott/code/meson/mesonbuild/interpreterbase.py", line 74, in method_call
    return self.methods[method_name](args, kwargs)
  File "/home/elliott/code/meson/mesonbuild/interpreter.py", line 803, in sizeof_method
    esize = self.compiler.sizeof(element, prefix, self.environment, extra_args, deps)
  File "/home/elliott/code/meson/mesonbuild/compilers.py", line 878, in sizeof
    return self.cross_sizeof(element, prefix, env, extra_args, dependencies)
  File "/home/elliott/code/meson/mesonbuild/compilers.py", line 862, in cross_sizeof
    if not self.compiles(element_exists_templ.format(prefix, element), env, args, dependencies):
NameError: name 'args' is not defined
```


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -859,11 +859,11 @@ def cross_sizeof(self, element, prefix, env, extra_args=None, dependencies=None)
 %s
 int temparray[%d-sizeof(%s)];
 '''
-        if not self.compiles(element_exists_templ.format(prefix, element), env, args, dependencies):
+        if not self.compiles(element_exists_templ.format(prefix, element), env, extra_args, dependencies):
             return -1
         for i in range(1, 1024):
             code = templ % (prefix, i, element)
-            if self.compiles(code, env, args, dependencies):
+            if self.compiles(code, env, extra_args, dependencies):
                 if self.id == 'msvc':
                     # MSVC refuses to construct an array of zero size, so
                     # the test only succeeds when i is sizeof(element) + 1
@@ -907,11 +907,11 @@ def cross_alignment(self, typename, env, extra_args=None, dependencies=None):
 
 int testarray[%d-offsetof(struct tmp, target)];
 '''
-        if not self.compiles(type_exists_templ.format(typename), env, args, dependencies):
+        if not self.compiles(type_exists_templ.format(typename), env, extra_args, dependencies):
             return -1
         for i in range(1, 1024):
             code = templ % (typename, i)
-            if self.compiles(code, env, args, dependencies):
+            if self.compiles(code, env, extra_args, dependencies):
                 if self.id == 'msvc':
                     # MSVC refuses to construct an array of zero size, so
                     # the test only succeeds when i is sizeof(element) + 1
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py
--- a/mesonbuild/dependencies.py
+++ b/mesonbuild/dependencies.py
@@ -113,11 +113,11 @@ def __init__(self, name, environment, kwargs):
         # When finding dependencies for cross-compiling, we don't care about
         # the 'native' pkg-config
         if want_cross:
-            if 'pkgconfig' not in env.cross_info.config['binaries']:
+            if 'pkgconfig' not in environment.cross_info.config['binaries']:
                 if self.required:
                     raise DependencyException('Pkg-config binary missing from cross file')
             else:
-                pkgbin = environment.cross_info.config['binaries']['pkgconfig']
+                PkgConfigDependency.pkgbin = environment.cross_info.config['binaries']['pkgconfig']
         # Only search for the native pkg-config the first time and
         # store the result in the class definition
         elif PkgConfigDependency.pkgbin is None:


Test patch: