-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow configure_file, custom_target and generator output to subdirectories under build dir #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jasonszang
wants to merge
7
commits into
mesonbuild:master
from
jasonszang:feature/gen_source_in_subdir
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
413a05e
Allow configure_file to output to subdirectories of current build dir.
jasonszang 4c75b50
Allow custom_target to output to subdirectories of current build dir.
jasonszang 31c7547
Allow generator to output to subdirectories under output dir.
jasonszang a657964
Make @ROOTNAME@ also available to custom_targets and a minor bug fix.
jasonszang a7ac10f
Add tests for new features.
jasonszang 6424f10
Replace failing test case "output subdir" with "output escaping" as o…
jasonszang ebb7970
Use pathlib instead of os.path to check for '..' and fix a bug breaki…
jasonszang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,7 @@ def test_string_templates_substitution(self): | |
| outputs = [] | ||
| ret = dictfunc(inputs, outputs) | ||
| d = {'@INPUT@': inputs, '@INPUT0@': inputs[0], | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c'} | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c', '@ROOTNAME@': "bar/foo.c"} | ||
| # Check dictionary | ||
| self.assertEqual(ret, d) | ||
| # Check substitutions | ||
|
|
@@ -235,6 +235,9 @@ def test_string_templates_substitution(self): | |
| cmd = ['@INPUT@', '@[email protected]', 'strings'] | ||
| self.assertEqual(substfunc(cmd, d), | ||
| inputs + [d['@BASENAME@'] + '.hah'] + cmd[2:]) | ||
| cmd = ['@INPUT@', '@[email protected]', 'strings'] | ||
| self.assertEqual(substfunc(cmd, d), | ||
| inputs + [d['@ROOTNAME@'] + '.bar'] + cmd[2:]) | ||
| cmd = ['@OUTPUT@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
|
|
||
|
|
@@ -243,8 +246,8 @@ def test_string_templates_substitution(self): | |
| outputs = ['out.c'] | ||
| ret = dictfunc(inputs, outputs) | ||
| d = {'@INPUT@': inputs, '@INPUT0@': inputs[0], | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c', | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0], '@OUTDIR@': '.'} | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c', '@ROOTNAME@': 'bar/foo.c', | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0]} | ||
| # Check dictionary | ||
| self.assertEqual(ret, d) | ||
| # Check substitutions | ||
|
|
@@ -259,13 +262,16 @@ def test_string_templates_substitution(self): | |
| cmd = ['@INPUT@', '@[email protected]', 'strings'] | ||
| self.assertEqual(substfunc(cmd, d), | ||
| inputs + [d['@BASENAME@'] + '.hah'] + cmd[2:]) | ||
| cmd = ['@INPUT@', '@[email protected]', 'strings'] | ||
| self.assertEqual(substfunc(cmd, d), | ||
| inputs + [d['@ROOTNAME@'] + '.bar'] + cmd[2:]) | ||
|
|
||
| # One input, one output with a subdir | ||
| outputs = ['dir/out.c'] | ||
| ret = dictfunc(inputs, outputs) | ||
| d = {'@INPUT@': inputs, '@INPUT0@': inputs[0], | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c', | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0], '@OUTDIR@': 'dir'} | ||
| '@PLAINNAME@': 'foo.c.in', '@BASENAME@': 'foo.c', '@ROOTNAME@': 'bar/foo.c', | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0]} | ||
| # Check dictionary | ||
| self.assertEqual(ret, d) | ||
|
|
||
|
|
@@ -298,19 +304,19 @@ def test_string_templates_substitution(self): | |
| self.assertRaises(ME, substfunc, cmd, d) | ||
| cmd = ['@BASENAME@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
| cmd = ['@ROOTNAME@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
| # No outputs | ||
| cmd = ['@OUTPUT@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
| cmd = ['@OUTPUT0@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
| cmd = ['@OUTDIR@'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
|
|
||
| # Two inputs, one output | ||
| outputs = ['dir/out.c'] | ||
| ret = dictfunc(inputs, outputs) | ||
| d = {'@INPUT@': inputs, '@INPUT0@': inputs[0], '@INPUT1@': inputs[1], | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0], '@OUTDIR@': 'dir'} | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0]} | ||
| # Check dictionary | ||
| self.assertEqual(ret, d) | ||
| # Check substitutions | ||
|
|
@@ -336,8 +342,7 @@ def test_string_templates_substitution(self): | |
| outputs = ['dir/out.c', 'dir/out2.c'] | ||
| ret = dictfunc(inputs, outputs) | ||
| d = {'@INPUT@': inputs, '@INPUT0@': inputs[0], '@INPUT1@': inputs[1], | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0], '@OUTPUT1@': outputs[1], | ||
| '@OUTDIR@': 'dir'} | ||
| '@OUTPUT@': outputs, '@OUTPUT0@': outputs[0], '@OUTPUT1@': outputs[1]} | ||
| # Check dictionary | ||
| self.assertEqual(ret, d) | ||
| # Check substitutions | ||
|
|
@@ -347,8 +352,8 @@ def test_string_templates_substitution(self): | |
| self.assertEqual(substfunc(cmd, d), outputs + cmd[1:]) | ||
| cmd = ['@OUTPUT0@', '@OUTPUT1@', 'strings'] | ||
| self.assertEqual(substfunc(cmd, d), outputs + cmd[2:]) | ||
| cmd = ['@[email protected]', '@[email protected]', '@OUTDIR@'] | ||
| self.assertEqual(substfunc(cmd, d), [outputs[0] + '.out', inputs[1] + '.ok', 'dir']) | ||
| cmd = ['@[email protected]', '@[email protected]'] | ||
| self.assertEqual(substfunc(cmd, d), [outputs[0] + '.out', inputs[1] + '.ok']) | ||
| # Many inputs, can't use @INPUT@ like this | ||
| cmd = ['@[email protected]', 'ordinary', 'strings'] | ||
| self.assertRaises(ME, substfunc, cmd, d) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // An ordinary header. |
1 change: 1 addition & 0 deletions
1
test cases/common/16 configure file/include/prjdir/version.h.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #define VERSION "@version@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include <prjdir/foo.h> | ||
| #include <prjdir/version.h> | ||
|
|
||
| int main(int argc, char **argv) { | ||
| return strcmp(VERSION, "1.0.0"); | ||
| } |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ases/failing/27 output subdir/meson.build → ...es/failing/27 output escaping/meson.build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| project('outdir path', 'c') | ||
|
|
||
| configure_file(input : 'foo.in', | ||
| output : 'subdir/foo', | ||
| output : '../subdir/foo', | ||
| configuration : configuration_data()) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,52 @@ | ||
| project('protocol buffer test', 'cpp') | ||
|
|
||
| protoc = find_program('protoc', required : false) | ||
| dep = dependency('protobuf', required : false) | ||
| protobuf_dep = dependency('protobuf') | ||
| protoc = find_program('protoc') | ||
|
|
||
| if not protoc.found() or not dep.found() | ||
| if not protoc.found() or not protobuf_dep.found() | ||
| error('MESON_SKIP_TEST: protoc tool and/or protobuf pkg-config dependency not found') | ||
| endif | ||
|
|
||
| # Builds a proto subtree from top_level meson.build. | ||
| # Currently build proto subtree from outside requires a little hack in order to get proto headers | ||
| # currectly on include paths. Building with subdir at the top level of proto subtree is a cleaner | ||
| # solution. | ||
| protos_basename = [ | ||
| 'messages/dummy_messages', | ||
| 'dummy_service', | ||
| ] | ||
| protos_src = [] | ||
| protos_hdr = [] | ||
| foreach p : protos_basename | ||
| cc_target = custom_target( | ||
| p.underscorify(), | ||
| input: 'proto/' + p + '.proto', | ||
| output: [p + '.pb.cc', p + '.pb.h'], | ||
| command: [protoc, '-I', '@CURRENT_SOURCE_DIR@/proto', '--cpp_out', '@OUTDIR@', '@INPUT@'] | ||
| ) | ||
| protos_src += cc_target[0] | ||
| protos_hdr += cc_target[1] | ||
| endforeach | ||
|
|
||
| gen = generator(protoc, \ | ||
| output : ['@[email protected]', '@[email protected]'], | ||
| arguments : ['--proto_path=@SOURCE_DIR@', '--cpp_out=@BUILD_DIR@', '@INPUT@']) | ||
| # Builds another proto subtree in a subdir | ||
| subdir('proto_subdir') | ||
|
|
||
| generated = gen.process('defs.proto') | ||
| e = executable('prog', 'main.cpp', generated, | ||
| dependencies : dep) | ||
| test('prototest', e) | ||
| # Builds proto trees with generators. This acturally looks cleaner than the custom_target | ||
| # approach, but with some limits: it requires that the current source dir to be treated as | ||
| # proto root, instead of the top level of the proto tree. This may require changes of existing | ||
| # code. | ||
| proto_gen = generator(protoc, | ||
| arguments: ['-I', '@CURRENT_SOURCE_DIR@', '--cpp_out', '@BUILD_DIR@', '@INPUT@'], | ||
| output: ['@[email protected]', '@[email protected]'], | ||
| ) | ||
| protos_name = [ | ||
| 'proto_generator/messages/dummy_messages3.proto', | ||
| 'proto_generator/dummy_service3.proto', | ||
| ] | ||
| protos_gen_src = proto_gen.process(protos_name) | ||
|
|
||
| subdir('asubdir') | ||
| dummy_bin = executable( | ||
| 'prog', | ||
| ['src/prog.cpp', protos_src, protos_hdr, protos_subdir_src, protos_subdir_hdr, protos_gen_src], | ||
| dependencies: protobuf_dep, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just use
pathlib.PurePathand then check.partsfor...