cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
958 stars 105 forks source link

Formatting of `file(STRING)` Fails #108

Closed sanssecours closed 5 years ago

sanssecours commented 5 years ago

Steps to Reproduce

  1. Create a file test.cmake with the following content:

    file(STRINGS filename.ext variable REGEX regex)
  2. Run cmake-format:

    cmake-format test.cmake

Expected Result

The command cmake-format prints a nicely formatted version of the given CMake code.

Actual Result

The command fails with an Attribute Error:

While processing test.cmake
Traceback (most recent call last):
  File "pyenv/versions/3.7.3/bin/cmake-format", line 11, in <module>
    load_entry_point('cmake-format==0.5.1.dev0', 'console_scripts', 'cmake-format')()
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/__main__.py", line 439, in main
    process_file(cfg, infile, outfile, args.dump)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/__main__.py", line 113, in process_file
    parse_tree = parser.parse(tokens, parse_db)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parser.py", line 1066, in parse
    return consume_body(tokens, parse_db)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parser.py", line 1042, in consume_body
    subtree = consume_statement(tokens, parse_db)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parser.py", line 924, in consume_statement
    subtree = parse_fun(tokens, breakstack)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parse_funs.py", line 942, in parse_file
    return parsemap[descriminator](tokens, breakstack)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parse_funs.py", line 596, in parse_file_strings
    breakstack=breakstack)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format-0.5.1.dev0-py3.7.egg/cmake_format/parser.py", line 550, in parse_standard
    kwarg_breakstack = breakstack + [KwargBreaker(list(kwargs.keys()) + flags)]
AttributeError: 'set' object has no attribute 'keys'

.

System Information

cheshirekow commented 5 years ago

I've updated the hotfixes_0.5.0 branch (link) with a fix for this as well.

sanssecours commented 5 years ago

Thank you. I opened an issue about another problem here.