Skip to content

Commit

Permalink
Add vscode extension, markup config opts, fix bugs
Browse files Browse the repository at this point in the history
* Add visual studio code extension
* Add algorithm order config option
* Add user specified fence regex config option
* Add user specified ruler regex config option
* Add config option to disable comment formatting altogether
* Fix get_config bug in ``__main__``
* Fix missing elseif command specification
* Fix missing elseif/else paren spacing when specified
* Add enable_markup config option
* Fix kwargstack early breaking in conditionals
* Add some notes for developers.
* Add warning if formatter is inactive at the end of a print
* Add config options to preserve first comment or any matching a regex

Closed issues:

* Fixes #34 - if conditions with many elements
* Closes #35 - break_before_args
* Resolves #42 - user specified string for fencing
* Resolves #43 - allow custom string for rulers
* Fixes #45 - config file not loaded properly
* Fixes #51 - competing herustics for 2+ argument statements
* Resolves #60 - option to not reflow initial comment block
* Resolves #61 - add non-builtin commands
* Fixes #63 - elseif like if
* Resolves #65 - warn if off doesn't have corresponding on
* Closes #67 - global option to not format comments
* Fixes #68 - seperate-ctrl-name-with-space
  • Loading branch information
cheshirekow committed Sep 17, 2018
1 parent afd9c6b commit 10203cd
Show file tree
Hide file tree
Showing 41 changed files with 4,390 additions and 179 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# cmake builds
.build

# visual studio code
.vscode

# python packaging
*.egg-info/
dist/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"restructuredtext.confPath": "/home/josh/Codes/cmake_format",
"restructuredtext.workspaceRoot": "/home/josh/Codes/cmake-format"
}
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@ project(cheshirekow)
enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

include(${CMAKE_SOURCE_DIR}/cmake/codestyle.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/doctools.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/pkgconfig.cmake)

find_package(Threads REQUIRED)
pkg_find(PKG libcurl #
PKG libglog
PKG libudev
PKG fuse
PKG vulkan
PKG x11-xcb)

include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/third_party/googletest/include)
include_directories(${CMAKE_SOURCE_DIR}/third_party/re2)
include_directories(${CMAKE_SOURCE_DIR}/third_party/fmt/include)
include_directories(${CMAKE_SOURCE_DIR}/third_party/glm)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CXX_STANDARD_FLAG "-std=c++11"
CACHE STRING "cxx command line flag specifying which C++ standard to apply")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD_FLAG}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")

add_custom_target(format)
Expand All @@ -28,5 +42,7 @@ foreach(child ${children})
if(EXISTS ${CMAKE_SOURCE_DIR}/${child}/CMakeLists.txt)
message("Enabling subdirectory '${child}' for this checkout")
add_subdirectory(${child})
else()
message("Skipping subdirectory '${child}' for this checkout")
endif()
endforeach()
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
# cmake
# gcc
# g++
# gnuradio-dev
# libcurl4-openssl-dev
# libfuse-dev
# libgoogle-glog-dev
# libmagic-dev
# libudev-dev
# libvulkan-dev
# libx11-xcb-dev
# ninja-build
#
# pip install --upgrade pip
# pip install --user
# cpplint
# autopep8
# pylint
# sphinx
#
# file-magic
# flask
# oauth2client
# pygerrit2
# pylint
# recommonmark
# sphinx
# sqlalchemy

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
Expand Down
103 changes: 103 additions & 0 deletions cmake/codestyle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# porcelain for format and lint rules

# 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
#
# CPP:
# formatter: clang-format
# linter: cpplint
#
# PYTHON:
# formatter: autopep8
# linter: pylint
#
function(format_and_lint module)
set(cmake_files_)
set(cc_files_)
set(py_files_)
set(unknown_files_)
set(state_ "AUTO")

foreach(arg ${ARGN})
# assign by filename
if(state_ STREQUAL "AUTO")
if(arg STREQUAL "CMAKE" OR arg STREQUAL "CC" OR arg STREQUAL "PY")
set(state_ SPECIFIC)
string(TOLOWER ${arg} typename_)
set(active_list_ ${typename}_files_)
else()
if(arg MATCHES ".*\.cmake" OR arg MATCHES ".*CMakeLists.txt")
list(APPEND cmake_files_ ${arg})
elseif(arg MATCHES ".*\.py")
list(APPEND py_files_ ${arg})
elseif(arg MATCHES ".*\.(cc|h)")
list(APPEND cc_files_ ${arg})
else()
list(APPEND unknown_files_ ${arg})
endif()
endif()
elseif(state_ STREQUAL "SPECIFIC")
if(arg STREQUAL "CMAKE" OR arg STREQUAL "CC" OR arg STREQUAL "PY")
string(TOLOWER ${arg} typename_)
set(active_list_ ${typename}_files_)
else()
list(APPEND ${active_list_} ${arg})
endif()
endif()
endforeach()

set(fmtcmds_)
set(depfiles_)
if(cmake_files_)
list(APPEND fmtcmds_ COMMAND python -Bm cmake_format -i ${cmake_files_})
list(APPEND depfiles_ ${cmake_files_})
endif()
if(cc_files_)
list(APPEND fmtcmds_ COMMAND clang-format -style file -i ${cc_files_})
list(APPEND lntcmds_ COMMAND cpplint ${cc_files_})
list(APPEND depfiles_ ${cc_files_})
endif()
if(py_files_)
list(APPEND fmtcmds_ COMMAND autopep8 -i ${py_files_})
list(APPEND lntcmds_ COMMAND pylint ${py_files_})
list(APPEND depfiles_ ${py_files_})
endif()

set(fmtstamp_ ${CMAKE_CURRENT_BINARY_DIR}/${module}_format.stamp)
add_custom_command(OUTPUT ${fmtstamp_}
${fmtcmds_}
COMMAND touch ${fmtstamp_}
DEPENDS ${depfiles_}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(${module}_format DEPENDS ${fmtstamp_})
add_dependencies(format ${module}_format)

set(lntstamp_ ${CMAKE_CURRENT_BINARY_DIR}/${module}_lint.stamp)
add_custom_command(OUTPUT ${lntstamp_}
${lntcmds_}
COMMAND touch ${lntstamp_}
DEPENDS ${depfiles_}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(${module}_lint DEPENDS ${lntstamp_})
add_dependencies(lint ${module}_lint)

if(unknown_files_)
string(REPLACE ";" "\n " filelist_ "${unknown_files_}")
message(WARNING
"The following files will not be linted/formatted because their"
" extension is not recognized: \n ${filelist_}")
endif()
endfunction()
22 changes: 22 additions & 0 deletions cmake/doctools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# porcelain for documentation generation tools


# Run sphinx
# usage:
# sphinx(<module>
# changlog.rst
# index.rst
# todo.rst
# README.rst)
function(sphinx module)
set(stamp_path_ ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp)
add_custom_command(OUTPUT ${stamp_path_}
COMMAND sphinx-build -M html ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
COMMAND touch ${stamp_path_}
DEPENDS ${ARGN}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(${module}_doc
DEPENDS ${stamp_path_})
add_dependencies(doc ${module}_doc)
endfunction()
176 changes: 176 additions & 0 deletions cmake/pkgconfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Porcelain tools for using pkg config. Better than cmake's builtins.

# Execute pkg-config and store flags in the cache
function(_pkg_query outvar arg)
execute_process(COMMAND pkg-config --cflags-only-I ${arg}
RESULT_VARIABLE _pkg_err
OUTPUT_VARIABLE _pkg_out
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _pkg_err EQUAL 0)
set(pkg_errno 1 PARENT_SCOPE)
return()
endif()
set(pkg_${outvar}_includedirs ${_pkg_out} CACHE STRING
"include directories for ${outvar}" FORCE)

execute_process(COMMAND pkg-config --cflags-only-other ${arg}
RESULT_VARIABLE _pkg_err
OUTPUT_VARIABLE _pkg_out
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _pkg_err EQUAL 0)
set(pkg_errno 1 PARENT_SCOPE)
return()
endif()

set(pkg_${outvar}_cflags ${_pkg_out} CACHE STRING
"cflags directories for ${outvar}" FORCE)

execute_process(COMMAND pkg-config --libs-only-L ${arg}
RESULT_VARIABLE _pkg_err
OUTPUT_VARIABLE _pkg_out
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _pkg_err EQUAL 0)
set(pkg_errno 1 PARENT_SCOPE)
return()
endif()

set(pkg_${outvar}_libdirs ${_pkg_out} CACHE STRING
"library directories for ${outvar}" FORCE)

execute_process(COMMAND pkg-config --libs-only-l ${arg}
RESULT_VARIABLE _pkg_err
OUTPUT_VARIABLE _pkg_out
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _pkg_err EQUAL 0)
set(pkg_errno 1 PARENT_SCOPE)
return()
endif()

set(pkg_${outvar}_libs ${_pkg_out} CACHE STRING
"library directories for ${outvar}" FORCE)

set(pkg_${outvar}_name ${arg} CACHE STRING
"selected name which worked as an argument to pkg-config" FORCE)

set(pkg_errno 0 PARENT_SCOPE)
endfunction()

# Execute pkg-config for each name in the list
function(_pkg_query_loop name)
set(outvar ${name})
set(names ${ARGN})
if(NOT names)
set(names ${name})
endif()

set(pkg_errno 1)
foreach(_qname ${names})
_pkg_query(${outvar} ${_qname})
if(pkg_errno EQUAL 0)
set(pkg_${outvar}_found TRUE CACHE BOOL "${outvar} was found" FORCE)
return()
endif()
endforeach()

set(pkg_${outvar}_found FALSE CACHE BOOL "${outvar} was not found" FORCE)
endfunction()

# Find system packages using pkg-config.
#
# usage:
# pkg_find(PKG libfoo NAMES libfoo libfoo-1 libfoox
# PKG libbar NAMES libarx
# PKG libbaz)
#
# Execute pkg-config to get flags for each of the given library names.
# Each library is specified with a line `PKG <name> [NAMES <name0>, ...]`.
# If the library might have different names on different supported systems
# you may specify a list of names to attempt. The first one that `pkg-config`
# exists with `0` for will be used. If `NAMES` is provided, then `<name>` will
# not be attempted (so duplicate it if you want to). `<name>` will be used
# for the key in the pkg-config database cache.
function(pkg_find)
set(state_ "PARSE_PKG")
set(name_)
set(names_)

foreach(arg ${ARGN})
if(state_ STREQUAL "PARSE_PKG")
if(arg STREQUAL "PKG")
set(state_ "PARSE_NAME")
set(name_)
set(names_)
else()
message(FATAL_ERROR "malformed pkg_find, "
"expected 'PKG' but got '${arg}'")
endif()
elseif(state_ STREQUAL "PARSE_NAME")
set(name_ ${arg})
set(state_ "PARSE_KEYWORD")
elseif(state_ STREQUAL "PARSE_KEYWORD")
if(arg STREQUAL "PKG")
_pkg_query_loop(${name_} ${names_})
set(name_)
set(names_)
set(state_ "PARSE_NAME")
elseif(arg STREQUAL "NAMES")
set(state_ "PARSE_NAMES")
else()
message(FATAL_ERROR "malformed pkg_find, expected keyword "
"'PKG' or 'NAMES' but got '${arg}'")
endif()
elseif(state_ STREQUAL "PARSE_NAMES")
if(arg STREQUAL "PKG")
_pkg_query_loop(${name_} ${names_})
set(name_)
set(names_)
set(state_ "PARSE_NAME")
elseif(arg STREQUAL "NAMES")
message(FATAL_ERROR "malformed pkg_find, found literal "
"'NAMES' when expecting library names")
else()
list(APPEND names_ ${arg})
endif()
endif()
endforeach()

if(name_)
_pkg_query_loop(${name_} ${names_})
endif()
endfunction()

# Add flags to compile/link options for the target according to the output of
# pkg-config. Asserts that the given pkg-config packages were found
function(target_pkg_depends target pkg0)
foreach(pkgname ${pkg0} ${ARGN})
if(NOT pkg_${pkgname}_found)
message(FATAL_ERROR "pkg-config package ${pkgname} is not enumerated, but"
" required by ${target}")
endif()
if(NOT ${pkg_${pkgname}_found})
message(FATAL_ERROR "pkg-config package ${pkgname} is not found, but"
" required by ${target}")
endif()
if(pkg_${pkgname}_includedirs)
# TODO(josh): passthrough things like
# SYSTEM, BEFORE, INTERFACE|PUBLIC|PRIVATE
target_include_directories(${target} SYSTEM PUBLIC
${pkg_${pkgname}_includedirs})
endif()
if(pkg_${pkgname}_cflags)
# TODO(josh): passthrough things like
# BEFORE, INTERFACE|PUBLIC|PRIVATE
target_compile_options(${target} PUBLIC ${pkg_${pkgname}_cflags})
endif()
if(pkg_${pkgname}_libdirs)
get_target_property(lflags_ ${target} LINK_FLAGS)
list(APPEND lflags_ ${pkg_${pkgname}_lflags})
set_target_properties(${target} PROPERTIES LINK_FLAGS ${lflags_})
endif()
if(pkg_${pkgname}_libs)
# Passthrough options like INTERFACE|PUBLIC|PRIVATE and
# debug|optimized|general
target_link_libraries(${target} PUBLIC ${pkg_${pkgname}_libs})
endif()
endforeach()
endfunction()
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.4.1'
VERSION = '0.4.2'
Loading

0 comments on commit 10203cd

Please sign in to comment.