internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mesonbuild/meson

Issue:
dependency() ignores required attribute when checked second or third time
I believe this should fail at the meson configure stage:

```
foo_dep = dependency('foo-bar-xyz-12.3', required : false)
bar_dep = dependency('foo-bar-xyz-12.3', required : true)
```

But it does not fail. Seems to re-use the previously-done dependency check and then ignore the required attribute.

The real-world use case is more complicated of course, dependency is not required in one subproject but required in another.



Discussion:

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1857,6 +1857,13 @@ def func_dependency(self, node, args, kwargs):
                     # Cached dep has the wrong version. Check if an external
                     # dependency or a fallback dependency provides it.
                     cached_dep = None
+
+            # Don't re-use cached dep if it wasn't required but this one is,
+            # so we properly go into fallback/error code paths
+            if 'required' in kwargs and cached_dep is not None:
+                if not cached_dep.required and kwargs.get('required', True):
+                    cached_dep = None
+
         if cached_dep:
             dep = cached_dep
         else:


Test patch:
diff --git a/test cases/failing/34 dependency not-required then required/meson.build b/test cases/failing/34 dependency not-required then required/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/failing/34 dependency not-required then required/meson.build	
@@ -0,0 +1,4 @@
+project('dep-test', 'c', version : '1.0')
+
+foo_dep = dependency('foo-bar-xyz-12.3', required : false)
+bar_dep = dependency('foo-bar-xyz-12.3', required : true)
Repository: mesonbuild/meson

Issue:
Add build dir before source dir in include directories
When adding a directory to the list of included directories, we currently add both the source and build directory, but we should put the build directory before the source directory.

This is particularly important for people who ship Meson alongside a build system that builds in-tree such as Autotools. We will accidentally pick up headers from the Autotools build over the one we just built with Meson.

This is very commonly hit by people, and is a blocker for GStreamer shipping meson build files in the tarball releases.


Discussion:

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1720,10 +1720,11 @@ def generate_single_compile(self, target, outfile, src, is_generated=False, head
         # Add the root source and build directories as include dirs
         curdir = target.get_subdir()
         tmppath = os.path.normpath(os.path.join(self.build_to_src, curdir))
-        commands += compiler.get_include_args(tmppath, False)
+        src_inc = compiler.get_include_args(tmppath, False)
         if curdir ==  '':
             curdir = '.'
-        commands += compiler.get_include_args(curdir, False)
+        build_inc = compiler.get_include_args(curdir, False)
+        commands += build_inc + src_inc
         # -I args work differently than other ones. In them the first found
         # directory is used whereas for other flags (such as -ffoo -fno-foo) the
         # latest one is used.  Therefore put the internal include directories


Test patch:
diff --git a/test cases/common/16 configure file/config.h b/test cases/common/16 configure file/config.h
new file mode 100644
--- /dev/null
+++ b/test cases/common/16 configure file/config.h	
@@ -0,0 +1 @@
+#error "This file should not be included. Build dir must become before source dir in search order"
diff --git a/test cases/common/16 configure file/prog.c b/test cases/common/16 configure file/prog.c
--- a/test cases/common/16 configure file/prog.c	
+++ b/test cases/common/16 configure file/prog.c	
@@ -1,5 +1,8 @@
 #include <string.h>
-#include "config.h"
+/* config.h must not be in quotes:
+ * https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html
+ */
+#include <config.h>
 
 #ifdef SHOULD_BE_UNDEF
 #error "FAIL!"
diff --git a/test cases/common/16 configure file/prog2.c b/test cases/common/16 configure file/prog2.c
--- a/test cases/common/16 configure file/prog2.c	
+++ b/test cases/common/16 configure file/prog2.c	
@@ -1,4 +1,4 @@
-#include"config2.h"
+#include<config2.h>
 
 int main(int argc, char **argv) {
     return ZERO_RESULT;
Repository: mesonbuild/meson

Issue:
generating RPM spec file fails
With this error:

```
Traceback (most recent call last):
  File "/tmp/meson/mesonbuild/mesonmain.py", line 279, in run
    app.generate()
  File "/tmp/meson/mesonbuild/mesonmain.py", line 167, in generate
    intr.run()
  File "/tmp/meson/mesonbuild/interpreter.py", line 1314, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/tmp/meson/mesonbuild/interpreter.py", line 1336, in evaluate_codeblock
    raise e
  File "/tmp/meson/mesonbuild/interpreter.py", line 1330, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/tmp/meson/mesonbuild/interpreter.py", line 1455, in evaluate_statement
    return self.method_call(cur)
  File "/tmp/meson/mesonbuild/interpreter.py", line 2608, in method_call
    return obj.method_call(method_name, self.flatten(args), kwargs)
  File "/tmp/meson/mesonbuild/interpreter.py", line 996, in method_call
    value = fn(state, args, kwargs)
  File "/tmp/meson/mesonbuild/modules/rpm.py", line 97, in generate_spec_template
    fn.write('BuildRequires: pkgconfig(%s)\n' % dep)
TypeError: not all arguments converted during string formatting
```



Discussion:

Resolving patch:
diff --git a/mesonbuild/modules/rpm.py b/mesonbuild/modules/rpm.py
--- a/mesonbuild/modules/rpm.py
+++ b/mesonbuild/modules/rpm.py
@@ -94,7 +94,7 @@ def generate_spec_template(self, state, args, kwargs):
             for compiler in compiler_deps:
                 fn.write('BuildRequires: %s\n' % compiler)
             for dep in state.environment.coredata.deps:
-                fn.write('BuildRequires: pkgconfig(%s)\n' % dep)
+                fn.write('BuildRequires: pkgconfig(%s)\n' % dep[0])
             for lib in state.environment.coredata.ext_libs.values():
                 fn.write('BuildRequires: %s # FIXME\n' % lib.fullpath)
                 mlog.log('Warning, replace', mlog.bold(lib.fullpath),


Test patch:
Repository: mesonbuild/meson

Issue:
Feature Request: Specify the name of scan-build executable with an environment variable
FreeBSD doesn't have a command called `scan-build`. Packages in ports use versioned names, such as `scan-build37`, `scan-build38`, `scan-build39`, because there is no default version and installing multiple versions is supported. It will be nice to allow specifying the name of scan-build with an environment variable, so we don't have to create a symlink and modify `PATH` to use the `scan-build` target.


Discussion:

Resolving patch:
diff --git a/mesonbuild/scripts/scanbuild.py b/mesonbuild/scripts/scanbuild.py
--- a/mesonbuild/scripts/scanbuild.py
+++ b/mesonbuild/scripts/scanbuild.py
@@ -16,10 +16,10 @@
 import shutil
 import tempfile
 
-def scanbuild(srcdir, blddir, privdir, logdir, args):
+def scanbuild(exename, srcdir, blddir, privdir, logdir, args):
     with tempfile.TemporaryDirectory(dir=privdir) as scandir:
-        meson_cmd = ['scan-build'] + args
-        build_cmd = ['scan-build', '-o', logdir, 'ninja']
+        meson_cmd = [exename] + args
+        build_cmd = [exename, '-o', logdir, 'ninja']
         rc = subprocess.call(meson_cmd + [srcdir, scandir])
         if rc != 0:
             return rc
@@ -32,7 +32,8 @@ def run(args):
     privdir = os.path.join(blddir, 'meson-private')
     logdir = os.path.join(blddir, 'meson-logs/scanbuild')
     shutil.rmtree(logdir, ignore_errors=True)
-    if not shutil.which('scan-build'):
-        print('Scan-build not installed')
+    exename = os.environ.get('SCANBUILD', 'scan-build')
+    if not shutil.which(exename):
+        print('Scan-build not installed.')
         return 1
-    return scanbuild(srcdir, blddir, privdir, logdir, meson_cmd)
+    return scanbuild(exename, srcdir, blddir, privdir, logdir, meson_cmd)


Test patch:
Repository: mesonbuild/meson

Issue:
extract_all_objects malfunctions with respect to vala files
`extract_all_objects` seems to malfunction when used on Vala projects. The extracted objects use the naming scheme of `object.vala.o`, while the generated ninja files are `object.c.o`. Attempting to use extracted objects with vala builds therefore fails.



Discussion:

Resolving patch:
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -271,6 +271,9 @@ def determine_linker(self, target, src):
     def object_filename_from_source(self, target, source):
         if isinstance(source, mesonlib.File):
             source = source.fname
+        # foo.vala files compile down to foo.c and then foo.c.o, not foo.vala.o
+        if source.endswith('.vala'):
+            source = os.path.join(self.get_target_private_dir(target), source[:-5] + '.c')
         return source.replace('/', '_').replace('\\', '_') + '.' + self.environment.get_object_suffix()
 
     def determine_ext_objs(self, extobj, proj_dir_to_build_root):


Test patch:
diff --git a/test cases/vala/6 static library/installed_files.txt b/test cases/vala/6 static library/installed_files.txt
new file mode 100644
--- /dev/null
+++ b/test cases/vala/6 static library/installed_files.txt	
@@ -0,0 +1 @@
+usr/lib/libextractedlib.a
diff --git a/test cases/vala/6 static library/meson.build b/test cases/vala/6 static library/meson.build
--- a/test cases/vala/6 static library/meson.build	
+++ b/test cases/vala/6 static library/meson.build	
@@ -3,6 +3,12 @@ project('valastatic', 'vala', 'c')
 valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')]
 
 l = static_library('valalib', 'mylib.vala', dependencies : valadeps)
+# NOTE: This static library is not usable from Vala because it does not carry
+# forward the .vapi and .h files generated by Valac to the next BuildTarget.
+# Will have to be fixed with https://github.com/mesonbuild/meson/issues/891
+m = static_library('extractedlib',
+  objects : l.extract_all_objects(),
+  install : true)
 
 e = executable('valaprog', 'prog.vala',
 link_with : l,
Repository: mesonbuild/meson

Issue:
gtkdoc ignore_headers support breaks gstreamer build
```
Building documentation for gstreamer
Traceback (most recent call last):
  File "/path/to/meson/meson.py", line 26, in <module>
    sys.exit(main())
  File "/path/to/meson/meson.py", line 23, in main
    return mesonmain.run(launcher, sys.argv[1:])
  File "/path/to/meson/mesonbuild/mesonmain.py", line 249, in run
    sys.exit(run_script_command(args[1:]))
  File "/path/to/meson/mesonbuild/mesonmain.py", line 239, in run_script_command
    return cmdfunc(cmdargs)
  File "/path/to/meson/mesonbuild/scripts/gtkdochelper.py", line 182, in run
    options.ignore_headers.split('@@') if options.ignore_headers else [])
  File "/path/to/meson/mesonbuild/scripts/gtkdochelper.py", line 96, in build_gtkdoc
    '--ignore-headers=' + ignore_headers] + scan_args
TypeError: Can't convert 'list' object to str implicitly
```

It seems that this error is caused by https://github.com/mesonbuild/meson/pull/980. When `ignore_headers` is not used in the build file, it defaults to an empty list, not an empty string.


Discussion:
@ebassi


Resolving patch:
diff --git a/mesonbuild/scripts/gtkdochelper.py b/mesonbuild/scripts/gtkdochelper.py
--- a/mesonbuild/scripts/gtkdochelper.py
+++ b/mesonbuild/scripts/gtkdochelper.py
@@ -90,10 +90,11 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir,
         f_abs = os.path.join(doc_src, f)
         shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs)))
 
-    scan_cmd = ['gtkdoc-scan',
-                '--module=' + module,
-                '--source-dir=' + abs_src,
-                '--ignore-headers=' + ignore_headers] + scan_args
+    scan_cmd = ['gtkdoc-scan', '--module=' + module, '--source-dir=' + abs_src]
+    if ignore_headers:
+        scan_cmd.append('--ignore-headers=' + ' '.join(ignore_headers))
+    # Add user-specified arguments
+    scan_cmd += scan_args
     gtkdoc_run_check(scan_cmd, abs_out)
 
     if gobject_typesfile:


Test patch:
Repository: mesonbuild/meson

Issue:
has_function fails to detect missing dependencies with CFLAGS=-O1
GStreamer uses `cc.has_function('backtrace', prefix : '#include <execinfo.h>')` to check whether it can use backtrace-related functions. Using these functions doesn't require linking extra libraries on GNU/Linux, but it is required to link with `-lexecinfo` on FreeBSD. Therefore, I have to write a meson alternative to autoconf `AC_SEARCH_LIBS` macro.

I implemented it with this patch: https://bugzilla-attachments.gnome.org/attachment.cgi?id=339827
However, this only worked with `CFLAGS=-O0`:
```
Has header "execinfo.h": YES
Checking for function "backtrace": NO    # without -lexecinfo
Library execinfo found: YES
Checking for function "backtrace": YES   # with -lexecinfo
```

If I set `CFLAGS=-O1` in the environment, the first `has_function` test didn't fail and caused undefined reference error when linking `libgstreamer-1.0.so`:
```
Has header "execinfo.h": YES
Checking for function "backtrace": YES   # without -lexecinfo
...
[99/442] Linking target gst/libgstreamer-1.0.so.0.1100.0
FAILED: gst/libgstreamer-1.0.so.0.1100.0 
gst/gstreamer-1.0@sha/gstinfo.c.o: In function `generate_backtrace_trace':
gst/gstinfo.c:2707: undefined reference to `backtrace_symbols'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

I tested it on FreeBSD 11.0 with clang 3.8.0 and binutils 2.27.


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -927,9 +927,11 @@ def _have_prototype_templ():
         """
         # Add the 'prefix', aka defines, includes, etc that the user provides
         head = '#include <limits.h>\n{0}\n'
-        # We don't know what the function takes or returns, so try to use it as
-        # a function pointer
-        main = '\nint main() {{ void *a = (void*) &{1}; }}'
+        # We don't know what the function takes or returns, so return it as an int.
+        # Just taking the address or comparing it to void is not enough because
+        # compilers are smart enough to optimize it away. The resulting binary
+        # is not run so we don't care what the return value is.
+        main = '\nint main() {{ void *a = (void*) &{1}; long b = (long) a; return (int) b; }}'
         return head, main
 
     def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):


Test patch:
Repository: mesonbuild/meson

Issue:
mesonintrospect should give us access to project data
I need to access the version/project_ name properties from a script and it appears that mesonintrospect doesn't let me get these. Is this supposed to be possible?


Discussion:
We should add that, it's just that no-one has needed it before you.

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1586,7 +1586,7 @@ def do_subproject(self, dirname, kwargs):
                 raise InterpreterException('Subproject %s version is %s but %s required.' % (dirname, pv, wanted))
         self.active_projectname = current_active
         mlog.log('\nSubproject', mlog.bold(dirname), 'finished.')
-        self.build.subprojects[dirname] = True
+        self.build.subprojects[dirname] = subi.project_version
         self.subprojects.update(subi.subprojects)
         self.subprojects[dirname] = SubprojectHolder(subi)
         self.build_def_files += subi.build_def_files
@@ -1660,6 +1660,8 @@ def func_project(self, node, args, kwargs):
             raise InvalidArguments('Not enough arguments to project(). Needs at least the project name and one language')
         self.active_projectname = args[0]
         self.project_version = kwargs.get('version', 'undefined')
+        if self.build.project_version is None:
+            self.build.project_version = self.project_version
         proj_license = mesonlib.stringlistify(kwargs.get('license', 'unknown'))
         self.build.dep_manifest[args[0]] = {'version': self.project_version,
                                             'license': proj_license}
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -39,6 +39,8 @@
                     help='List all benchmarks.')
 parser.add_argument('--dependencies', action='store_true', dest='dependencies', default=False,
                     help='list external dependencies.')
+parser.add_argument('--projectinfo', action='store_true', dest='projectinfo', default=False,
+                    help='information about projects.')
 parser.add_argument('args', nargs='+')
 
 def determine_installed_path(target, installdata):
@@ -179,6 +181,18 @@ def list_tests(testdata):
         result.append(to)
     print(json.dumps(result))
 
+def list_projinfo(builddata):
+    result = {}
+    result['name'] = builddata.project_name
+    result['version'] = builddata.project_version
+    subprojects = []
+    for k, v in builddata.subprojects.items():
+        c = {'name' : k,
+             'version' : v}
+        subprojects.append(c)
+    result['subprojects'] = subprojects
+    print(json.dumps(result))
+
 def run(args):
     options = parser.parse_args(args)
     if len(options.args) > 1:
@@ -217,6 +231,8 @@ def run(args):
         list_tests(benchmarkdata)
     elif options.dependencies:
         list_deps(coredata)
+    elif options.projectinfo:
+        list_projinfo(builddata)
     else:
         print('No command specified')
         return 1


Test patch:
Repository: mesonbuild/meson

Issue:
Inner class files not included in Jar
javac produces separate class files for inner classes. So multiple output files can be generated for one input file. If Foo.class and Foo$Bar.class files are generated form Foo.class, meson only includes Foo.class not Foo$Bar.class.

I am not a Java expert (I am just trying to write a binding for my C library); but according to a quick research on the Internet, an easy solution does not seem possible with javac while keeping the support for incremental builds.

SCons has a parser for Java files to guess output files. Another solution would be to pass only the output directory to jar command instead of passing each class file.

Some info about this: http://blog.ltgt.net/in-quest-of-the-ultimate-build-tool/#internals
SCons's parser: https://bitbucket.org/scons/scons/src/3763c12a06be2b44e945bdb03fcc1b5a888e5c96/src/engine/SCons/Tool/JavaCommon.py?at=default&fileviewer=file-view-default


Discussion:

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -798,8 +798,10 @@ def generate_jar_target(self, target, outfile):
         if e != '':
             commands.append(main_class)
         commands.append(self.get_target_filename(target))
-        for cls in class_list:
-            commands += ['-C', self.get_target_private_dir(target), cls]
+        # Java compilation can produce an arbitrary number of output
+        # class files for a single source file. Thus tell jar to just
+        # grab everything in the final package.
+        commands += ['-C', self.get_target_private_dir(target), '.']
         elem = NinjaBuildElement(self.all_outputs, outname_rel, jar_rule, [])
         elem.add_dep(class_dep_list)
         elem.add_item('ARGS', commands)


Test patch:
diff --git a/test cases/java/4 inner class/com/mesonbuild/Simple.java b/test cases/java/4 inner class/com/mesonbuild/Simple.java
new file mode 100644
--- /dev/null
+++ b/test cases/java/4 inner class/com/mesonbuild/Simple.java	
@@ -0,0 +1,15 @@
+package com.mesonbuild;
+
+class Simple {
+    class Inner {
+        public String getString() {
+            return "Inner class is working.\n";
+        }
+    }
+
+    public static void main(String [] args) {
+        Simple s = new Simple();
+        Simple.Inner ic = s.new Inner();
+        System.out.println(ic.getString());
+    }
+}
diff --git a/test cases/java/4 inner class/meson.build b/test cases/java/4 inner class/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/java/4 inner class/meson.build	
@@ -0,0 +1,5 @@
+project('simplejava', 'java')
+
+javaprog = jar('myprog', 'com/mesonbuild/Simple.java',
+  main_class : 'com.mesonbuild.Simple')
+test('mytest', javaprog)
Repository: mesonbuild/meson

Issue:
"Tried to use subproject object as a dependency." erroneous message
Given the following structure:
```
touch foo.c
echo "project('test', 'c')

subdir('subdir')

executable('foo', 'foo.c', dependencies: subdir_lib)" > meson.build
mkdir subdir
touch subdir/lib.c
echo "subdir_lib = static_library('lib', 'lib.c')" > subdir/meson.build
meson build
```

Meson throws an exception:

```
Meson encountered an error in file meson.build, line 5, column 0:
Tried to use subproject object as a dependency.
You probably wanted to use a dependency declared in it instead.
Access it by calling get_variable() on the subproject object.
```

But actually there is no subproject at all in this project, it confused me a lot to understand what was the actual problem which is I should not use a library as a dependency. All the stuff about `get_variable` is wrong and confusing in my opinion.



Discussion:

Resolving patch:
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -726,11 +726,14 @@ def add_deps(self, deps):
             elif isinstance(dep, dependencies.Dependency):
                 self.external_deps.append(dep)
                 self.process_sourcelist(dep.get_sources())
+            elif isinstance(dep, BuildTarget):
+                raise InvalidArguments('''Tried to use a build target as a dependency.
+You probably should put it in link_with instead.''')
             else:
                 # This is a bit of a hack. We do not want Build to know anything
                 # about the interpreter so we can't import it and use isinstance.
                 # This should be reliable enough.
-                if hasattr(dep, 'subproject'):
+                if hasattr(dep, 'args_frozen'):
                     raise InvalidArguments('Tried to use subproject object as a dependency.\n'
                                            'You probably wanted to use a dependency declared in it instead.\n'
                                            'Access it by calling get_variable() on the subproject object.')


Test patch: