Skip to content

Commit

Permalink
bugfixes and doc reorg
Browse files Browse the repository at this point in the history
* Fix empty kwarg can yield a parg group node with only whitespace
  children
* Fix ``file(READ ...)`` and ``file(STRINGS ...)`` parser kwargs using set
  syntax instead of dict syntax
* Fix agressive positional parser within conditional parser
* Fix missing endif, endwhile in parsemap
* Split parse functions out into separate modules for better organization
* Add more sanity tests for ``file(...)``.
* Remove README from online docs, replace with expanded documentation for
  each README section
* Restore ability to accept paren-group in arbitrary parg-group
* Fix missing tests on travis
* Fix new tests using unicode literals (affects python2)
* Fix command parser after --

* Closes #104 - Extra space for export targets
* Closes #106 - Formatting of ``file(READ)`` fails
* Closes #107 - multiline cmake commands
* Closes #108 - Formatting of ``file(STRING)`` fails
* Closes #110 - Formatting of Nested Expressions Fails

Change-Id: I1a4e0620dd42de613a3964b5d1af7caffeb6f54e
  • Loading branch information
cheshirekow committed May 2, 2019
1 parent 0a8a97c commit 28054df
Show file tree
Hide file tree
Showing 42 changed files with 3,612 additions and 1,637 deletions.
7 changes: 7 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
additional_commands = {
"pkg_find": {
"kwargs": {
"PKG": "*"
}
}
}
7 changes: 5 additions & 2 deletions cmake/codestyle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
# Create format and lint rules for module files
#
# usage:
# ~~~
# format_and_lint(module
# bar.h bar.cc
# CMAKE CMakeLists.txt test/CMakeLists.txt
# CC foo.h foo.cc
# PY foo.py)
#
# ~~~

# Will create rules `${module}_lint` and `${module}_format` using the standard
# code formatters and lint checkers for the appropriate language. These
# tools are:
#
# ~~~
# CMAKE:
# formatter: cmake-format
#
Expand All @@ -23,7 +26,7 @@
# PYTHON:
# formatter: autopep8
# linter: pylint
#
# ~~~
function(format_and_lint module)
set(cmake_files_)
set(cc_files_)
Expand Down
674 changes: 674 additions & 0 deletions cmake_format/.sub/LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cmake_format/.sub/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autopep8==1.3.5; python_version < '3.0'
autopep8==1.4.3; python_version >= '3.0'
flake8==3.6.0; python_version < '3.0'
flake8==3.7.7; python_version >= '3.0'
jinja2==2.10.1
pylint==1.9.1; python_version < '3.0'
pylint==2.2.2; python_version >= '3.0'
pyyaml==4.2b1
10 changes: 10 additions & 0 deletions cmake_format/.sub/sparse-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.cmake-format.py
/.gitignore
/.flake8
/.pep8
/cmake/*.cmake
/cmake_format
/CMakeLists.txt
/doc/conf.py
/Makefile
/pylintrc
13 changes: 13 additions & 0 deletions cmake_format/.sub/travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dist: xenial
language: python
python:
- "2.7"
- "3.5"
- "3.6"

install:
- pip install -r requirements.txt

script:
- make test
- make lint
29 changes: 25 additions & 4 deletions cmake_format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
format_and_lint(cmake_format
# cmake-format: sort
__init__.py
__main__.py
annotate.py
commands.py
command_tests/add_custom_command_tests.py
command_tests/add_executable_tests.py
command_tests/add_library_tests.py
command_tests/conditional_tests.py
command_tests/export_tests.py
command_tests/file_tests.py
command_tests/__init__.py
command_tests/install_tests.py
command_tests/set_tests.py
common.py
configuration.py
format_tests.py
doc/update_readme.py
formatter.py
format_tests.py
invocation_tests.py
lexer_tests.py
layout_tests.py
lexer.py
markup_tests.py
lexer_tests.py
markup.py
parser_tests.py
markup_tests.py
parse_funs/add_xxx.py
parse_funs/external_project.py
parse_funs/fetch_content.py
parse_funs/file.py
parse_funs/__init__.py
parser.py
parser_tests.py
pypi/setup.py
render.py
tests.py)

add_test(NAME cmake_format-format_tests
Expand Down Expand Up @@ -56,3 +76,4 @@ if(NOT IS_TRAVIS_CI)
endif()

add_subdirectory(doc)
add_subdirectory(command_tests)
2 changes: 1 addition & 1 deletion cmake_format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""
from __future__ import unicode_literals

VERSION = '0.5.0'
VERSION = '0.5.1'
53 changes: 53 additions & 0 deletions cmake_format/command_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
set(MODPREFIX cmake_format.command_tests)

add_test(NAME cmake_format-add_custom_command_tests
COMMAND python -m ${MODPREFIX}.add_custom_command_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-add_executable_tests
COMMAND python -m ${MODPREFIX}.add_executable_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-add_library_tests
COMMAND python -m ${MODPREFIX}.add_library_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-conditional_tests
COMMAND python -m ${MODPREFIX}.conditional_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-export_tests
COMMAND python -m ${MODPREFIX}.export_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-file_tests
COMMAND python -m ${MODPREFIX}.file_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-install_tests
COMMAND python -m ${MODPREFIX}.install_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-set_tests
COMMAND python -m ${MODPREFIX}.set_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

if(NOT IS_TRAVIS_CI)
add_test(NAME cmake_format-add_custom_command_tests_py3
COMMAND python3 -m ${MODPREFIX}.add_custom_command_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-add_executable_tests_py3
COMMAND python3 -m ${MODPREFIX}.add_executable_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-add_library_tests_py3
COMMAND python3 -m ${MODPREFIX}.add_library_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-conditional_tests_py3
COMMAND python3 -m ${MODPREFIX}.conditional_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-export_tests_py3
COMMAND python3 -m ${MODPREFIX}.export_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-file_tests_py3
COMMAND python3 -m ${MODPREFIX}.file_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-install_tests_py3
COMMAND python3 -m ${MODPREFIX}.install_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-set_tests_py3
COMMAND python3 -m ${MODPREFIX}.set_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
30 changes: 22 additions & 8 deletions cmake_format/command_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,29 @@ def setUp(self):
setattr(self, name, WrapTestWithRunFun(self, value))

def assertExpectations(self):
if self.expect_lex is not None:
with self.subTest(phase="lex"):
# Empty source_str is shorthand for "assertInvariant"
if self.source_str is None:
self.source_str = self.expect_format

if sys.version_info < (3, 0, 0):
if self.expect_lex is not None:
assert_lex(self, self.source_str, self.expect_lex)
if self.expect_parse is not None:
with self.subTest(phase="parse"):
if self.expect_parse is not None:
assert_parse(self, self.source_str, self.expect_parse)
if self.expect_layout is not None:
with self.subTest(phase="layout"):
if self.expect_layout is not None:
assert_layout(self, self.source_str, self.expect_layout)
if self.expect_format is not None:
with self.subTest(phase="format"):
if self.expect_format is not None:
assert_format(self, self.source_str, self.expect_format)
else:
if self.expect_lex is not None:
with self.subTest(phase="lex"): # pylint: disable=no-member
assert_lex(self, self.source_str, self.expect_lex)
if self.expect_parse is not None:
with self.subTest(phase="parse"): # pylint: disable=no-member
assert_parse(self, self.source_str, self.expect_parse)
if self.expect_layout is not None:
with self.subTest(phase="layout"): # pylint: disable=no-member
assert_layout(self, self.source_str, self.expect_layout)
if self.expect_format is not None:
with self.subTest(phase="format"): # pylint: disable=no-member
assert_format(self, self.source_str, self.expect_format)
2 changes: 2 additions & 0 deletions cmake_format/command_tests/add_custom_command_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=bad-continuation
from __future__ import unicode_literals
import unittest

from cmake_format.command_tests import TestBase
Expand Down Expand Up @@ -86,5 +87,6 @@ def test_single_argument(self):
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
"""


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions cmake_format/command_tests/add_executable_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=bad-continuation
from __future__ import unicode_literals
import unittest

from cmake_format.command_tests import TestBase
Expand Down
1 change: 1 addition & 0 deletions cmake_format/command_tests/add_library_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=bad-continuation
from __future__ import unicode_literals
import unittest

from cmake_format.command_tests import TestBase
Expand Down
32 changes: 12 additions & 20 deletions cmake_format/command_tests/conditional_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=bad-continuation
from __future__ import unicode_literals
import unittest

from cmake_format.command_tests import TestBase
Expand All @@ -11,22 +12,6 @@ class TestConditionalCommands(TestBase):

def test_complicated_boolean(self):
self.config.max_subargs_per_line = 10
self.source_str = """\
set(matchme
"_DATA_\\|_CMAKE_\\|INTRA_PRED\\|_COMPILED\\|_HOSTING\\|_PERF_\\|CODER_")
if (("${var}" MATCHES "_TEST_" AND NOT
"${var}" MATCHES
"${matchme}")
OR (CONFIG_AV1_ENCODER AND CONFIG_ENCODE_PERF_TESTS AND
"${var}" MATCHES "_ENCODE_PERF_TEST_")
OR (CONFIG_AV1_DECODER AND CONFIG_DECODE_PERF_TESTS AND
"${var}" MATCHES "_DECODE_PERF_TEST_")
OR (CONFIG_AV1_ENCODER AND "${var}" MATCHES "_TEST_ENCODER_")
OR (CONFIG_AV1_DECODER AND "${var}" MATCHES "_TEST_DECODER_"))
list(APPEND aom_test_source_vars ${var})
endif ()
"""

self.expect_format = """\
set(matchme "_DATA_\\|_CMAKE_\\|INTRA_PRED\\|_COMPILED\\|_HOSTING\\|_PERF_\\|CODER_")
if(("${var}" MATCHES "_TEST_" AND NOT "${var}" MATCHES "${matchme}")
Expand All @@ -43,20 +28,27 @@ def test_complicated_boolean(self):
"""

def test_nested_parens(self):
self.source_str = """\
self.expect_format = """\
if((NOT HELLO) OR (NOT EXISTS ${WORLD}))
message(WARNING "something is wrong")
set(foobar FALSE)
endif()
"""

def test_negated_single_nested_parens(self):
self.expect_format = """\
if((NOT HELLO) OR (NOT EXISTS ${WORLD}))
message(WARNING "something is wrong")
set(foobar FALSE)
if(NOT ("" STREQUALS ""))
# pass
endif()
"""

def test_conditional_in_if_and_endif(self):
self.expect_format = """\
if(SOMETHING AND (NOT SOMETHING_ELSE STREQUAL ""))
# pass
endif(SOMETHING AND (NOT SOMETHING_ELSE STREQUAL ""))
"""


if __name__ == '__main__':
unittest.main()
20 changes: 20 additions & 0 deletions cmake_format/command_tests/export_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# pylint: disable=bad-continuation
from __future__ import unicode_literals
import unittest

from cmake_format.command_tests import TestBase


class TestExportCommand(TestBase):
"""
Test various examples of export()
"""

def test_empty_parg_group(self):
self.expect_format = """\
export(TARGETS FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
"""


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 28054df

Please sign in to comment.