aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-04-08 21:21:19 +0300
committerGitHub <noreply@github.com>2017-04-08 21:21:19 +0300
commit664c2c909b35e8c37becf7bdfc948bf365a38e80 (patch)
tree06192c74e5b86559fba3a3be801f9fbbb54bf554
parentaad21d26393326b61eefaef837aedb17e494f5ee (diff)
parenta00ab548ebc323d52a1ff59dd9a8adec9ce0302a (diff)
downloadmeson-664c2c909b35e8c37becf7bdfc948bf365a38e80.zip
meson-664c2c909b35e8c37becf7bdfc948bf365a38e80.tar.gz
meson-664c2c909b35e8c37becf7bdfc948bf365a38e80.tar.bz2
Merge pull request #1580 from pitti/feature/add-arguments-language-list
Add support for language list in add_*_arguments
-rw-r--r--mesonbuild/interpreter.py103
-rw-r--r--test cases/common/123 subproject project arguments/exe.c4
-rw-r--r--test cases/common/123 subproject project arguments/exe.cpp4
-rw-r--r--test cases/common/123 subproject project arguments/meson.build5
-rw-r--r--test cases/common/123 subproject project arguments/subprojects/subexe/subexe.c4
-rw-r--r--test cases/common/23 global arg/meson.build2
-rw-r--r--test cases/common/23 global arg/prog.c4
-rw-r--r--test cases/common/23 global arg/prog.cc4
8 files changed, 62 insertions, 68 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index bf3dffe..d1ac569 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1239,7 +1239,8 @@ class Interpreter(InterpreterBase):
self.builtin.update({'meson': MesonMain(build, self)})
self.generators = []
self.visited_subdirs = {}
- self.args_frozen = False
+ self.project_args_frozen = False
+ self.global_args_frozen = False # implies self.project_args_frozen
self.subprojects = {}
self.subproject_stack = []
self.default_project_options = default_project_options[:] # Passed from the outside, only used in subprojects.
@@ -1522,7 +1523,7 @@ class Interpreter(InterpreterBase):
raise InterpreterException(msg.format(os.path.join(self.subproject_dir, dirname), e))
subdir = os.path.join(self.subproject_dir, resolved)
os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True)
- self.args_frozen = True
+ self.global_args_frozen = True
mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='')
subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir,
mesonlib.stringlistify(kwargs.get('default_options', [])))
@@ -2439,83 +2440,51 @@ different subdirectory.
@stringArgs
def func_add_global_arguments(self, node, args, kwargs):
- if self.subproject != '':
- msg = 'Global arguments can not be set in subprojects because ' \
- 'there is no way to make that reliable.\nPlease only call ' \
- 'this if is_subproject() returns false. Alternatively, ' \
- 'define a variable that\ncontains your language-specific ' \
- 'arguments and add it to the appropriate *_args kwarg ' \
- 'in each target.'
- raise InvalidCode(msg)
- if self.args_frozen:
- msg = 'Tried to set global arguments after a build target has ' \
- 'been declared.\nThis is not permitted. Please declare all ' \
- 'global arguments before your targets.'
- raise InvalidCode(msg)
- if 'language' not in kwargs:
- raise InvalidCode('Missing language definition in add_global_arguments')
- lang = kwargs['language'].lower()
- if lang in self.build.global_args:
- self.build.global_args[lang] += args
- else:
- self.build.global_args[lang] = args
+ self.add_global_arguments(node, self.build.global_args, args, kwargs)
@stringArgs
def func_add_global_link_arguments(self, node, args, kwargs):
+ self.add_global_arguments(node, self.build.global_link_args, args, kwargs)
+
+ @stringArgs
+ def func_add_project_arguments(self, node, args, kwargs):
+ self.add_project_arguments(node, self.build.projects_args, args, kwargs)
+
+ @stringArgs
+ def func_add_project_link_arguments(self, node, args, kwargs):
+ self.add_project_arguments(node, self.build.projects_link_args, args, kwargs)
+
+ def add_global_arguments(self, node, argsdict, args, kwargs):
if self.subproject != '':
- msg = 'Global link arguments can not be set in subprojects because ' \
+ msg = 'Function \'{}\' cannot be used in subprojects because ' \
'there is no way to make that reliable.\nPlease only call ' \
'this if is_subproject() returns false. Alternatively, ' \
'define a variable that\ncontains your language-specific ' \
'arguments and add it to the appropriate *_args kwarg ' \
- 'in each target.'
+ 'in each target.'.format(node.func_name)
raise InvalidCode(msg)
- if self.args_frozen:
- msg = 'Tried to set global link arguments after a build target has ' \
- 'been declared.\nThis is not permitted. Please declare all ' \
- 'global arguments before your targets.'
+ frozen = self.project_args_frozen or self.global_args_frozen
+ self.add_arguments(node, argsdict, frozen, args, kwargs)
+
+ def add_project_arguments(self, node, argsdict, args, kwargs):
+ if self.subproject not in argsdict:
+ argsdict[self.subproject] = {}
+ self.add_arguments(node, argsdict[self.subproject],
+ self.project_args_frozen, args, kwargs)
+
+ def add_arguments(self, node, argsdict, args_frozen, args, kwargs):
+ if args_frozen:
+ msg = 'Tried to use \'{}\' after a build target has been declared.\n' \
+ 'This is not permitted. Please declare all ' \
+ 'arguments before your targets.'.format(node.func_name)
raise InvalidCode(msg)
- if 'language' not in kwargs:
- raise InvalidCode('Missing language definition in add_global_link_arguments')
- lang = kwargs['language'].lower()
- if lang in self.build.global_link_args:
- self.build.global_link_args[lang] += args
- else:
- self.build.global_link_args[lang] = args
- @stringArgs
- def func_add_project_link_arguments(self, node, args, kwargs):
- if self.args_frozen:
- msg = 'Tried to set project link arguments after a build target has ' \
- 'been declared.\nThis is not permitted. Please declare all ' \
- 'project link arguments before your targets.'
- raise InvalidCode(msg)
if 'language' not in kwargs:
- raise InvalidCode('Missing language definition in add_project_link_arguments')
- lang = kwargs['language'].lower()
- if self.subproject not in self.build.projects_link_args:
- self.build.projects_link_args[self.subproject] = {}
+ raise InvalidCode('Missing language definition in {}'.format(node.func_name))
- args = self.build.projects_link_args[self.subproject].get(lang, []) + args
- self.build.projects_link_args[self.subproject][lang] = args
-
- @stringArgs
- def func_add_project_arguments(self, node, args, kwargs):
- if self.args_frozen:
- msg = 'Tried to set project arguments after a build target has ' \
- 'been declared.\nThis is not permitted. Please declare all ' \
- 'project arguments before your targets.'
- raise InvalidCode(msg)
-
- if 'language' not in kwargs:
- raise InvalidCode('Missing language definition in add_project_arguments')
-
- if self.subproject not in self.build.projects_args:
- self.build.projects_args[self.subproject] = {}
-
- lang = kwargs['language'].lower()
- args = self.build.projects_args[self.subproject].get(lang, []) + args
- self.build.projects_args[self.subproject][lang] = args
+ for lang in mesonlib.stringlistify(kwargs['language']):
+ lang = lang.lower()
+ argsdict[lang] = argsdict.get(lang, []) + args
def func_environment(self, node, args, kwargs):
return EnvironmentVariablesHolder()
@@ -2600,7 +2569,7 @@ different subdirectory.
self.add_cross_stdlib_info(target)
l = targetholder(target, self)
self.add_target(name, l.held_object)
- self.args_frozen = True
+ self.project_args_frozen = True
return l
def get_used_languages(self, target):
diff --git a/test cases/common/123 subproject project arguments/exe.c b/test cases/common/123 subproject project arguments/exe.c
index b04344a..d6440f0 100644
--- a/test cases/common/123 subproject project arguments/exe.c
+++ b/test cases/common/123 subproject project arguments/exe.c
@@ -18,6 +18,10 @@
#error
#endif
+#ifndef PROJECT_OPTION_C_CPP
+#error
+#endif
+
int main(int argc, char **argv) {
return 0;
}
diff --git a/test cases/common/123 subproject project arguments/exe.cpp b/test cases/common/123 subproject project arguments/exe.cpp
index 7ffe098..8471c6f 100644
--- a/test cases/common/123 subproject project arguments/exe.cpp
+++ b/test cases/common/123 subproject project arguments/exe.cpp
@@ -18,6 +18,10 @@
#error
#endif
+#ifndef PROJECT_OPTION_C_CPP
+#error
+#endif
+
int main(int argc, char **argv) {
return 0;
}
diff --git a/test cases/common/123 subproject project arguments/meson.build b/test cases/common/123 subproject project arguments/meson.build
index aee803c..90d4c05 100644
--- a/test cases/common/123 subproject project arguments/meson.build
+++ b/test cases/common/123 subproject project arguments/meson.build
@@ -4,10 +4,13 @@ project('project options tester', 'c', 'cpp',
add_global_arguments('-DGLOBAL_ARGUMENT', language: 'c')
add_project_arguments('-DPROJECT_OPTION', language: 'c')
-add_project_arguments('-DPROJECT_OPTION_1', language: 'c')
add_project_arguments('-DPROJECT_OPTION_CPP', language: 'cpp')
+add_project_arguments('-DPROJECT_OPTION_C_CPP', language: ['c', 'cpp'])
sub = subproject('subexe', version : '1.0.0')
+
+add_project_arguments('-DPROJECT_OPTION_1', language: 'c')
+
e = executable('exe', 'exe.c')
e = executable('execpp', 'exe.cpp')
test('exetest', e)
diff --git a/test cases/common/123 subproject project arguments/subprojects/subexe/subexe.c b/test cases/common/123 subproject project arguments/subprojects/subexe/subexe.c
index 6ebd752..f748afc 100644
--- a/test cases/common/123 subproject project arguments/subprojects/subexe/subexe.c
+++ b/test cases/common/123 subproject project arguments/subprojects/subexe/subexe.c
@@ -6,6 +6,10 @@
#error
#endif
+#ifdef PROJECT_OPTION_C_CPP
+#error
+#endif
+
#ifndef GLOBAL_ARGUMENT
#error
#endif
diff --git a/test cases/common/23 global arg/meson.build b/test cases/common/23 global arg/meson.build
index aec5c2d..d7fd428 100644
--- a/test cases/common/23 global arg/meson.build
+++ b/test cases/common/23 global arg/meson.build
@@ -3,6 +3,8 @@ project('global arg test', 'cpp', 'c')
add_global_arguments('-DMYTHING', language : 'c')
add_global_arguments('-DMYCPPTHING', language : 'cpp')
+add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'])
+
exe1 = executable('prog', 'prog.c')
exe2 = executable('prog2', 'prog.cc')
diff --git a/test cases/common/23 global arg/prog.c b/test cases/common/23 global arg/prog.c
index df91777..ace5a0a 100644
--- a/test cases/common/23 global arg/prog.c
+++ b/test cases/common/23 global arg/prog.c
@@ -6,6 +6,10 @@
#error "Wrong global argument set"
#endif
+#ifndef MYCANDCPPTHING
+#error "Global argument not set"
+#endif
+
int main(int argc, char **argv) {
return 0;
}
diff --git a/test cases/common/23 global arg/prog.cc b/test cases/common/23 global arg/prog.cc
index 342fdd0..0ffd85e 100644
--- a/test cases/common/23 global arg/prog.cc
+++ b/test cases/common/23 global arg/prog.cc
@@ -6,6 +6,10 @@
#error "Global argument not set"
#endif
+#ifndef MYCANDCPPTHING
+#error "Global argument not set"
+#endif
+
int main(int argc, char **argv) {
return 0;
}