Skip to content

Commit

Permalink
refactor cmake-format to cmakelang
Browse files Browse the repository at this point in the history
* Fix `--check` missing early return.
* Fix wrong base class for TupleParser
* Add `PATTERN` as allowed duplicate keyword
* Enable `cmake-lint: disable=` within a statement
* Add cmake lint checks on tab policy and indentation size

Closes: #31
Closes: #197
Closes: #205
Closes: #208
Closes: #210
Closes: #216
Closes: #217
  • Loading branch information
cheshirekow committed Aug 19, 2020
1 parent 9fd3c1f commit 0b2f636
Show file tree
Hide file tree
Showing 224 changed files with 2,340 additions and 1,328 deletions.
28 changes: 28 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
}
},

"cc_library": {
"pargs": "1+",
"flags": ["STATIC", "SHARED"],
Expand Down Expand Up @@ -68,6 +69,7 @@
}
}
},

"cc_test": {
"pargs": 1,
"kwargs": {
Expand All @@ -80,6 +82,7 @@
"LABELS": "*"
}
},

"check_call": {
"kwargs": {
"COMMAND": "*",
Expand All @@ -101,13 +104,36 @@
"ERROR_STRIP_TRAILING_WHITESPACE",
]
},

"join": {
"pargs": [1, "+"],
"kwargs": {
"GLUE": 1,
}
},

"check_pyoneline": {
"pargs": "+",
"kwargs": {
"OUTPUT_VARIABLE": 1,
"ERROR_VARIABLE": 1
}
},

"tangent_addtest": {
"kwargs": {
"NAME": 1,
"WORKING_DIRECTORY": 1,
"COMMAND": "+",
"CONFIGURATIONS": "+"
}
},

"travis_decrypt": {
"pargs": [3],
"kwargs": {}
},

# debian.cmake
"create_debian_binary_packages": {
"pargs": [3, "+"],
Expand Down Expand Up @@ -177,6 +203,7 @@
},
},


# GtkDocConfig.cmake
"gtk_doc_add_module": {
"pargs": 1,
Expand All @@ -190,4 +217,5 @@
"XML": 1,
},
},

}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
*.o
*.so
refactor.ipynb

# sparse-export stuff
.gitu
Expand Down Expand Up @@ -38,5 +39,9 @@ node_modules
# bazel sucks...
WORKSPACE

# node sucks
vscode_extension/node_modules
vscode_extension/out

# Temp/backup files
*~
2 changes: 1 addition & 1 deletion .sparse-export
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cmake_format
cmakelang
61 changes: 46 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ python:
go:
- 1.13

env:
global:
# GITHUB_ACCESS_TOKEN=
- secure: "e62y3i4FG7KsJ/I8aVKoPk5CG0L7/TW1K4M+BLt5zULsKGyRw6b53I97p5Tc1zcAHqcocFeYL/eC3AucG3VNvyv6LIZuv5Y0upF/MG++tvkfV9Iyok76mP70DXR/ikAJDMgZSdEL/6uTTJ4XfBuH/VvCMMBvj+5ORSL65KIfqXcexj2JWaNtEEfwiVSkDvQZYYbHLRjQdAXzzI7g1xh+8mCmuFAvtn6U1cIZpdQv5u1DNIry8PoQ2asHr+vaCN9iVXvkWcUjoXpJTp96Hd8eO40ts3v3Ja1yJ7GzH09zjbKJS63dcB0LfV5uLjybJCkQ03102ua0V+E5OzPn5VYeIRSRWmdo35e9xZjqqbtNdHqNayOOpew/ik+wf2Nmzva5MCRf154pFfWjBDL4zh0WGBW8FyJ/9NxdYDJsOIznHBPBHCXnQOlrpdInIptuoLnT52V7MOq9XIiuqLlAH8Tr0GzNSJIJfwwhwJuGxgYi2DPDH8PRmkbHbvY/mN2WBxNFfHBSfCQGZJt6kHtEE+xIi0QQXME0h36V/8sOsmQDzArNFl2Um5GCXodtIjZI6Ga3nQhHDRRiQKJz0V/9OsJF4GteGw94xt/l6PkCT0o4D1cmPIELrBTzaEMnXYKRQEOPnvViyV8eJF2RBnaqNk+FqI+hmGtXXUKAdXZWAzyS66I="


before_install:
- sudo add-apt-repository --no-update -y ppa:longsleep/golang-backports
- sudo apt-get update
Expand All @@ -31,38 +37,63 @@ script:
- ninja better-test
- ninja lint

env:
global:
# GITHUB_ACCESS_TOKEN=
secure: "e62y3i4FG7KsJ/I8aVKoPk5CG0L7/TW1K4M+BLt5zULsKGyRw6b53I97p5Tc1zcAHqcocFeYL/eC3AucG3VNvyv6LIZuv5Y0upF/MG++tvkfV9Iyok76mP70DXR/ikAJDMgZSdEL/6uTTJ4XfBuH/VvCMMBvj+5ORSL65KIfqXcexj2JWaNtEEfwiVSkDvQZYYbHLRjQdAXzzI7g1xh+8mCmuFAvtn6U1cIZpdQv5u1DNIry8PoQ2asHr+vaCN9iVXvkWcUjoXpJTp96Hd8eO40ts3v3Ja1yJ7GzH09zjbKJS63dcB0LfV5uLjybJCkQ03102ua0V+E5OzPn5VYeIRSRWmdo35e9xZjqqbtNdHqNayOOpew/ik+wf2Nmzva5MCRf154pFfWjBDL4zh0WGBW8FyJ/9NxdYDJsOIznHBPBHCXnQOlrpdInIptuoLnT52V7MOq9XIiuqLlAH8Tr0GzNSJIJfwwhwJuGxgYi2DPDH8PRmkbHbvY/mN2WBxNFfHBSfCQGZJt6kHtEE+xIi0QQXME0h36V/8sOsmQDzArNFl2Um5GCXodtIjZI6Ga3nQhHDRRiQKJz0V/9OsJF4GteGw94xt/l6PkCT0o4D1cmPIELrBTzaEMnXYKRQEOPnvViyV8eJF2RBnaqNk+FqI+hmGtXXUKAdXZWAzyS66I="
_is_pseudo_source_branch: &is-pseudo-source-branch
repo = cheshirekow/cmake_format
AND NOT tag IS present
AND branch =~ ^((master)|(staging))$

_is_pseudo_release: &is-pseudo-release
repo = cheshirekow/cmake_format
AND tag IS present
AND tag =~ ^pseudo-((master)|(staging))$

_not_pseudo_tag: &not-pseudo-release
repo = cheshirekow/cmake_format
AND (tag IS NOT present
OR tag =~ ^(?!pseudo-).*$)

_is_release: &is-release
repo == cheshirekow/cmake_format
AND tag IS present
AND (tag =~ ^pseudo-((master)|(staging))$
OR tag =~ ^v\d+\.\d+\.\d+$)

jobs:
include:
# If this is a push to one of the pseudo-release branches, then generate
# the tag and push it to the repo
- stage: deploy
name: deploy-tag
if: repo = cheshirekow/cmake_format
AND NOT tag IS present
AND branch =~ ^((master)|(staging))$
if: *is-pseudo-source-branch
python: 3.6
script:
- mkdir ${TRAVIS_BUILD_DIR}/../cmake-build
- cd ${TRAVIS_BUILD_DIR}/../cmake-build
- cmake -G Ninja ${TRAVIS_BUILD_DIR}
- ninja push-cmake_format-github-pseudorelease-tag
- ninja push-cmakelang-github-pseudorelease-tag

# If this is a release tag, then push release artifacts and synchronize
# dependant repositories.
- name: deploy-artifacts
python: 3.6
if: repo = cheshirekow/cmake_format
AND tag IS present
AND (tag =~ ^pseudo-((master)|(staging))$
OR tag =~ ^v\d+\.\d+\.\d+$)
if: *is-release
script:
- mkdir ${TRAVIS_BUILD_DIR}/../cmake-build
- cd ${TRAVIS_BUILD_DIR}/../cmake-build
- cmake -G Ninja ${TRAVIS_BUILD_DIR}
- ninja push-cmake_format-github-release
- ninja push-cmake_format-rtd-repo
- ninja push-cmakelang-github-release
- ninja push-cmakelang-rtd-repo
- ninja push-cmakelang-pypi-release
- ninja push-cmakelang-precommit
- ninja push-cmakelang-docker

stages:
- test
# Skip the test stage if this is a pseudo-release tag, since those tests
# were already run on the branch
- name: test
if: *not-pseudo-release

# Enable the deploy stage only if this was a push. In particular, exclude
# this stage on pull requests
- name: deploy
if: type = push
2 changes: 1 addition & 1 deletion README.rst
4 changes: 4 additions & 0 deletions build_tooling/cmake/tangent.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Execute ctest")

add_custom_target(
best-test
COMMENT "Execute all tests")

# ====================
# buildbot-test target
# ====================
Expand Down
6 changes: 3 additions & 3 deletions build_tooling/cmake/tangent/codestyle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
# formatter: autopep8
# linter: pylint, flake8
# ~~~
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake_format)
set(CMAKE_FORMAT_CMD python -Bm cmake_format)
set(CMAKE_LINT_CMD python -Bm cmake_lint)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmakelang)
set(CMAKE_FORMAT_CMD python -Bm cmakelang.format)
set(CMAKE_LINT_CMD python -Bm cmakelang.lint)
else()
set(CMAKE_FORMAT_CMD cmake-format)
set(CMAKE_LINT_CMD cmake-lint)
Expand Down
6 changes: 2 additions & 4 deletions build_tooling/cmake/tangent/environment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ endfunction()
# include(environment.cmake)
# ~~~
set(IS_TRAVIS_CI FALSE)
if(DEFINED ENV{CI}
AND DEFINED ENV{TRAVIS}
AND "$ENV{CI}" STREQUAL "true"
if("$ENV{CI}" STREQUAL "true"
AND "$ENV{TRAVIS}" STREQUAL "true")
set(IS_TRAVIS_CI TRUE)
set(IS_TRAVIS_CI TRUE CACHE BOOL "This build is on travis" FORCE)
endif()

set(IS_PULL_REQUEST FALSE)
Expand Down
80 changes: 78 additions & 2 deletions build_tooling/cmake/tangent/wrappers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,64 @@ function(check_call)
endif()
endfunction()

# Executes a python oneline using `execute_process` and reports error if the
# command failed
function(check_pyoneline)
cmake_parse_arguments(_args "" "OUTPUT_VARIABLE;ERROR_VARIABLE" "" ${ARGN})

# Escape semicolons in the cmake list, the resulting string will contain \\\;
# for each semicolon. When we pass this into check_call the escape sequences
# will be interpreted, resulting in \; within the `COMMAND` argument to
# execute_process.
string(REPLACE ";" "\\\\\\;" _oneline "${_args_UNPARSED_ARGUMENTS}")

set(_pyonline ${ARGN})
check_call(
# NOTE(josh): cmake concats lines using semicolon, which is the same
# separator that python expects, so we don't need to do any special
# processing. The cmake list-concat gives us a python oneliner for free.
COMMAND python -Bc "${_oneline}"
OUTPUT_VARIABLE stdout
ERROR_VARIABLE stderr
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)

if(_args_OUTPUT_VARIABLE)
set(${_args_OUTPUT_VARIABLE}
${stdout}
PARENT_SCOPE)
endif()
if(_args_ERROR_VARIABLE)
set(${_args_ERROR_VARIABLE}
${stderr}
PARENT_SCOPE)
endif()
endfunction()

# Get a list of all known properties
check_call(COMMAND ${CMAKE_COMMAND} --help-property-list
OUTPUT_VARIABLE _propslist)
# Replace newlines with list separator
string(REGEX REPLACE "[\n ]+" ";" _propslist "${_propslist}")
set(KNOWN_PROPERTIES ${_propslist})

function(tangent_addtest)
cmake_parse_arguments(_args "" "NAME;WORKING_DIRECTORY"
"COMMAND;CONFIGURATIONS;DEPENDS" ${ARGN})

add_test(
NAME ${_args_NAME}
COMMAND ${_args_COMMAND}
WORKING_DIRECTORY ${_args_WORKING_DIRECTORY}
CONFIGURATIONS ${_args_CONFIGURATIONS})
add_custom_target(
runtest.${_args_NAME}
DEPENDS ${_args_DEPENDS}
COMMAND ${_args_COMMAND}
WORKING_DIRECTORY ${_args_WORKING_DIRECTORY})
add_dependencies(best-test runtest.${_args_NAME})

endfunction()

# Wraps add_library and provides additional keyword options that translate into
# additional calls to target_link_libraries, target_set_properties, etc. Usage:
# ~~~
Expand Down Expand Up @@ -352,8 +403,8 @@ set_property(GLOBAL PROPERTY SEMVER_INCLUDENO 0)
# get_version_from_header(<header-path> <macro>)
# ~~~
#
# Assigns into the calling scope a variable witht the same name as `${macro}`
# the value of the version
# Assigns into the calling scope a variable with the same name as `${macro}` the
# value of the version
function(get_version_from_header headerpath macro)
get_property(_includeno GLOBAL PROPERTY SEMVER_INCLUDENO)
math(EXPR _includeno "${_includeno} + 1")
Expand Down Expand Up @@ -447,3 +498,28 @@ function(glob_subdirs)
endif()
endforeach()
endfunction()

# If this build system was generated on travis, the include a rule to decrypt
# the given file to the given location.
function(travis_decrypt tgtfile srcfile keyid)
get_filename_component(_filename ${tgtfile} NAME)
if(IS_TRAVIS_CI)
add_custom_command(
OUTPUT ${tgtfile}
DEPENDS ${srcfile}
COMMAND
# cmake-format: off
openssl aes-256-cbc
# NOTE(josh): we could use $ENV{...} but then we end up with the
# actual encryption key in the command line... which might show up
# in logs or error messages.
-K "\$\${encrypted_${keyid}_key}"
-iv "\$\${encrypted_${keyid}_iv}"
-in ${srcfile}
-out ${tgtfile}
-d
# cmake-format: on
COMMAND chmod 0600 ${tgtfile}
COMMENT "Decrypting ${_filename}")
endif()
endfunction()
6 changes: 3 additions & 3 deletions build_tooling/lint-excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
build-.*
cmake/node_modules/.*
semver-.*\.cmake
cmake_format/command_tests/.*\.cmake
cmake_format/test/.*\.cmake
cmake_lint/test/.*\.cmake
cmakelang/command_tests/.*\.cmake
cmakelang/format/testdata/.*\.cmake
cmakelang/lint/test/.*\.cmake
linkhash/testproject/.*

# third party stuff
Expand Down
Loading

0 comments on commit 0b2f636

Please sign in to comment.