Restarted the production of the app
This commit is contained in:
17
libs/CLI11/scripts/ExtractVersion.py
Executable file
17
libs/CLI11/scripts/ExtractVersion.py
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
config_h = os.path.join(base_path, "include", "CLI", "Version.hpp")
|
||||
data = {"MAJOR": 0, "MINOR": 0, "PATCH": 0}
|
||||
reg = re.compile(r"^\s*#define\s+CLI11_VERSION_([A-Z]+)\s+([0-9]+).*$")
|
||||
|
||||
with open(config_h, "r") as fp:
|
||||
for l in fp:
|
||||
m = reg.match(l)
|
||||
if m:
|
||||
data[m.group(1)] = int(m.group(2))
|
||||
|
||||
print("{}.{}.{}".format(data["MAJOR"], data["MINOR"], data["PATCH"]))
|
||||
158
libs/CLI11/scripts/MakeSingleHeader.py
Executable file
158
libs/CLI11/scripts/MakeSingleHeader.py
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import argparse
|
||||
from subprocess import Popen, PIPE
|
||||
import warnings
|
||||
|
||||
tag_str = r"""
|
||||
^ # Begin of line
|
||||
[/\s]+ # Whitespace or comment // chars
|
||||
\[ # A literal [
|
||||
{tag}: # The tag
|
||||
(?P<name>[\w_]+) # name: group name
|
||||
: # Colon
|
||||
(?P<action>[\w_]+) # action: type of include
|
||||
\] # A literal ]
|
||||
\s* # Whitespace
|
||||
$ # End of a line
|
||||
|
||||
(?P<content>.*) # All
|
||||
|
||||
^ # Begin of line
|
||||
[/\s]+ # Whitespace or comment // chars
|
||||
\[ # A literal [
|
||||
{tag}: # The tag
|
||||
(?P=name) # Repeated name
|
||||
: # Colon
|
||||
end # Literal "end"
|
||||
\] # A literal ]
|
||||
\s* # Whitespace
|
||||
$ # End of a line
|
||||
"""
|
||||
|
||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class HeaderGroups(dict):
|
||||
def __init__(self, tag):
|
||||
"""
|
||||
A dictionary that also can read headers given a tag expression.
|
||||
|
||||
TODO: might have gone overboard on this one, could maybe be two functions.
|
||||
"""
|
||||
self.re_matcher = re.compile(
|
||||
tag_str.format(tag=tag), re.MULTILINE | re.DOTALL | re.VERBOSE
|
||||
)
|
||||
super(HeaderGroups, self).__init__()
|
||||
|
||||
def read_header(self, filename):
|
||||
"""
|
||||
Read a header file in and add items to the dict, based on the item's action.
|
||||
"""
|
||||
with open(filename) as f:
|
||||
inner = f.read()
|
||||
|
||||
matches = self.re_matcher.findall(inner)
|
||||
|
||||
if not matches:
|
||||
warnings.warn(
|
||||
"Failed to find any matches in {filename}".format(filename=filename)
|
||||
)
|
||||
|
||||
for name, action, content in matches:
|
||||
if action == "verbatim":
|
||||
assert (
|
||||
name not in self
|
||||
), "{name} read in more than once! Quitting.".format(name=name)
|
||||
self[name] = content
|
||||
elif action == "set":
|
||||
self[name] = self.get(name, set()) | set(content.strip().splitlines())
|
||||
else:
|
||||
raise RuntimeError("Action not understood, must be verbatim or set")
|
||||
|
||||
def post_process(self):
|
||||
"""
|
||||
Turn sets into multiple line strings.
|
||||
"""
|
||||
for key in self:
|
||||
if isinstance(self[key], set):
|
||||
self[key] = "\n".join(self[key])
|
||||
|
||||
|
||||
def make_header(output, main_header, files, tag, namespace, macro=None, version=None):
|
||||
"""
|
||||
Makes a single header given a main header template and a list of files.
|
||||
"""
|
||||
groups = HeaderGroups(tag)
|
||||
|
||||
# Set tag if possible to class variable
|
||||
try:
|
||||
proc = Popen(
|
||||
["git", "describe", "--tags", "--always"], cwd=str(DIR), stdout=PIPE
|
||||
)
|
||||
out, _ = proc.communicate()
|
||||
groups["git"] = out.decode("utf-8").strip() if proc.returncode == 0 else ""
|
||||
except OSError:
|
||||
groups["git"] = ""
|
||||
|
||||
for f in files:
|
||||
groups.read_header(f)
|
||||
|
||||
groups["namespace"] = namespace
|
||||
groups["version"] = version or groups["git"]
|
||||
|
||||
groups.post_process()
|
||||
|
||||
with open(main_header) as f:
|
||||
single_header = f.read().format(**groups)
|
||||
|
||||
if macro is not None:
|
||||
before, after = macro
|
||||
print("Converting macros", before, "->", after)
|
||||
single_header.replace(before, after)
|
||||
|
||||
new_namespace = namespace + "::"
|
||||
single_header = re.sub(r"\bCLI::\b", new_namespace, single_header)
|
||||
|
||||
if output is not None:
|
||||
with open(output, "w") as f:
|
||||
f.write(single_header)
|
||||
|
||||
print("Created", output)
|
||||
else:
|
||||
print(single_header)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
usage="Convert source to single header include. Can optionally add namespace and search-replace replacements (for macros).",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument("--output", default=None, help="Single header file output")
|
||||
parser.add_argument(
|
||||
"--main",
|
||||
default="CLI11.hpp.in",
|
||||
help="The main include file that defines the other files",
|
||||
)
|
||||
parser.add_argument("files", nargs="+", help="The header files")
|
||||
parser.add_argument("--namespace", default="CLI", help="Set the namespace")
|
||||
parser.add_argument("--tag", default="CLI11", help="Tag to look up")
|
||||
parser.add_argument(
|
||||
"--macro", nargs=2, help="Replaces OLD_PREFIX_ with NEW_PREFIX_"
|
||||
)
|
||||
parser.add_argument("--version", help="Include this version in the generated file")
|
||||
args = parser.parse_args()
|
||||
|
||||
make_header(
|
||||
args.output,
|
||||
args.main,
|
||||
args.files,
|
||||
args.tag,
|
||||
args.namespace,
|
||||
args.macro,
|
||||
args.version,
|
||||
)
|
||||
10
libs/CLI11/scripts/check_style.sh
Executable file
10
libs/CLI11/scripts/check_style.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env sh
|
||||
set -evx
|
||||
|
||||
clang-format --version
|
||||
|
||||
git ls-files -- '*.cpp' '*.hpp' | xargs clang-format -sort-includes -i -style=file
|
||||
|
||||
git diff --exit-code --color
|
||||
|
||||
set +evx
|
||||
14
libs/CLI11/scripts/check_style_docker.sh
Executable file
14
libs/CLI11/scripts/check_style_docker.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Also good but untagged: CLANG_FORMAT=unibeautify/clang-format
|
||||
# This might provide more control in the future: silkeh/clang:8 (etc)
|
||||
CLANG_FORMAT=saschpe/clang-format:5.0.1
|
||||
|
||||
set -evx
|
||||
|
||||
docker run --rm ${CLANG_FORMAT} --version
|
||||
docker run --rm --user $(id -u):$(id -g) -v "$(pwd)":/workdir -w /workdir ${CLANG_FORMAT} -style=file -sort-includes -i $(git ls-files -- '*.cpp' '*.hpp')
|
||||
|
||||
git diff --exit-code --color
|
||||
|
||||
set +evx
|
||||
36
libs/CLI11/scripts/clang-format-pre-commit
Executable file
36
libs/CLI11/scripts/clang-format-pre-commit
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# To use:
|
||||
# ln -s scripts/clang-format.hook .git/hooks/pre-commit
|
||||
|
||||
# Based loosely on https://github.com/andrewseidl/githook-clang-format
|
||||
|
||||
format_file() {
|
||||
file="${1}"
|
||||
case "$file" in
|
||||
*.hpp | *.cpp | .c | *.cc | *.cu | *.h )
|
||||
if [ -f "${1}" ] ; then
|
||||
clang-format -i -style=file -sort-includes "${1}"
|
||||
if git diff-files --quiet -- "${1}" ; then
|
||||
echo "Already nicely formatted: ${1}"
|
||||
else
|
||||
git add "${1}"
|
||||
echo "Reformatting file: ${1}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "${1}" in
|
||||
--about )
|
||||
echo "Runs clang-format on source files"
|
||||
;;
|
||||
* )
|
||||
for file in `git diff-index --cached --name-only HEAD` ; do
|
||||
format_file "${file}"
|
||||
done
|
||||
;;
|
||||
esac
|
||||
9
libs/CLI11/scripts/mdlint_style.rb
Normal file
9
libs/CLI11/scripts/mdlint_style.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
all
|
||||
|
||||
exclude_rule 'MD013' # Line length
|
||||
exclude_rule 'MD033' # Inline HTML
|
||||
exclude_rule 'MD034' # Bare URL (for now)
|
||||
|
||||
rule 'MD026', punctuation: '.,;:!' # Trailing punctuation in header (& in this case)
|
||||
rule 'MD029', style: :ordered
|
||||
rule 'MD007', indent: 2
|
||||
Reference in New Issue
Block a user