cheshirekow / cmake_format

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

Formatting of `file(READ)` Fails #106

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 (READ filename.extension variable)
  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 10, in <module>
    sys.exit(main())
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/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/__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/parser.py", line 1061, in parse
    return consume_body(tokens, parse_db)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format/parser.py", line 1037, in consume_body
    subtree = consume_statement(tokens, parse_db)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format/parser.py", line 919, in consume_statement
    subtree = parse_fun(tokens, breakstack)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/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/parse_funs.py", line 564, in parse_file_read
    breakstack=breakstack)
  File "pyenv/versions/3.7.3/lib/python3.7/site-packages/cmake_format/parser.py", line 545, 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 believe I have a fix for this. If you'd like to try yourself or need a quickfix you can check out the temporary hotfixes_0.5.0 branch here

sanssecours commented 5 years ago

Thank you for the quick fix. Unfortunately I found another problem, which I reported here.