Commit Graph

46 Commits

Author SHA1 Message Date
Mathieu Duponchelle 10e7566ed8 dict: fix CI issues 2018-05-21 00:19:31 +02:00
Mathieu Duponchelle 195c356f91 dict: address review comments 2018-05-20 22:36:18 +02:00
Kyrylo Shpytsya 09dc48d941 Add methods to the dict builtin
Adds "has_key" and "get".

Adapted and updated by Mathieu Duponchelle <mathieu@centricular.com>
2018-05-20 21:19:44 +02:00
Mathieu Duponchelle ecb8838082 Add new built-in type, dict
For now dicts are immutable, and do not expose any methods,
they however support "native" syntax such as [] lookup,
and foreach iterating, and can be printed.
2018-05-20 21:19:44 +02:00
Mathieu Duponchelle f1c92d7c9c Interpreter: don't flatten the arguments of various methods
this fixes eg set_variable('foo', ['bar', 'baz']), which
was previously erroring out complaining about the number
of arguments.

Closes #1481
2018-05-04 15:24:21 +00:00
Xavier Claessens 10a9bdad96 interpreter: Verify permitted kwargs on all methods 2018-04-26 00:01:48 +03:00
behlec 37d379ebe5 Allow meson build file to exit early. (#2808) 2018-03-29 21:29:45 +03:00
Jussi Pakkanen 9ecb75670f
Merge pull request #3127 from bluetech/method-permitted-kwargs 2018-03-13 21:16:30 +02:00
Jon Turney 390333a18d Fix remaining flake8 report
$ flake8
./mesonbuild/interpreterbase.py:411:13: F821 undefined name 'set_variable'

This looks like an actual bug which would affect disabler use :)
2018-03-03 21:37:20 +00:00
Ran Benita 4d8e4654cb Warn if non-permitted keyword arguments are given to compiler methods
This can help future generations avoid mistakes like this:
edb1c66239

To avoid breaking builds, this is currently just an error. After
sufficient time has passed this can hopefully become a hard error,
similarly to the already-existing `permittedKwargs` warnings.
2018-02-23 04:35:15 +02:00
Jon Turney 7297e9f7a3 Add source location to warning for comparing different types 2018-02-15 12:53:46 +00:00
Jon Turney 56286fd2b8 Fix test cases/failing/52 inconsistent comparison
Since PR #2884, this is failing with an exception

Keep the behaviour we have had since PR #1810 (0.41.0), that ordering
comparisons of different types fail with an InterpreterException.

Also warn about equality comparisons of different types, which will one day
become an error, as per PR #2884.
2018-02-15 12:51:25 +00:00
Jussi Pakkanen 6cd7372e26 Comparing objects of different type prints a warning. Closes #2870. 2018-02-01 22:56:58 +02:00
Jon Turney 6a1a56ab57 Report warning/error locations in a format IDEs may already know how to parse
Examples:

meson.build:2:0: ERROR: Dependency is both required and not-found
meson.build:4: WARNING: Keyword argument "link_with" defined multiple times.

These are already matched by the default compilation-error-regexp-alist in
emacs.

Also:
Don't start 'red' markup until after the \n before an error
Unabsorb full-stop at end of warning with location from mlog.warning()
Update warning_location test
2018-01-30 06:48:22 +11:00
Jon Turney bcc95d7dd7 Use location formatting in mlog.warning() for invalid kwarg warning
This already reports the location (in a slightly different format), but
using mlog.warning() will make it easier if we want to change the location
format in future.
2018-01-01 13:21:01 +00:00
Jussi Pakkanen 678daad6cc Created a new disabler type. 2017-12-04 23:53:23 +02:00
Iñigo Martínez 3d0a9b7911 interpreter: Reduce to_sring method to base 10
The int's to_string method implementation has been reduced to base
10.
2017-11-26 17:14:32 +02:00
Iñigo Martínez 30f2c4857c interpreter: Support to_string method for int values
Although some other base types like boolean objects can be expresed
as strings, this is not possible with int objects.

This patch adds support to express int values as strings as hex,
decimal or octal values.
2017-11-26 17:14:32 +02:00
Dylan Baker dda5e8cadb Allow CustomTarget's to be indexed
This allows a CustomTarget to be indexed, and the resulting indexed
value (a CustomTargetIndex type), to be used as a source in other
targets. This will confer a dependency on the original target, but only
inserts the source file returning by index the original target's
outputs. This can allow a CustomTarget that creates both a header and a
code file to have it's outputs split, for example.

Fixes #1470
2017-09-27 22:01:24 +03:00
Nirbheek Chauhan 276e9c15cc str.split() can now take a positional argument
All the specified characters in the specified argument will be
stripped. If unspecified, the old behaviour is used.

Includes tests.
2017-09-12 14:07:29 +05:30
Jussi Pakkanen 4a766147fb Printing unknown kwarg error message no longer crashes the parser. 2017-08-14 22:32:29 +03:00
Jussi Pakkanen c69a4aee1e Store current line number so it can be printed in warning messages. Closes #2181. 2017-08-14 18:44:39 +03:00
Jussi Pakkanen 917e12e4e7 Merge pull request #2017 from mesonbuild/fix2012
Do not pickle interpreter objects by accident
2017-07-02 16:33:49 -04:00
Jehan 2f691410fc Improve "Passed invalid keyword argument" warning.
I got this warning on a build:
> WARNING: Passed invalid keyword argument preset. This will become a hard error in the future.
I had to grep in meson code to understand that "preset" was the name of
the invalid argument. This is not obvious at all depending on the
argument name (here it looked like it was about argument presets).
Let's make it clearer by putting it in quotes.
2017-07-02 10:08:08 -04:00
Jussi Pakkanen c11a4cb952 Make Interpreter object unpicklable as it was being pickled by accident in copies of kwargs. 2017-07-01 00:11:27 +03:00
Jussi Pakkanen 3262be23dc Fixed issues raised in review. 2017-06-26 23:29:42 +03:00
Jussi Pakkanen 97b7a7b10e Moved func_ methods from base class to Interpreter. 2017-06-26 21:10:27 +03:00
Jussi Pakkanen 46e61971ce Decorator to check for permitted kwargs. 2017-06-26 21:10:27 +03:00
Elliott Sales de Andrade 0e56ec2dbd Don't allow non-equality comparisons across types. 2017-05-17 22:00:02 -04:00
Elliott Sales de Andrade b36513a5b6 Only allow equality comparisons for non-elementary types. 2017-05-17 21:48:04 -04:00
Elliott Sales de Andrade 30645ed54b Remove extra casts on InterpreterBase.evaluate_statement.
The result of this method is always a "native" object, and code coverage
(plus a manual inspection) shows that this conversion is never done.
2017-05-17 19:43:39 -04:00
Dylan Baker a8173630ea Don't use len() to test emptiness vs not emptiness
Meson has a common pattern of using 'if len(foo) == 0:' or
'if len(foo) != 0:', however, this is a common anti-pattern in python.
Instead tests for emptiness/non-emptiness should be done with a simple
'if foo:' or 'if not foo:'

Consider the following:
>>> import timeit
>>> timeit.timeit('if len([]) == 0: pass')
0.10730923599840025
>>> timeit.timeit('if not []: pass')
0.030033907998586074
>>> timeit.timeit('if len(['a', 'b', 'c', 'd']) == 0: pass')
0.1154778649979562
>>> timeit.timeit("if not ['a', 'b', 'c', 'd']: pass")
0.08259823200205574
>>> timeit.timeit('if len("") == 0: pass')
0.089759664999292
>>> timeit.timeit('if not "": pass')
0.02340641999762738
>>> timeit.timeit('if len("foo") == 0: pass')
0.08848102600313723
>>> timeit.timeit('if not "foo": pass')
0.04032287199879647

And for the one additional case of 'if len(foo.strip()) == 0', which can
be replaced with 'if not foo.isspace()'
>>> timeit.timeit('if len("   ".strip()) == 0: pass')
0.15294511600222904
>>> timeit.timeit('if "   ".isspace(): pass')
0.09413968399894657
>>> timeit.timeit('if len("   abc".strip()) == 0: pass')
0.2023209120015963
>>> timeit.timeit('if "   abc".isspace(): pass')
0.09571301700270851

In other words, it's always a win to not use len(), when you don't
actually want to check the length.
2017-05-02 21:57:26 +03:00
Hemmo Nieminen e42f366e0b Fix an uninitialized variable access error.
To reproduce, one could write:

  foo = files('foo.c')
  foo[0].path()

and get:

  Traceback (most recent call last):
  [snip]
    File "/home/trhd/Projects/meson/mesonbuild/interpreterbase.py", line 398, in method_call
      raise InvalidArguments('Variable "%s" is not callable.' % object_name)
  UnboundLocalError: local variable 'object_name' referenced before assignment

Fix this by handling file objects separately.
2017-02-02 19:39:33 +02:00
Nirbheek Chauhan 0e078adf5a interpreter: Implement array.get(index, fallback)
If the index is out of range, the fallback value is used. Includes
a test.

Closes #1337
2017-01-26 23:22:14 +02:00
Jussi Pakkanen 8ec9b0a71f Better error message when using = rather than : for defining keywords. 2017-01-23 22:02:37 +02:00
Mike Sinkovsky 969be1f679 cleanup: Remove redundant parentheses 2017-01-18 21:22:47 +02:00
Mike Sinkovsky 77515ee541 style: [E303] too many blank lines (2) 2017-01-11 12:33:27 -05:00
Mike Sinkovsky bf14cec81b style: [E712] comparison to True should be 'if cond is True:' or 'if cond:' 2017-01-11 12:33:27 -05:00
Igor Gnatenko f0b30baa39 style: fix E225 violations
E225: missing whitespace around operator

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2017-01-01 12:02:05 -05:00
Igor Gnatenko 9ffc0d2f89 tree-wide: remove blank lines at EOF
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-12-19 18:34:06 +01:00
Nirbheek Chauhan 2c83bd16fc Test targets with only generated and prebuilt objects 2016-12-13 09:37:48 +05:30
Jussi Pakkanen 14ca7d602c Store subdir information for each node so we can remove files set in other subdirectories. 2016-12-04 18:28:25 +02:00
Jussi Pakkanen c41805f012 Moved more stuff, can now parse all of common tests. 2016-11-19 22:11:20 +02:00
Jussi Pakkanen 7e8872236d Implement a bunch of functions. 2016-11-19 21:25:28 +02:00
Jussi Pakkanen 7ed7219d9d Moved functions to base enough to get the base sample project parsed. 2016-11-19 20:18:30 +02:00
Jussi Pakkanen 0a31afd672 Embark on a journey to create a rewrite tool. 2016-11-19 19:48:12 +02:00