diff options
author | James Hilliard <james.hilliard1@gmail.com> | 2019-05-26 12:31:43 -0600 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-08-12 01:05:45 +0300 |
commit | b21fd95f737ab96f57c45e15a1d89d5c483daec8 (patch) | |
tree | f19e6f869220b3832d4e586901d10bb059d5a5d8 | |
parent | 8764e4f579287d2bc15d5ea8b0a5382c90712ec0 (diff) | |
download | meson-b21fd95f737ab96f57c45e15a1d89d5c483daec8.zip meson-b21fd95f737ab96f57c45e15a1d89d5c483daec8.tar.gz meson-b21fd95f737ab96f57c45e15a1d89d5c483daec8.tar.bz2 |
Add is_disabler function
This is useful if one needs to check if a variable is a disabler.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
-rw-r--r-- | data/syntax-highlighting/vim/syntax/meson.vim | 1 | ||||
-rw-r--r-- | docs/markdown/Reference-manual.md | 8 | ||||
-rw-r--r-- | docs/markdown/Release-notes-for-0.52.0.md | 11 | ||||
-rw-r--r-- | docs/sitemap.txt | 1 | ||||
-rw-r--r-- | mesonbuild/ast/interpreter.py | 1 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 9 | ||||
-rw-r--r-- | mesonbuild/interpreterbase.py | 2 | ||||
-rwxr-xr-x | run_unittests.py | 10 | ||||
-rw-r--r-- | test cases/common/1 trivial/meson.build | 10 | ||||
-rw-r--r-- | test cases/common/156 index customtarget/meson.build | 22 | ||||
-rw-r--r-- | test cases/common/163 disabler/meson.build | 35 | ||||
-rw-r--r-- | test cases/common/2 cpp/meson.build | 10 | ||||
-rw-r--r-- | test cases/common/3 static/meson.build | 10 | ||||
-rw-r--r-- | test cases/common/4 shared/meson.build | 10 | ||||
-rw-r--r-- | test cases/common/52 custom target/meson.build | 10 |
15 files changed, 149 insertions, 1 deletions
diff --git a/data/syntax-highlighting/vim/syntax/meson.vim b/data/syntax-highlighting/vim/syntax/meson.vim index 94936c8..6742616 100644 --- a/data/syntax-highlighting/vim/syntax/meson.vim +++ b/data/syntax-highlighting/vim/syntax/meson.vim @@ -98,6 +98,7 @@ syn keyword mesonBuiltin \ install_headers \ install_man \ install_subdir + \ is_disabler \ is_variable \ jar \ join_paths diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 6be3ed7..a89d939 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1061,6 +1061,14 @@ share/ file1 ``` +### is_disabler() + +``` meson + bool is_disabler(var) +``` + +Returns true if a variable is a disabler and false otherwise. Added in 0.52.0. + ### is_variable() ``` meson diff --git a/docs/markdown/Release-notes-for-0.52.0.md b/docs/markdown/Release-notes-for-0.52.0.md new file mode 100644 index 0000000..c36758a --- /dev/null +++ b/docs/markdown/Release-notes-for-0.52.0.md @@ -0,0 +1,11 @@ +--- +title: Release 0.52.0 +short-description: Release notes for 0.52.0 +... + +# New features + +## Allow checking if a variable is a disabler + +Added the function `is_disabler(var)`. Returns true if a variable is a disabler +and false otherwise. diff --git a/docs/sitemap.txt b/docs/sitemap.txt index 6ebf63b..c2bc610 100644 --- a/docs/sitemap.txt +++ b/docs/sitemap.txt @@ -75,6 +75,7 @@ index.md Shipping-prebuilt-binaries-as-wraps.md fallback-wraptool.md Release-notes.md + Release-notes-for-0.52.0.md Release-notes-for-0.51.0.md Release-notes-for-0.50.0.md Release-notes-for-0.49.0.md diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index 13c717b..6684ca4 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -106,6 +106,7 @@ class AstInterpreter(interpreterbase.InterpreterBase): 'subdir': self.func_subdir, 'set_variable': self.func_do_nothing, 'get_variable': self.func_do_nothing, + 'is_disabler': self.func_do_nothing, 'is_variable': self.func_do_nothing, 'disabler': self.func_do_nothing, 'gettext': self.func_do_nothing, diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index d45b313..3a5dfaf 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2147,6 +2147,7 @@ class Interpreter(InterpreterBase): 'install_headers': self.func_install_headers, 'install_man': self.func_install_man, 'install_subdir': self.func_install_subdir, + 'is_disabler': self.func_is_disabler, 'is_variable': self.func_is_variable, 'jar': self.func_jar, 'join_paths': self.func_join_paths, @@ -4278,3 +4279,11 @@ This will become a hard error in the future.''', location=self.current_node) if not isinstance(native, bool): raise InvalidArguments('Argument to "native" must be a boolean.') return MachineChoice.BUILD if native else MachineChoice.HOST + + @FeatureNew('is_disabler', '0.52.0') + @noKwargs + def func_is_disabler(self, node, args, kwargs): + if len(args) != 1: + raise InvalidCode('Is_disabler takes one argument.') + varname = args[0] + return isinstance(varname, Disabler) diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index b5510cf..082515c 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -767,7 +767,7 @@ The result of this is undefined and will become a hard error in a future Meson r def function_call(self, node): func_name = node.func_name (posargs, kwargs) = self.reduce_arguments(node.args) - if is_disabled(posargs, kwargs): + if is_disabled(posargs, kwargs) and func_name != 'set_variable' and func_name != 'is_disabler': return Disabler() if func_name in self.funcs: func = self.funcs[func_name] diff --git a/run_unittests.py b/run_unittests.py index 735f3e2..26850b7 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -105,6 +105,15 @@ def is_ci(): return True return False +def is_pull(): + # Travis + if os.environ.get('TRAVIS_PULL_REQUEST', 'false') != 'false': + return True + # Azure + if 'SYSTEM_PULLREQUEST_ISFORK' in os.environ: + return True + return False + def _git_init(project_dir): subprocess.check_call(['git', 'init'], cwd=project_dir, stdout=subprocess.DEVNULL) subprocess.check_call(['git', 'config', @@ -1144,6 +1153,7 @@ class DataTests(unittest.TestCase): defined = set([a.strip() for a in res.group().split('\\')][1:]) self.assertEqual(defined, set(chain(interp.funcs.keys(), interp.builtin.keys()))) + @unittest.skipIf(is_pull(), 'Skipping because this is a pull request') def test_json_grammar_syntax_highlighting(self): ''' Ensure that syntax highlighting JSON grammar written by TingPing was diff --git a/test cases/common/1 trivial/meson.build b/test cases/common/1 trivial/meson.build index c71d9b0..557274f 100644 --- a/test cases/common/1 trivial/meson.build +++ b/test cases/common/1 trivial/meson.build @@ -22,3 +22,13 @@ endif exe = executable('trivialprog', sources : sources) test('runtest', exe) # This is a comment + +has_not_changed = false +if is_disabler(exe) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Executable has changed.') + +assert(not is_disabler(exe), 'Executable is a disabler.') diff --git a/test cases/common/156 index customtarget/meson.build b/test cases/common/156 index customtarget/meson.build index 27d28b5..b06ceea 100644 --- a/test cases/common/156 index customtarget/meson.build +++ b/test cases/common/156 index customtarget/meson.build @@ -24,11 +24,33 @@ gen = custom_target( command : [prog_python, '@INPUT@', '--header', '@OUTPUT1@', '--code', '@OUTPUT0@'], ) +has_not_changed = false +if is_disabler(gen) + has_not_changed = true +else + has_not_changed = true +endif + +assert(has_not_changed, 'Custom target has changed.') + +assert(not is_disabler(gen), 'Custom target is a disabler.') + lib = static_library( 'libfoo', ['lib.c', gen[1]], ) +has_not_changed = false +if is_disabler(lib) + has_not_changed = true +else + has_not_changed = true +endif + +assert(has_not_changed, 'Static library has changed.') + +assert(not is_disabler(lib), 'Static library is a disabler.') + custom_target( 'foo', input: gen[0], diff --git a/test cases/common/163 disabler/meson.build b/test cases/common/163 disabler/meson.build index 9437ace..5eb24ba 100644 --- a/test cases/common/163 disabler/meson.build +++ b/test cases/common/163 disabler/meson.build @@ -7,6 +7,20 @@ d3 = (d == d2) d4 = d + 0 d5 = d2 or true +has_not_changed = false +if is_disabler(d) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Disabler has changed.') + +assert(is_disabler(d), 'Disabler was not identified correctly.') +assert(is_disabler(d2), 'Function laundered disabler was not identified correctly.') +assert(is_disabler(d3), 'Disabler comparison should yield disabler.') +assert(is_disabler(d4), 'Disabler addition should yield disabler.') +assert(is_disabler(d5), 'Disabler logic op should yield disabler.') + assert(d, 'Disabler did not cause this to be skipped.') assert(d2, 'Function laundered disabler did not cause this to be skipped.') assert(d3, 'Disabler comparison should yield disabler and thus this would not be called.') @@ -21,6 +35,15 @@ else number = 2 endif +has_not_changed = false +if is_disabler(number) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Number has changed.') + +assert(not is_disabler(number), 'Number should not be a disabler.') assert(number == 0, 'Plain if handled incorrectly, value should be 0 but is @0@'.format(number)) if d.found() @@ -33,11 +56,23 @@ assert(number == 2, 'If found handled incorrectly, value should be 2 but is @0@' dep = dependency('notfounddep', required : false, disabler : true) app = executable('myapp', 'notfound.c', dependencies : [dep]) +assert(is_disabler(app), 'App is not a disabler.') app = executable('myapp', 'notfound.c', dependencies : [[dep]]) +assert(is_disabler(app), 'App is not a disabler.') cc = meson.get_compiler('c') dep = cc.find_library('notfounddep', required : false, disabler : true) app = executable('myapp', 'notfound.c', dependencies : [dep]) +assert(is_disabler(app), 'App is not a disabler.') dep = find_program('donotfindme', required : false, disabler : true) app = executable('myapp', 'notfound.c', dependencies : [dep]) +assert(is_disabler(app), 'App is not a disabler.') + +has_not_changed = false +if is_disabler(app) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'App has changed.') diff --git a/test cases/common/2 cpp/meson.build b/test cases/common/2 cpp/meson.build index 27c4321..23c8e72 100644 --- a/test cases/common/2 cpp/meson.build +++ b/test cases/common/2 cpp/meson.build @@ -10,3 +10,13 @@ endif exe = executable('trivialprog', 'trivial.cc', extra_files : 'something.txt') test('runtest', exe) + +has_not_changed = false +if is_disabler(exe) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Executable has changed.') + +assert(not is_disabler(exe), 'Executable is a disabler.') diff --git a/test cases/common/3 static/meson.build b/test cases/common/3 static/meson.build index e539956..84dab95 100644 --- a/test cases/common/3 static/meson.build +++ b/test cases/common/3 static/meson.build @@ -2,3 +2,13 @@ project('static library test', 'c') lib = static_library('mylib', get_option('source'), link_args : '-THISMUSTNOBEUSED') # Static linker needs to ignore all link args. + +has_not_changed = false +if is_disabler(lib) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Static library has changed.') + +assert(not is_disabler(lib), 'Static library is a disabler.') diff --git a/test cases/common/4 shared/meson.build b/test cases/common/4 shared/meson.build index b2c8fa3..1c88bc5 100644 --- a/test cases/common/4 shared/meson.build +++ b/test cases/common/4 shared/meson.build @@ -1,3 +1,13 @@ project('shared library test', 'c') lib = shared_library('mylib', 'libfile.c') build_target('mylib2', 'libfile.c', target_type: 'shared_library') + +has_not_changed = false +if is_disabler(lib) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Shared library has changed.') + +assert(not is_disabler(lib), 'Shared library is a disabler.') diff --git a/test cases/common/52 custom target/meson.build b/test cases/common/52 custom target/meson.build index 2e6f69c..824ab48 100644 --- a/test cases/common/52 custom target/meson.build +++ b/test cases/common/52 custom target/meson.build @@ -19,4 +19,14 @@ install : true, install_dir : 'subdir' ) +has_not_changed = false +if is_disabler(mytarget) + has_not_changed = true +else + has_not_changed = true +endif +assert(has_not_changed, 'Custom target has changed.') + +assert(not is_disabler(mytarget), 'Custom target is a disabler.') + subdir('depfile') |