aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Aguirre <alberto.aguirre@canonical.com>2017-04-14 08:18:37 -0500
committerJussi Pakkanen <jpakkane@gmail.com>2017-05-08 20:53:57 +0200
commitccab7d64f474f00e010b2c6601e63d8034c5552a (patch)
tree2007c7528dd669cb70195aa2ec5524cf300b0359
parent1882548f056a49945de2c3b4b7d57d283cecb012 (diff)
downloadmeson-ccab7d64f474f00e010b2c6601e63d8034c5552a.zip
meson-ccab7d64f474f00e010b2c6601e63d8034c5552a.tar.gz
meson-ccab7d64f474f00e010b2c6601e63d8034c5552a.tar.bz2
Add support for @CURRENT_SOURCE_DIR@ in generator arguments
Allow users to specify @CURRENT_SOURCE_DIR@ in generator arguments to specify the current target source directory. This is useful when creating protobuf generator objects in sub-directories because protoc will then generate files in the expected location. Fixes #1622. Remove stray semicolon Update documentation
-rw-r--r--docs/markdown/Reference-manual.md1
-rw-r--r--mesonbuild/backend/backends.py4
-rw-r--r--mesonbuild/backend/ninjabackend.py2
-rw-r--r--mesonbuild/backend/vs2010backend.py2
-rw-r--r--test cases/frameworks/5 protocol buffers/asubdir/defs.proto3
-rw-r--r--test cases/frameworks/5 protocol buffers/asubdir/main.cpp9
-rw-r--r--test cases/frameworks/5 protocol buffers/asubdir/meson.build8
-rw-r--r--test cases/frameworks/5 protocol buffers/meson.build2
8 files changed, 31 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index b46f907..276c9c9 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -318,6 +318,7 @@ In addition to the above substitutions, the `arguments` keyword argument also ac
- `@OUTPUT@`: the full path to the output file
- `@INPUT@`: the full path to the input file
- `@SOURCE_DIR@`: the full path to the root of the source tree
+- `@CURRENT_SOURCE_DIR@`: this is the directory where the currently processed meson.build is located in
- `@BUILD_DIR@`: the full path to the root of the build dir where the output will be placed
NOTE: Generators should only be used for outputs that will ***only*** be used as inputs for a [build target](#build_target) or a [custom target](#custom_target). When you use the processed output of a generator in multiple targets, the generator will be run multiple times to create outputs for each target. Each output will be created in a target-private directory `@BUILD_DIR@`.
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 5bb58f5..419d04f 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -149,6 +149,10 @@ class Backend:
dirname = 'meson-out'
return dirname
+ def get_target_source_dir(self, target):
+ dirname = os.path.join(self.build_to_src, self.get_target_dir(target))
+ return dirname
+
def get_target_private_dir(self, target):
dirname = os.path.join(self.get_target_dir(target), target.get_basename() + target.type_suffix())
return dirname
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index dad752b..f4c78a1 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1660,6 +1660,7 @@ rule FORTRAN_DEP_HACK
outfilelist = genlist.get_outputs()
base_args = generator.get_arglist()
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
+ source_target_dir = self.get_target_source_dir(target)
for i in range(len(infilelist)):
if len(generator.outputs) == 1:
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i])
@@ -1686,6 +1687,7 @@ rule FORTRAN_DEP_HACK
relout = self.get_target_private_dir(target)
args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout)
for x in args]
+ args = [x.replace("@CURRENT_SOURCE_DIR@", source_target_dir) for x in args]
args = [x.replace("@SOURCE_ROOT@", self.build_to_src).replace("@BUILD_ROOT@", '.')
for x in args]
cmdlist = exe_arr + self.replace_extra_args(args, genlist)
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index e910a03..533edf0 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -120,6 +120,7 @@ class Vs2010Backend(backends.Backend):
custom_target_include_dirs = []
custom_target_output_files = []
target_private_dir = self.relpath(self.get_target_private_dir(target), self.get_target_dir(target))
+ source_target_dir = self.get_target_source_dir(target)
down = self.target_to_build_root(target)
for genlist in target.get_generated_sources():
if isinstance(genlist, build.CustomTarget):
@@ -154,6 +155,7 @@ class Vs2010Backend(backends.Backend):
args = [x.replace("@SOURCE_DIR@", self.environment.get_source_dir())
.replace("@BUILD_DIR@", target_private_dir)
for x in args]
+ args = [x.replace("@CURRENT_SOURCE_DIR@", source_target_dir) for x in args]
args = [x.replace("@SOURCE_ROOT@", self.environment.get_source_dir())
.replace("@BUILD_ROOT@", self.environment.get_build_dir())
for x in args]
diff --git a/test cases/frameworks/5 protocol buffers/asubdir/defs.proto b/test cases/frameworks/5 protocol buffers/asubdir/defs.proto
new file mode 100644
index 0000000..f795651
--- /dev/null
+++ b/test cases/frameworks/5 protocol buffers/asubdir/defs.proto
@@ -0,0 +1,3 @@
+message Dummy {
+ required string text = 1;
+}
diff --git a/test cases/frameworks/5 protocol buffers/asubdir/main.cpp b/test cases/frameworks/5 protocol buffers/asubdir/main.cpp
new file mode 100644
index 0000000..f6566d5
--- /dev/null
+++ b/test cases/frameworks/5 protocol buffers/asubdir/main.cpp
@@ -0,0 +1,9 @@
+#include "defs.pb.h"
+
+int main(int argc, char **argv) {
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+ Dummy *d = new Dummy;
+ delete d;
+ google::protobuf::ShutdownProtobufLibrary();
+ return 0;
+}
diff --git a/test cases/frameworks/5 protocol buffers/asubdir/meson.build b/test cases/frameworks/5 protocol buffers/asubdir/meson.build
new file mode 100644
index 0000000..9727165
--- /dev/null
+++ b/test cases/frameworks/5 protocol buffers/asubdir/meson.build
@@ -0,0 +1,8 @@
+subdirgen = generator(protoc, \
+ output : ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
+ arguments : ['--proto_path=@CURRENT_SOURCE_DIR@', '--cpp_out=@BUILD_DIR@', '@INPUT@'])
+
+generated = subdirgen.process('defs.proto')
+e = executable('subdir-prog', 'main.cpp', generated,
+ dependencies : dep)
+test('subdir-prototest', e)
diff --git a/test cases/frameworks/5 protocol buffers/meson.build b/test cases/frameworks/5 protocol buffers/meson.build
index c99e0a8..58666f9 100644
--- a/test cases/frameworks/5 protocol buffers/meson.build
+++ b/test cases/frameworks/5 protocol buffers/meson.build
@@ -16,3 +16,5 @@ generated = gen.process('defs.proto')
e = executable('prog', 'main.cpp', generated,
dependencies : dep)
test('prototest', e)
+
+subdir('asubdir')