ci: Update common files from meta-phosh
This updates to commit f3c92e90dcc0d65322888217429b75dd101bd0d3
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd po/ || exit 1
|
||||||
|
# barf on untranslated C files. Seems intltool
|
||||||
|
# can't be told to exit with non-zero exit status
|
||||||
|
# in this case
|
||||||
|
|
||||||
|
if intltool-update -m 2>&1 | grep -E -qs '/.*\.(c|ui)'; then
|
||||||
|
intltool-update -m
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for broken po files
|
||||||
|
for file in *.po; do
|
||||||
|
echo -n "Checking ${file}: "
|
||||||
|
msgfmt -v -c "${file}"
|
||||||
|
# Check for errors, msgfmt returns 0 on errors too
|
||||||
|
if msgfmt -c "${file}" 2>&1 | grep -qs 'fatal error'; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
+47
-31
@@ -11,7 +11,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
# Path relative to this script
|
# Path relative to this script
|
||||||
uncrustify_cfg = '.gitlab-ci/uncrustify.cfg'
|
uncrustify_cfg = ".gitlab-ci/uncrustify.cfg"
|
||||||
|
|
||||||
|
|
||||||
def run_diff(sha):
|
def run_diff(sha):
|
||||||
@@ -25,8 +25,8 @@ def run_diff(sha):
|
|||||||
|
|
||||||
|
|
||||||
def find_chunks(diff):
|
def find_chunks(diff):
|
||||||
file_entry_re = re.compile(r'^\+\+\+ b/(.*)$')
|
file_entry_re = re.compile(r"^\+\+\+ b/(.*)$")
|
||||||
diff_chunk_re = re.compile(r'^@@ -\d+,\d+ \+(\d+),(\d+)')
|
diff_chunk_re = re.compile(r"^@@ -\d+,\d+ \+(\d+),(\d+)")
|
||||||
file = None
|
file = None
|
||||||
chunks = []
|
chunks = []
|
||||||
|
|
||||||
@@ -41,8 +41,10 @@ def find_chunks(diff):
|
|||||||
len = int(match.group(2))
|
len = int(match.group(2))
|
||||||
end = start + len
|
end = start + len
|
||||||
|
|
||||||
if len > 0 and (file.endswith('.c') or file.endswith('.h') or file.endswith('.vala')):
|
if len > 0 and (
|
||||||
chunks.append({'file': file, 'start': start, 'end': end})
|
file.endswith(".c") or file.endswith(".h") or file.endswith(".vala")
|
||||||
|
):
|
||||||
|
chunks.append({"file": file, "start": start, "end": end})
|
||||||
|
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
@@ -53,14 +55,14 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
|||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
tmp = tempfile.NamedTemporaryFile()
|
tmp = tempfile.NamedTemporaryFile()
|
||||||
if start > 1:
|
if start > 1:
|
||||||
tmp.write(b'/** *INDENT-OFF* **/\n')
|
tmp.write(b"/** *INDENT-OFF* **/\n")
|
||||||
for i, line in enumerate(f, start=1):
|
for i, line in enumerate(f, start=1):
|
||||||
if i == start - 1:
|
if i == start - 1:
|
||||||
tmp.write(b'/** *INDENT-ON* **/\n')
|
tmp.write(b"/** *INDENT-ON* **/\n")
|
||||||
|
|
||||||
tmp.write(bytes(line, 'utf-8'))
|
tmp.write(bytes(line, "utf-8"))
|
||||||
if i == end - 1:
|
if i == end - 1:
|
||||||
tmp.write(b'/** *INDENT-OFF* **/\n')
|
tmp.write(b"/** *INDENT-OFF* **/\n")
|
||||||
tmp.seek(0)
|
tmp.seek(0)
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
@@ -68,7 +70,7 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
|||||||
def remove_indent_comments(output):
|
def remove_indent_comments(output):
|
||||||
tmp = tempfile.NamedTemporaryFile()
|
tmp = tempfile.NamedTemporaryFile()
|
||||||
for line in output:
|
for line in output:
|
||||||
if line != b'/** *INDENT-OFF* **/\n' and line != b'/** *INDENT-ON* **/\n':
|
if line != b"/** *INDENT-OFF* **/\n" and line != b"/** *INDENT-ON* **/\n":
|
||||||
tmp.write(line)
|
tmp.write(line)
|
||||||
|
|
||||||
tmp.seek(0)
|
tmp.seek(0)
|
||||||
@@ -77,7 +79,7 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
|||||||
changed = None
|
changed = None
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
# Add INDENT-ON/OFF comments
|
# Add INDENT-ON/OFF comments
|
||||||
tmp = create_temp_file(chunk['file'], chunk['start'], chunk['end'])
|
tmp = create_temp_file(chunk["file"], chunk["start"], chunk["end"])
|
||||||
|
|
||||||
# uncrustify chunk
|
# uncrustify chunk
|
||||||
proc = subprocess.run(
|
proc = subprocess.run(
|
||||||
@@ -96,24 +98,24 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
|||||||
if dry_run is True:
|
if dry_run is True:
|
||||||
# Show changes
|
# Show changes
|
||||||
proc = subprocess.run(
|
proc = subprocess.run(
|
||||||
["diff", "-up", "--color=always", chunk['file'], formatted.name],
|
["diff", "-up", "--color=always", chunk["file"], formatted.name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
diff = proc.stdout
|
diff = proc.stdout
|
||||||
if diff != '':
|
if diff != "":
|
||||||
output = re.sub('\t', '↦\t', diff)
|
output = re.sub("\t", "↦\t", diff)
|
||||||
print(output)
|
print(output)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
# Apply changes
|
# Apply changes
|
||||||
diff = subprocess.run(
|
diff = subprocess.run(
|
||||||
["diff", "-up", chunk['file'], formatted.name],
|
["diff", "-up", chunk["file"], formatted.name],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
subprocess.run(["patch", chunk['file']], input=diff.stdout)
|
subprocess.run(["patch", chunk["file"]], input=diff.stdout)
|
||||||
|
|
||||||
formatted.close()
|
formatted.close()
|
||||||
|
|
||||||
@@ -121,22 +123,33 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
|||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = argparse.ArgumentParser(description='Check code style. Needs uncrustify installed.')
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('--sha', metavar='SHA', type=str,
|
description="Check code style. Needs uncrustify installed."
|
||||||
help='SHA for the commit to compare HEAD with')
|
)
|
||||||
parser.add_argument('--dry-run', '-d', type=bool,
|
parser.add_argument(
|
||||||
action=argparse.BooleanOptionalAction,
|
"--sha", metavar="SHA", type=str, help="SHA for the commit to compare HEAD with"
|
||||||
help='Only print changes to stdout, do not change code')
|
)
|
||||||
parser.add_argument('--rewrite', '-r', type=bool,
|
parser.add_argument(
|
||||||
action=argparse.BooleanOptionalAction,
|
"--dry-run",
|
||||||
help='Whether to amend the result to the last commit (e.g. \'git rebase --exec "%(prog)s -r"\')')
|
"-d",
|
||||||
|
type=bool,
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
help="Only print changes to stdout, do not change code",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--rewrite",
|
||||||
|
"-r",
|
||||||
|
type=bool,
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
help="Whether to amend the result to the last commit (e.g. 'git rebase --exec \"%(prog)s -r\"')",
|
||||||
|
)
|
||||||
|
|
||||||
if not os.path.exists('.git'):
|
if not os.path.exists(".git"):
|
||||||
print("Not in toplevel of a git repository", fille=sys.stderr)
|
print("Not in toplevel of a git repository", fille=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
sha = args.sha or 'HEAD^'
|
sha = args.sha or "HEAD^"
|
||||||
|
|
||||||
diff = run_diff(sha)
|
diff = run_diff(sha)
|
||||||
chunks = find_chunks(diff)
|
chunks = find_chunks(diff)
|
||||||
@@ -148,22 +161,25 @@ def main(argv):
|
|||||||
# Commit the added changes as a squash commit
|
# Commit the added changes as a squash commit
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["git", "commit", "--squash", "HEAD", "-C", "HEAD"],
|
["git", "commit", "--squash", "HEAD", "-C", "HEAD"],
|
||||||
stdout=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
# Delete the unapplied changes
|
# Delete the unapplied changes
|
||||||
subprocess.run(["git", "reset", "--hard"], stdout=subprocess.DEVNULL)
|
subprocess.run(["git", "reset", "--hard"], stdout=subprocess.DEVNULL)
|
||||||
return 0
|
return 0
|
||||||
elif args.dry_run is True and changed is True:
|
elif args.dry_run is True and changed is True:
|
||||||
print(f"""
|
print(
|
||||||
|
f"""
|
||||||
Issue the following commands in your local tree to apply the suggested changes:
|
Issue the following commands in your local tree to apply the suggested changes:
|
||||||
|
|
||||||
$ git rebase {sha} --exec "./.gitlab-ci/check-style.py -r"
|
$ git rebase {sha} --exec "./.gitlab-ci/check-style.py -r"
|
||||||
$ git rebase --autosquash {sha}
|
$ git rebase --autosquash {sha}
|
||||||
|
|
||||||
Don't trust uncrustify unconditionally.
|
Don't trust uncrustify unconditionally.
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
sys.exit(main(sys.argv[1:]))
|
sys.exit(main(sys.argv[1:]))
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
patterns:
|
||||||
|
deny:
|
||||||
|
- regex: '^$CI_MERGE_REQUEST_PROJECT_URL/(-/)?merge_requests/$CI_MERGE_REQUEST_IID$'
|
||||||
|
message: Commit message must not contain a link to its own merge request
|
||||||
|
- regex: '^[^:]+: [a-z]'
|
||||||
|
message: "Commit description in commit message subject should be properly Capitalized. E.g. 'monitor: Avoid crash on unplug'"
|
||||||
|
where: subject
|
||||||
|
- regex: '^\S*\.(c|h|ui):'
|
||||||
|
message: Commit message subject prefix should not include .c, .h etc.
|
||||||
|
where: subject
|
||||||
|
- regex: '([^.]\.|[:,;])\s*$'
|
||||||
|
message: Commit message subject should not end with punctuation
|
||||||
|
where: subject
|
||||||
|
- regex: '^[A-Z]\S*:'
|
||||||
|
message: "Identifier in commit message subject should start lowercase 'monitor: Avoid crash on unplug'"
|
||||||
|
where: subject
|
||||||
|
require:
|
||||||
|
- regex: '^[a-z0-9,\.\+\-/#=_]+:'
|
||||||
|
message: "Commit message should start with a lowercase identifier 'monitor: Avoid crash on unplug'"
|
||||||
|
where: subject
|
||||||
@@ -1,9 +1,22 @@
|
|||||||
|
#
|
||||||
|
# Uncrustify config for phosh and related projects
|
||||||
|
#
|
||||||
|
|
||||||
|
# A span is the number of lines considered
|
||||||
|
# A threshold is the maximum number of columns an item is moved
|
||||||
|
|
||||||
# Indent by two spaces
|
# Indent by two spaces
|
||||||
indent_columns = 2
|
indent_columns = 2
|
||||||
# No tabs
|
# No tabs
|
||||||
indent_with_tabs = 0
|
indent_with_tabs = 0
|
||||||
# Line length
|
# Line length
|
||||||
code_width = 100
|
code_width = 100
|
||||||
|
# Whether to remove superfluous semicolons
|
||||||
|
mod_remove_extra_semicolon = true
|
||||||
|
# indent goto by 1 (or -1 brace level)
|
||||||
|
indent_label = -1
|
||||||
|
# don't indent case after switch
|
||||||
|
indent_switch_case = 0
|
||||||
|
|
||||||
#
|
#
|
||||||
# Keywords and operators
|
# Keywords and operators
|
||||||
@@ -30,11 +43,23 @@ nl_else_brace = remove
|
|||||||
nl_else_if = remove
|
nl_else_if = remove
|
||||||
# Add or remove newline between 'for' and '{'.
|
# Add or remove newline between 'for' and '{'.
|
||||||
nl_for_brace = remove
|
nl_for_brace = remove
|
||||||
|
# Add or remove newline between 'while' and '{'.
|
||||||
|
nl_while_brace = remove
|
||||||
# Treat iterators as for loops:
|
# Treat iterators as for loops:
|
||||||
set FOR wl_list_for_each wl_list_for_each_reverse wl_list_for_each_safe
|
set FOR wl_list_for_each wl_list_for_each_reverse wl_list_for_each_safe
|
||||||
|
# Remove braces on single line if/for/while statements
|
||||||
|
mod_full_brace_if = remove
|
||||||
|
mod_full_brace_for = remove
|
||||||
|
mod_full_brace_while = remove
|
||||||
|
# If any must be braced, they are all braced. If all can be unbraced, then the braces are removed.
|
||||||
|
mod_full_brace_if_chain = 1
|
||||||
|
# Remove braces around case (when there are no variables declarations)
|
||||||
|
mod_case_brace = remove
|
||||||
|
# Don't remove branches if the statement has more than one line
|
||||||
|
mod_full_brace_nl = 2
|
||||||
|
|
||||||
#
|
#
|
||||||
# Function declarations, defintions and calls
|
# Function declarations, definitions and calls
|
||||||
#
|
#
|
||||||
# Add space between function name and '(' on function declaration.
|
# Add space between function name and '(' on function declaration.
|
||||||
sp_func_proto_paren = add
|
sp_func_proto_paren = add
|
||||||
@@ -45,6 +70,10 @@ sp_func_proto_paren_empty = add
|
|||||||
sp_func_def_paren = add
|
sp_func_def_paren = add
|
||||||
# Add or remove space between function name and '(' on function calls.
|
# Add or remove space between function name and '(' on function calls.
|
||||||
sp_func_call_paren = add
|
sp_func_call_paren = add
|
||||||
|
# Specialcase i18n macros
|
||||||
|
set func_call_user _ N_ C_
|
||||||
|
sp_func_call_user_paren = remove
|
||||||
|
|
||||||
# Whether to force indentation of function definitions to start in column 1.
|
# Whether to force indentation of function definitions to start in column 1.
|
||||||
indent_func_def_force_col1 = true
|
indent_func_def_force_col1 = true
|
||||||
# Add newline between return type and function name in a function definition.
|
# Add newline between return type and function name in a function definition.
|
||||||
@@ -102,8 +131,15 @@ align_typedef_star_style = 2
|
|||||||
# The gap for aligning struct/union member definitions.
|
# The gap for aligning struct/union member definitions.
|
||||||
align_var_struct_gap = 1
|
align_var_struct_gap = 1
|
||||||
# The span for aligning struct/union member definitions.
|
# The span for aligning struct/union member definitions.
|
||||||
align_var_struct_span = 8
|
align_var_struct_span = 4
|
||||||
|
# The threshold for aligning struct/union member definitions.
|
||||||
|
align_var_struct_thresh = 8
|
||||||
|
|
||||||
# Remove space between pointer stars '*'.
|
# Remove space between pointer stars '*'.
|
||||||
sp_between_ptr_star = remove
|
sp_between_ptr_star = remove
|
||||||
# Add space before '(' of control statements ('if', 'for', 'switch', 'while', etc.)
|
# Add space before '(' of control statements ('if', 'for', 'switch', 'while', etc.)
|
||||||
sp_before_sparen = add
|
sp_before_sparen = add
|
||||||
|
|
||||||
|
# Add spaces around assignments and arithmethic operators
|
||||||
|
sp_assign = add
|
||||||
|
sp_arith = add
|
||||||
|
|||||||
Reference in New Issue
Block a user