Skip to content

Commit

Permalink
Initial cmake-lint program
Browse files Browse the repository at this point in the history
* Add `ctest-to` program
* Add `cmake-lint` program
* Separate documentation by program
* Add some more detailed configuration documentation
* Make some of the config logic generic and push into a base class
* Some groundwork for cleaning up the config into different sections
* Fix externalproject_add_stepdependencies

Closes #152
  • Loading branch information
cheshirekow committed Dec 13, 2019
1 parent dd69598 commit b20fd1a
Show file tree
Hide file tree
Showing 51 changed files with 3,633 additions and 530 deletions.
11 changes: 10 additions & 1 deletion cmake_format/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ py_library(
"annotate.py",
"commands.py",
"common.py",
"config_util.py",
"configuration.py",
"ctest_to.py",
"formatter.py",
"invocation_tests.py",
"layout_tests.py",
Expand All @@ -30,7 +32,14 @@ py_library(
"parser_tests.py",
"pypi/setup.py",
"render.py",
"tests.py"],
"tests.py",
"tools/__init__.py",
"tools/parse_cmake_help.py",
"tools/properties.jinja.py",
"tools/usage_lexer.py",
"tools/usage_parser.py",
"tools/variables.jinja.py"
],
data=["templates/layout.html.tpl",
"templates/style.css"])

Expand Down
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.6.2'
VERSION = '0.6.3'
30 changes: 14 additions & 16 deletions cmake_format/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import cmake_format
from cmake_format import commands
from cmake_format import configuration
from cmake_format import config_util
from cmake_format import formatter
from cmake_format import lexer
from cmake_format import markup
Expand Down Expand Up @@ -180,15 +181,12 @@ def load_yaml(config_file):
return out


def exec_pyconfig(configfile_path, config_dict=None):
if config_dict is None:
config_dict = {}
config_dict["__file__"] = os.path.realpath(configfile_path)
def exec_pyconfig(configfile_path):
_global = config_util.ExecGlobal(configfile_path)
with io.open(configfile_path, 'r', encoding='utf-8') as infile:
# pylint: disable=exec-used
exec(infile.read(), config_dict)
config_dict.pop("__file__")
return config_dict
exec(infile.read(), _global)
return _global


def try_get_configdict(configfile_path):
Expand Down Expand Up @@ -327,7 +325,7 @@ def dump_config(args, config_dict, outfile):
outfile.write('\n')
return

configuration.python_dump(cfg, outfile)
cfg.dump(outfile)


USAGE_STRING = """
Expand Down Expand Up @@ -377,7 +375,7 @@ def add_config_options(arg_parser):
elif isinstance(value, bool):
optgroup.add_argument('--' + key.replace('_', '-'), nargs='?',
default=None, const=(not value),
type=configuration.parse_bool, help=helptext)
type=config_util.parse_bool, help=helptext)
elif isinstance(value, value_types):
optgroup.add_argument('--' + key.replace('_', '-'), type=type(value),
help=helptext,
Expand Down Expand Up @@ -437,13 +435,6 @@ def setup_argparser(arg_parser):
def main():
"""Parse arguments, open files, start work."""

# set up main logger, which logs everything. We'll leave this one logging
# to the console
format_str = '[%(levelname)-4s] %(filename)s:%(lineno)-3s: %(message)s'
logging.basicConfig(level=logging.INFO,
format=format_str,
filemode='w')

arg_parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -551,4 +542,11 @@ def main():


if __name__ == '__main__':
# set up main logger, which logs everything. We'll leave this one logging
# to the console
format_str = '%(levelname)-4s %(filename)s:%(lineno)-3s: %(message)s'
logging.basicConfig(level=logging.INFO,
format=format_str,
filemode='w')

sys.exit(main())
8 changes: 6 additions & 2 deletions cmake_format/command_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ py_library(
"add_executable_tests.py",
"add_library_tests.py",
"misc_tests.py",
"partialmethod.py"],
"partialmethod.py"
],
data=[
"add_custom_command_tests.cmake",
"add_executable_tests.cmake",
"add_library_tests.cmake",
"conditional_tests.cmake",
"export_tests.cmake",
"external_project_tests.cmake",
"file_tests.cmake",
"foreach_tests.cmake",
"install_tests.cmake",
"misc_tests.cmake",
"set_target_properties_tests.cmake",
"set_tests.cmake"])
"set_tests.cmake",
])

# -- Python 2 --

Expand Down
7 changes: 7 additions & 0 deletions cmake_format/command_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ class TestExport(TestBase):
kExpectNumSidecarTests = 1


class TestExternalProject(TestBase):
"""
Test various examples of ExternalProject_xxx()
"""
kExpectNumSidecarTests = 5


class TestFile(TestBase):
"""
Test various examples of the file command
Expand Down
1 change: 1 addition & 0 deletions cmake_format/command_tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
TestAddCustomCommand,
TestConditional,
TestExport,
TestExternalProject,
TestForeach,
TestFile,
TestInstall,
Expand Down
34 changes: 34 additions & 0 deletions cmake_format/command_tests/external_project_tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# test: externalproject_add
ExternalProject_Add(
foo_proj
PREFIX ${CMAKE_BINARY_DIR}/foo/
TMP_DIR ${CMAKE_BINARY_DIR}/foo/.tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/foo/.stamp
LOG_DIR ${CMAKE_BINARY_DIR}/foo/.log
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/foo/.download
SOURCE_DIR ${CMAKE_BINARY_DIR}/foo/src
BINARY_DIR ${CMAKE_BINARY_DIR}/foo/build
INSTALL_DIR ${CMAKE_BINARY_DIR}/foo/install)

# test: externalproject_get_property
ExternalProject_Get_Property(foo_proj SOURCE_DIR BINARY_DIR)

# test: externalproject_add_step
ExternalProject_Add_Step(
foo_proj hello_step
COMMAND echo "hello world"
COMMENT "say hello"
DEPENDEES first_step
DEPENDERS goodbye_step
BYPRODUCTS hello.txt
ALWAYS FALSE
EXCLUDE_FROM_MAIN TRUE
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/foo
LOG TRUE
USES_TERMINAL FALSE)

# test: externalproject_add_steptargets
ExternalProject_Add_StepTargets(foo_proj NO_DEPENDS hello_step goodbye_step)

# test: externalproject_add_stepdependencies
ExternalProject_Add_StepDependencies(foo_proj hello_step target_one target_two)
Loading

0 comments on commit b20fd1a

Please sign in to comment.