mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.59k stars 1.63k forks source link

Cross file whitespace parsing error #1497

Open codido opened 7 years ago

codido commented 7 years ago

A parsing error is thrown if a closing bracket in a cross file appears at the beginning of the line.

For example, this works:

c_args = [
    '-DFOO'
    ]

...but this doesn't:

c_args = [
    '-DFOO'
]
Salamandar commented 5 years ago

I can confirm the bug still exists.

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/mesonbuild/mesonmain.py", line 112, in run
    return options.run_func(options)
  File "/usr/lib/python3.7/site-packages/mesonbuild/msetup.py", line 230, in run
    app.generate()
  File "/usr/lib/python3.7/site-packages/mesonbuild/msetup.py", line 156, in generate
    env = environment.Environment(self.source_dir, self.build_dir, self.options)
  File "/usr/lib/python3.7/site-packages/mesonbuild/environment.py", line 359, in __init__
    self.cross_info = CrossBuildInfo(self.coredata.cross_file)
  File "/usr/lib/python3.7/site-packages/mesonbuild/environment.py", line 1107, in __init__
    self.parse_datafile(filename)
  File "/usr/lib/python3.7/site-packages/mesonbuild/environment.py", line 1120, in parse_datafile
    config.read_file(f, filename)
  File "/usr/lib/python3.7/configparser.py", line 717, in read_file
    self._read(f, source)
  File "/usr/lib/python3.7/configparser.py", line 1110, in _read
    raise e
configparser.ParsingError: Source contains parsing errors: '/home/salamandar/phenix/stm32-template/stm32f303.meson'
    [line 29]: ']\n'
    [line 35]: ']\n'
    [line 41]: ']\n'
bdsbdsbds commented 4 years ago

This has been annoying me so I looked into it, and I believe this is because Meson is just using Python's default configparser module, which doesn't actually have a concept of a list. Instead, everything is just a string. Multiline values are accepted, but only so long as they are also indented, which is why having an ending bracket on an unindented line doesn't work. After looking at the documentation for configparser, supporting lists seems completely out of scope, so it seems like if Meson wants to properly support lists in cross files, it would need an actual parser for them.

Salamandar commented 4 years ago

Why not use the actual meson parser, but with "forbidden values", just like for the meson_options.txt file ? That would allow "variables" like :

c_args = […]

cpp_args = c_args + […]
bdsbdsbds commented 4 years ago

That seems like a much better idea. I didn't realize that the regular meson parser was already being used for parsing things other than just meson.build files. Unifying the allowed syntax as much as possible with meson.build seems ideal.