summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2021-03-24 17:18:03 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2021-03-29 18:57:34 +0300
commite80ff985fb1d4a0b840e5bf67a7e5dff08a21cdd (patch)
treed85c4738d0315073267bb97728b12ae4e9af39ac
parent448b11cb7fb41199880cc60d9fce040ea0cf5a3b (diff)
downloadmeson-e80ff985fb1d4a0b840e5bf67a7e5dff08a21cdd.tar.gz
Do not add custom target dir automatically when implicit false.
-rw-r--r--docs/markdown/snippets/customimplicit.md17
-rw-r--r--mesonbuild/backend/ninjabackend.py6
-rwxr-xr-xrun_unittests.py17
-rw-r--r--test cases/unit/94 custominc/easytogrepfor/genh.py7
-rw-r--r--test cases/unit/94 custominc/easytogrepfor/meson.build3
-rw-r--r--test cases/unit/94 custominc/helper.c5
-rw-r--r--test cases/unit/94 custominc/meson.build9
-rw-r--r--test cases/unit/94 custominc/prog.c9
-rw-r--r--test cases/unit/94 custominc/prog2.c10
9 files changed, 79 insertions, 4 deletions
diff --git a/docs/markdown/snippets/customimplicit.md b/docs/markdown/snippets/customimplicit.md
new file mode 100644
index 000000000..8956c696f
--- /dev/null
+++ b/docs/markdown/snippets/customimplicit.md
@@ -0,0 +1,17 @@
+## Do not add custom target dir to header path if `implicit_include_directories` is `false`
+
+If you do the following:
+
+```meson
+# in some subdirectory
+gen_h = custom_target(...)
+# in some other directory
+executable('foo', 'foo.c', gen_h)
+```
+
+then the output directory of the custom target is automatically added
+to the header search path. This is convenient, but sometimes it can
+lead to problems. Starting with this version, the directory will no
+longer be put in the search path if the target has
+`implicit_include_directories: false`. In these cases you need to set
+up the path manually with `include_directories`.
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 594e297db..aa899328d 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2377,10 +2377,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
commands += self.generate_basic_compiler_args(target, compiler, no_warn_args)
# Add custom target dirs as includes automatically, but before
# target-specific include directories.
- # XXX: Not sure if anyone actually uses this? It can cause problems in
- # situations which increase the likelihood for a header name collision,
- # such as in subprojects.
- commands += self.get_custom_target_dir_include_args(target, compiler)
+ if target.implicit_include_directories:
+ commands += self.get_custom_target_dir_include_args(target, compiler)
# Add include dirs from the `include_directories:` kwarg on the target
# and from `include_directories:` of internal deps of the target.
#
diff --git a/run_unittests.py b/run_unittests.py
index 0888a9752..fd75c8c9c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5616,6 +5616,23 @@ class AllPlatformTests(BasePlatformTests):
self.assertEqual(0, output.count('File reformatted:'))
self.build('clang-format-check')
+ def test_custom_target_implicit_include(self):
+ testdir = os.path.join(self.unit_test_dir, '94 custominc')
+ self.init(testdir)
+ self.build()
+ compdb = self.get_compdb()
+ matches = 0
+ for c in compdb:
+ if 'prog.c' in c['file']:
+ self.assertNotIn('easytogrepfor', c['command'])
+ matches += 1
+ self.assertEqual(matches, 1)
+ matches = 0
+ for c in compdb:
+ if 'prog2.c' in c['file']:
+ self.assertIn('easytogrepfor', c['command'])
+ matches += 1
+ self.assertEqual(matches, 1)
class FailureTests(BasePlatformTests):
'''
diff --git a/test cases/unit/94 custominc/easytogrepfor/genh.py b/test cases/unit/94 custominc/easytogrepfor/genh.py
new file mode 100644
index 000000000..48e033a72
--- /dev/null
+++ b/test cases/unit/94 custominc/easytogrepfor/genh.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys
+
+f = open(sys.argv[1], 'w')
+f.write('#define RETURN_VALUE 0')
+f.close()
diff --git a/test cases/unit/94 custominc/easytogrepfor/meson.build b/test cases/unit/94 custominc/easytogrepfor/meson.build
new file mode 100644
index 000000000..e749753bc
--- /dev/null
+++ b/test cases/unit/94 custominc/easytogrepfor/meson.build
@@ -0,0 +1,3 @@
+genh = custom_target('header',
+ output: 'generated.h',
+ command: [find_program('genh.py'), '@OUTPUT@'])
diff --git a/test cases/unit/94 custominc/helper.c b/test cases/unit/94 custominc/helper.c
new file mode 100644
index 000000000..3237441bc
--- /dev/null
+++ b/test cases/unit/94 custominc/helper.c
@@ -0,0 +1,5 @@
+#include<generated.h>
+
+int func(void) {
+ return RETURN_VALUE;
+}
diff --git a/test cases/unit/94 custominc/meson.build b/test cases/unit/94 custominc/meson.build
new file mode 100644
index 000000000..bab113908
--- /dev/null
+++ b/test cases/unit/94 custominc/meson.build
@@ -0,0 +1,9 @@
+project('implicit custom dirs', 'c')
+
+subdir('easytogrepfor')
+
+l = static_library('helper', 'helper.c', genh)
+d = declare_dependency(link_with: l, sources: genh)
+executable('prog', 'prog.c', dependencies: d, implicit_include_directories: false)
+
+executable('prog2', 'prog2.c', dependencies: d)
diff --git a/test cases/unit/94 custominc/prog.c b/test cases/unit/94 custominc/prog.c
new file mode 100644
index 000000000..db9df9d5e
--- /dev/null
+++ b/test cases/unit/94 custominc/prog.c
@@ -0,0 +1,9 @@
+#include<stdlib.h>
+
+int func(void);
+
+int main(int argc, char **argv) {
+ (void)argc;
+ (void)(argv);
+ return func();
+}
diff --git a/test cases/unit/94 custominc/prog2.c b/test cases/unit/94 custominc/prog2.c
new file mode 100644
index 000000000..e64b22919
--- /dev/null
+++ b/test cases/unit/94 custominc/prog2.c
@@ -0,0 +1,10 @@
+#include<stdlib.h>
+#include<generated.h>
+
+int func(void);
+
+int main(int argc, char **argv) {
+ (void)argc;
+ (void)(argv);
+ return func() + RETURN_VALUE;
+}