Commit Graph

67 Commits

Author SHA1 Message Date
Dylan Baker ec48dbd2d6 interpreterobjects: Clean up GeneratedListHolder
Remove an unused method (that didn't work before this series), and
remove the ability to pass a Generator to the GeneratedListHolder, it's
never used and it's weird and not the way Meson generally works now.
While we're here, finish the type annotations.
2021-06-15 12:48:53 -07:00
Dylan Baker c422621317 interpreterobjects|build: use typed_kwargs for generator.process 2021-06-15 12:48:53 -07:00
Dylan Baker 5952dc9818 interpreter|build: use typed_pos_args and unholder in the interpreter
For generator.process_files. Just cleaner and nicer
2021-06-15 12:48:53 -07:00
Dylan Baker 491c756dc9 interpreter: use typed_kwargs for func_generator
Do the type checking in a nice tidy way
2021-06-15 12:48:53 -07:00
Dylan Baker 2ac9b32391 interpreter: Do not create Generator in GeneratorHolder
This is an odd pattern, not the way most Holders work, and would be
problematic if a method wanted to return a Generator.
2021-06-15 12:48:53 -07:00
Dylan Baker 2bc7a1b3da modules/qt: fully annotate and check qt.has_tools 2021-06-15 12:36:05 -07:00
Jussi Pakkanen a4a61b6bf8
Merge pull request #8512 from bonzini/feature-methods
Utility methods for feature objects
2021-06-08 12:37:25 +03:00
Paolo Bonzini a87e32d181 interpreter: add feature.disable_auto_if()
Add a method to downgrade an option to disabled if it is not used.
This is useful to avoid unnecessary search for dependencies;
for example

    dep = dependency('dep', required: get_option('feature').disable_auto_if(not foo))

can be used instead of the more verbose and complex

    if get_option('feature').auto() and not foo then
      dep = dependency('', required: false)
    else
      dep = dependency('dep', required: get_option('feature'))
    endif

or to avoid unnecessary dependency searches:

  dep1 = dependency('dep1', required: get_option('foo'))
  # dep2 is only used together with dep1
  dep2 = dependency('dep2', required: get_option('foo').disable_auto_if(not dep1.found()))
 ```

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-06-08 10:18:12 +02:00
Paolo Bonzini 2f2d99e1d8 interpreter: add feature.require()
Add a method to perform a logical AND on a feature object.  The method
also takes care of raising an error if 'enabled' is ANDed with false.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-06-08 10:18:12 +02:00
Dylan Baker 6f562ed734 interpreterobjects: Fix type annotation for CustomTargetHolder 2021-06-04 20:10:05 -07:00
Paolo Bonzini 5298d8eaf1 interpreter: wrap access to Feature value
This will allow adding "forced-off" Feature objects in the next patch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-05-31 16:01:57 +02:00
Paolo Bonzini 08a8043f19 interpreter: add feature.allowed()
This method simplifies the conversion of Feature objects to booleans.
Often, one has to use the "not" operator in order to treat "auto"
and "enabled" the same way.

"allowed()" also works well in conjunction with the require method that
is introduced in the next patch.  For example,

  if get_option('foo').require(host_machine.system() == 'windows').allowed() then
    src += ['foo.c']
    config.set10('HAVE_FOO', 1)
  endif

can be used instead of

  if host_machine.system() != 'windows'
    if get_option('foo').enabled()
      error('...')
    endif
  endif
  if not get_option('foo').disabled() then
    src += ['foo.c']
    config.set10('HAVE_FOO', 1)
  endif

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-05-31 16:01:57 +02:00
Xavier Claessens 2e02ef6592 modules: Add methods dict everywhere
This fix calling random internal methods from meson.build as long as
they were not prefixed by underscore.
2021-05-28 15:17:10 -04:00
Xavier Claessens 3340284805 modules: Stop using InterpreterObject
Custom objects returned by modules must be subclass of ModuleObject and
have the state argument in its methods.

Add MutableModuleObject base class for objects that needs to be deep
copied on assignation.
2021-05-28 15:17:10 -04:00
Xavier Claessens 723c5227a4 modules: Remove snippet methods
The only advantage they have is they have the interpreter in arguments,
but it's already available as self.interpreter. We should discourage
usage of the interpreter API and rely on ModuleState object instead in
the future.

This also lift the restriction that a module method cannot add build
targets, but that was not enforced for snippet methods anyway (and some
modules were doing it) and it's really loose restriction as it should
check for many other things if we wanted to make it consistent.
2021-05-28 15:17:10 -04:00
Xavier Claessens 501d7cf01c interpreter: flatten environment() initial values
Turns out listify() flattens by default, but stringlistify() cannot
flatten... How do I realize this only now?

Fixes: #8727
2021-05-13 10:38:17 +03:00
Xavier Claessens 558a7bc6ff interpreter: Move to its own folder and split it 2021-04-01 14:26:33 -04:00