ci: Update common files from meta-phosh
This updates to commit f3c92e90dcc0d65322888217429b75dd101bd0d3
This commit is contained in:
+47
-31
@@ -11,7 +11,7 @@ import sys
|
||||
import tempfile
|
||||
|
||||
# Path relative to this script
|
||||
uncrustify_cfg = '.gitlab-ci/uncrustify.cfg'
|
||||
uncrustify_cfg = ".gitlab-ci/uncrustify.cfg"
|
||||
|
||||
|
||||
def run_diff(sha):
|
||||
@@ -25,8 +25,8 @@ def run_diff(sha):
|
||||
|
||||
|
||||
def find_chunks(diff):
|
||||
file_entry_re = re.compile(r'^\+\+\+ b/(.*)$')
|
||||
diff_chunk_re = re.compile(r'^@@ -\d+,\d+ \+(\d+),(\d+)')
|
||||
file_entry_re = re.compile(r"^\+\+\+ b/(.*)$")
|
||||
diff_chunk_re = re.compile(r"^@@ -\d+,\d+ \+(\d+),(\d+)")
|
||||
file = None
|
||||
chunks = []
|
||||
|
||||
@@ -41,8 +41,10 @@ def find_chunks(diff):
|
||||
len = int(match.group(2))
|
||||
end = start + len
|
||||
|
||||
if len > 0 and (file.endswith('.c') or file.endswith('.h') or file.endswith('.vala')):
|
||||
chunks.append({'file': file, 'start': start, 'end': end})
|
||||
if len > 0 and (
|
||||
file.endswith(".c") or file.endswith(".h") or file.endswith(".vala")
|
||||
):
|
||||
chunks.append({"file": file, "start": start, "end": end})
|
||||
|
||||
return chunks
|
||||
|
||||
@@ -53,14 +55,14 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
||||
with open(file) as f:
|
||||
tmp = tempfile.NamedTemporaryFile()
|
||||
if start > 1:
|
||||
tmp.write(b'/** *INDENT-OFF* **/\n')
|
||||
tmp.write(b"/** *INDENT-OFF* **/\n")
|
||||
for i, line in enumerate(f, 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:
|
||||
tmp.write(b'/** *INDENT-OFF* **/\n')
|
||||
tmp.write(b"/** *INDENT-OFF* **/\n")
|
||||
tmp.seek(0)
|
||||
return tmp
|
||||
|
||||
@@ -68,7 +70,7 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
||||
def remove_indent_comments(output):
|
||||
tmp = tempfile.NamedTemporaryFile()
|
||||
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.seek(0)
|
||||
@@ -77,7 +79,7 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
||||
changed = None
|
||||
for chunk in chunks:
|
||||
# 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
|
||||
proc = subprocess.run(
|
||||
@@ -96,24 +98,24 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
||||
if dry_run is True:
|
||||
# Show changes
|
||||
proc = subprocess.run(
|
||||
["diff", "-up", "--color=always", chunk['file'], formatted.name],
|
||||
["diff", "-up", "--color=always", chunk["file"], formatted.name],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
encoding="utf-8",
|
||||
)
|
||||
diff = proc.stdout
|
||||
if diff != '':
|
||||
output = re.sub('\t', '↦\t', diff)
|
||||
if diff != "":
|
||||
output = re.sub("\t", "↦\t", diff)
|
||||
print(output)
|
||||
changed = True
|
||||
else:
|
||||
# Apply changes
|
||||
diff = subprocess.run(
|
||||
["diff", "-up", chunk['file'], formatted.name],
|
||||
["diff", "-up", chunk["file"], formatted.name],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
subprocess.run(["patch", chunk['file']], input=diff.stdout)
|
||||
subprocess.run(["patch", chunk["file"]], input=diff.stdout)
|
||||
|
||||
formatted.close()
|
||||
|
||||
@@ -121,22 +123,33 @@ def reformat_chunks(chunks, rewrite, dry_run):
|
||||
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description='Check code style. Needs uncrustify installed.')
|
||||
parser.add_argument('--sha', metavar='SHA', type=str,
|
||||
help='SHA for the commit to compare HEAD with')
|
||||
parser.add_argument('--dry-run', '-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"\')')
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Check code style. Needs uncrustify installed."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--sha", metavar="SHA", type=str, help="SHA for the commit to compare HEAD with"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
"-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)
|
||||
return 1
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
sha = args.sha or 'HEAD^'
|
||||
sha = args.sha or "HEAD^"
|
||||
|
||||
diff = run_diff(sha)
|
||||
chunks = find_chunks(diff)
|
||||
@@ -148,22 +161,25 @@ def main(argv):
|
||||
# Commit the added changes as a squash commit
|
||||
subprocess.run(
|
||||
["git", "commit", "--squash", "HEAD", "-C", "HEAD"],
|
||||
stdout=subprocess.DEVNULL)
|
||||
stdout=subprocess.DEVNULL,
|
||||
)
|
||||
# Delete the unapplied changes
|
||||
subprocess.run(["git", "reset", "--hard"], stdout=subprocess.DEVNULL)
|
||||
return 0
|
||||
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:
|
||||
|
||||
$ git rebase {sha} --exec "./.gitlab-ci/check-style.py -r"
|
||||
$ git rebase --autosquash {sha}
|
||||
|
||||
Don't trust uncrustify unconditionally.
|
||||
""")
|
||||
"""
|
||||
)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
||||
Reference in New Issue
Block a user