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>
pull/5795/head
James Hilliard 5 years ago committed by Jussi Pakkanen
parent 8764e4f579
commit b21fd95f73
  1. 1
      data/syntax-highlighting/vim/syntax/meson.vim
  2. 8
      docs/markdown/Reference-manual.md
  3. 11
      docs/markdown/Release-notes-for-0.52.0.md
  4. 1
      docs/sitemap.txt
  5. 1
      mesonbuild/ast/interpreter.py
  6. 9
      mesonbuild/interpreter.py
  7. 2
      mesonbuild/interpreterbase.py
  8. 10
      run_unittests.py
  9. 10
      test cases/common/1 trivial/meson.build
  10. 22
      test cases/common/156 index customtarget/meson.build
  11. 35
      test cases/common/163 disabler/meson.build
  12. 10
      test cases/common/2 cpp/meson.build
  13. 10
      test cases/common/3 static/meson.build
  14. 10
      test cases/common/4 shared/meson.build
  15. 10
      test cases/common/52 custom target/meson.build

@ -98,6 +98,7 @@ syn keyword mesonBuiltin
\ install_headers
\ install_man
\ install_subdir
\ is_disabler
\ is_variable
\ jar
\ join_paths

@ -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

@ -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.

@ -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

@ -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,

@ -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)

@ -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]

@ -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

@ -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.')

@ -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],

@ -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.')

@ -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.')

@ -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.')

@ -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.')

@ -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')

Loading…
Cancel
Save