Skip to content

Commit

Permalink
Add clang-format 16 and 17
Browse files Browse the repository at this point in the history
  • Loading branch information
WolleTD committed Dec 23, 2023
1 parent e436e7f commit 74192a3
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 51 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ FROM alpine:latest
RUN apk --no-cache add git python3 patch setpriv

ARG GH_REPO="muttleyxd/clang-tools-static-binaries"
ARG GH_RELEASE="master-1d7ec53d"
ARG GH_RELEASE="master-8f72ab3c"
ENV GH_URL="https://github.com/${GH_REPO}/releases/download/${GH_RELEASE}"
ENV CLANG_LATEST=15
ENV CLANG_LATEST=17

ADD ${GH_URL}/clang-format-3.9_linux-amd64 \
${GH_URL}/clang-format-4_linux-amd64 \
Expand All @@ -21,6 +21,8 @@ ADD ${GH_URL}/clang-format-3.9_linux-amd64 \
${GH_URL}/clang-format-13_linux-amd64 \
${GH_URL}/clang-format-14_linux-amd64 \
${GH_URL}/clang-format-15_linux-amd64 \
${GH_URL}/clang-format-16_linux-amd64 \
${GH_URL}/clang-format-17_linux-amd64 \
entrypoint.sh \
check-format.sh \
set-clang-version \
Expand Down
30 changes: 16 additions & 14 deletions clang-format_linux.sha512sums
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
f686973bd6642f6decbbb84c73b400a1f39f7d9417badf4eb59eaa4244085d4e5890a79db46ccfa1547546931eaefe26f04d5a76f5218d3adb2f69944341c48c clang-format-3.9_linux-amd64
c2fa0f6ec757bc0add039c4da8aab0c126917a0b87ca53c8594a5078eb31f5089b46139dd6e71f7d8bf3eebbc046f9166d58da4d91ad839e69dd29a5178b04ab clang-format-4_linux-amd64
35fd5bf728adaffb0e90ba1ee1b04e8b0a1147591b875f133dee80f399ed1675f2fe1b85b1e841cd84d4bfd086d40b4328d51213c414eefa3348b1d33a9996eb clang-format-5_linux-amd64
d8829a8cb70aba18f79aa4e14819e92d0edf8f2582a33b8f26253d872f3bbc865c58f49c77078fd9f4076f046a413e88fa91f4fd462494923f4be474ea6999e9 clang-format-6_linux-amd64
d52d0f0d7e67c445e59682a4ddfbfc49a3d8c339b2e3d74dcc70cff231934ad1716542b8a1ebfef06f23b38f058f93e4023614e9cb0e51c1d6305fd4a89d14da clang-format-7_linux-amd64
4dd522562a7b52875129d103f03883bf3ff64804a81ee4fe649b2298c275c72969b20431668f1d5ca2e2670321c251c2e2f07739a25c17e0f89080d36afbda20 clang-format-8_linux-amd64
3f6f30b2d516a5b848f9b57a2ae061709f4e457d37db7ad0877f8968f6b97cda02537f40f439cc0a98f2846c4e16d6444e3406ca154c4734b405a288d655b179 clang-format-9_linux-amd64
4ef38082e99529764209b14236ad9943be3678176dd99ac36d6d29dbcee3210f7d77e878ccd5b70d27046e6a0207cb4637074ae82ea7ce4a106f8bced716ca89 clang-format-10_linux-amd64
9bec37921b824bec8b593761ec1bdd8718c7008616fc09a4fd42cea2d8d805df024ae601058371afd73c4faa3d331453ab3ee402d19b6a98fd1dbf00e4fe375f clang-format-11_linux-amd64
9471428ef735c49c8241c24c111eafec0afcdf4ca2dca19d2a2895e7b76a4b2d46beec54d9cde64aee949692e281997080e61c18dead46bb2e6aa9b359de32f2 clang-format-12_linux-amd64
e91e6357018c3275a7bd3b01ab5c9c5fdabba3f2862ae7a29ad0d36dd5f8137da841dc0001964ab4611d42701f39138191e37c6f3265ce122e4e1f710c5ff6ce clang-format-12.0.1_linux-amd64
21726b8414e3ebeab09cc98db3aee81b504dda60547c4b4af1613b66acc965a74257d17d3192c16fccc2dfe5e8b8ca5f50dc70bb72bc448d4f995df9ec3677c4 clang-format-13_linux-amd64
9613be11bd195b1208d2ef7f40607ee91bbdd0fc54f9b363248809951b861e25708817f9053b5b987c5c1845ae12fb5245b7c6a91c6736eac8a7c1ede612c276 clang-format-14_linux-amd64
8251ea669e08afc1ffd2ffe6b3c261bc8fd12ae812c2c2a3e4aeb008206997e1cb49ae92528d13029f1a79a1091e7a751f8084b6bad0563c2ce7c03146056352 clang-format-15_linux-amd64
e1c8bbacf8306037e34605a4a8c33089a115fe534c39527ad3a2e9e3a36ed8eaf0e411dcad06c907b8fd7ccb970d7aa042159f89dfdcadb64d542e18808a33ec clang-format-3.9_linux-amd64
42ed7ac80d9eb4706a7568baf907ab0552261020dedb3fd45f413aad9d92560e6a62e94b9011b5ef4f241c1b106bd0f18cfe25280ed3df20caf764d396efaf74 clang-format-4_linux-amd64
df2728bf97d45ca761732ab6979e662c9ec1c376a9ac5fdcf3b67d79064903ee0c809a7f4ce29b3f576278ec3bef1e6504e9987fa52ff447d79c2acab53b8300 clang-format-5_linux-amd64
427861d72313886856fe77a01c52ee8067f63f2bb73a5628f26bb1593a6a49ceb3f36ef219646be3e0676b24ab832ad59712b0d977ad891364ddcfd8b7cea36a clang-format-6_linux-amd64
eb8a8e2f6bbb1cda7d5847d2432183b72dc4056a184716ac4f3b06c41993800767424fe0838964fcb3af0babdae370bcdff71b672ef5186a221a743d0e922f1a clang-format-7_linux-amd64
1ed2a302994bd7a877f4c1a45e8bafab6a2194b3e9543e67e342688ecb5d50eaa1edadfd3d9c1eecfc40742f5bc4576d1a5e47b44c080415dd8832b9bbd9be42 clang-format-8_linux-amd64
da1049d00c6d622a8f7924e09c383b86f38bced1eb6856b2484b9eb26a725413dc9125ea4960692c31a241e509945e3d5da200d0eac7a73d82388fe24fdc358a clang-format-9_linux-amd64
b8ae8e3ee2f6335349b015460dc0b66ecf185dffd847230010b136732602c7f5e9b12d9821ccecfe0f33579cd0725df9ffc48795646275e39e8a86b83c5d9490 clang-format-10_linux-amd64
e96b3e1b19417398221bbb72d2bfc8dd45d569914d9053b8980e12fa45c7d23736c17a056372afe7de1fa43b76fbd9364c7034f8e33318c379d95380e87c35e6 clang-format-11_linux-amd64
4c588c373b6043d0e6509a0653e795d7449d804b2bebdf35bb836c583ff188eb20d0dc3889c0da4b86f3b20f1361404d6be5f3cef68da4eab199caa2f5248dec clang-format-12_linux-amd64
bcefc22f39137a492ea244fa49a1568795f218b8c673b47aeeb28ffca67b031b84cd1a364ed767db4913a5af098d64e3e1484ba5aae2ecba4ae1c833dfbf7a05 clang-format-12.0.1_linux-amd64
d36a88277ad4cd46c3484505108b3a7e39a2838051f28b3d4278900cd3a15622092357bcfa75c217108b586f9eeb8594e9acd3524576fd5c9afcfa49b497046a clang-format-13_linux-amd64
a8dc02d425f2e88b4e3ea9e16dc03a8f328ddb3df92bcba7216c2bfb12fbe932b5bab0e19e61446647f84ccca227b387f0cddeca577332efb2a6bc30c8c83be3 clang-format-14_linux-amd64
d5ea58d9a5f3b7206ec74c19671d1d540c871ed2326565d168db48254659b0507240409cc1089f5195c86f8a3e923c4ed9de6dddcb286164a2e1dca35034ceaa clang-format-15_linux-amd64
74bfb79aa851823db65e5b5ef80bb479c610309d3af1e7de395b5b7cd1d62f24c512a050126632a9266f671c1f8c892f9bef5ce2fd6a9061c2c3a758d0b9a520 clang-format-16_linux-amd64
cd6bb7126959c412986531ec0fb93f6990ba21ab4a9925c014643d6a663cdbf605fda707169f83af207fb92aa3873704b52252822530af739d32744bea78124f clang-format-17_linux-amd64
17 changes: 17 additions & 0 deletions get_sha512sums.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -eu

if [ $# -ne 1 ]; then
echo "Usage: $0 <release>" >&2
exit 1
fi

gh_release="$1"
gh_repo="muttleyxd/clang-tools-static-binaries"
gh_url="https://github.com/${gh_repo}/releases/download/${gh_release}"

versions=( 3.9 4 5 6 7 8 9 10 11 12 12.0.1 13 14 15 16 17 )

for version in ${versions[@]}; do
curl -fL ${gh_url}/clang-format-${version}_linux-amd64.sha512sum
done
96 changes: 61 additions & 35 deletions git-clang-format-15 → git-clang-format-17
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main():
'c', 'h', # C
'm', # ObjC
'mm', # ObjC++
'cc', 'cp', 'cpp', 'c++', 'cxx', 'hh', 'hpp', 'hxx', # C++
'cc', 'cp', 'cpp', 'c++', 'cxx', 'hh', 'hpp', 'hxx', 'inc', # C++
'ccm', 'cppm', 'cxxm', 'c++m', # C++ Modules
'cu', 'cuh', # CUDA
# Other languages that clang-format supports
Expand Down Expand Up @@ -179,15 +179,17 @@ def main():

if len(commits) > 1:
old_tree = commits[1]
new_tree = run_clang_format_and_save_to_tree(changed_lines,
revision=commits[1],
binary=opts.binary,
style=opts.style)
revision = old_tree
elif opts.staged:
old_tree = create_tree_from_index(changed_lines)
revision = ''
else:
old_tree = create_tree_from_workdir(changed_lines)
new_tree = run_clang_format_and_save_to_tree(changed_lines,
binary=opts.binary,
style=opts.style)
revision = None
new_tree = run_clang_format_and_save_to_tree(changed_lines,
revision,
binary=opts.binary,
style=opts.style)
if opts.verbose >= 1:
print('old tree: %s' % old_tree)
print('new tree: %s' % new_tree)
Expand All @@ -198,16 +200,16 @@ def main():
return 0

if opts.diff:
print_diff(old_tree, new_tree)
elif opts.diffstat:
print_diffstat(old_tree, new_tree)
else:
changed_files = apply_changes(old_tree, new_tree, force=opts.force,
patch_mode=opts.patch)
if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
print('changed files:')
for filename in changed_files:
print(' %s' % filename)
return print_diff(old_tree, new_tree)
if opts.diffstat:
return print_diffstat(old_tree, new_tree)

changed_files = apply_changes(old_tree, new_tree, force=opts.force,
patch_mode=opts.patch)
if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
print('changed files:')
for filename in changed_files:
print(' %s' % filename)

return 1

Expand Down Expand Up @@ -345,7 +347,7 @@ def extract_lines(patch_file):
line = convert_string(line)
match = re.search(r'^\+\+\+\ [^/]+/(.*)', line)
if match:
filename = match.group(1).rstrip('\r\n')
filename = match.group(1).rstrip('\r\n\t')
match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
if match:
start_line = int(match.group(1))
Expand Down Expand Up @@ -394,23 +396,45 @@ def create_tree_from_workdir(filenames):
return create_tree(filenames, '--stdin')


def create_tree_from_index(filenames):
# Copy the environment, because the files have to be read from the original
# index.
env = os.environ.copy()
def index_contents_generator():
for filename in filenames:
git_ls_files_cmd = ['git', 'ls-files', '--stage', '-z', '--', filename]
git_ls_files = subprocess.Popen(git_ls_files_cmd, env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout = git_ls_files.communicate()[0]
yield convert_string(stdout.split(b'\0')[0])
return create_tree(index_contents_generator(), '--index-info')


def run_clang_format_and_save_to_tree(changed_lines, revision=None,
binary='clang-format', style=None):
"""Run clang-format on each file and save the result to a git tree.
Returns the object ID (SHA-1) of the created tree."""
# Copy the environment when formatting the files in the index, because the
# files have to be read from the original index.
env = os.environ.copy() if revision == '' else None
def iteritems(container):
try:
return container.iteritems() # Python 2
except AttributeError:
return container.items() # Python 3
def index_info_generator():
for filename, line_ranges in iteritems(changed_lines):
if revision:
git_metadata_cmd = ['git', 'ls-tree',
'%s:%s' % (revision, os.path.dirname(filename)),
os.path.basename(filename)]
git_metadata = subprocess.Popen(git_metadata_cmd, stdin=subprocess.PIPE,
if revision is not None:
if len(revision) > 0:
git_metadata_cmd = ['git', 'ls-tree',
'%s:%s' % (revision, os.path.dirname(filename)),
os.path.basename(filename)]
else:
git_metadata_cmd = ['git', 'ls-files', '--stage', '--', filename]
git_metadata = subprocess.Popen(git_metadata_cmd, env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout = git_metadata.communicate()[0]
mode = oct(int(stdout.split()[0], 8))
Expand All @@ -422,7 +446,8 @@ def run_clang_format_and_save_to_tree(changed_lines, revision=None,
blob_id = clang_format_to_blob(filename, line_ranges,
revision=revision,
binary=binary,
style=style)
style=style,
env=env)
yield '%s %s\t%s' % (mode, blob_id, filename)
return create_tree(index_info_generator(), '--index-info')

Expand All @@ -448,11 +473,12 @@ def create_tree(input_lines, mode):


def clang_format_to_blob(filename, line_ranges, revision=None,
binary='clang-format', style=None):
binary='clang-format', style=None, env=None):
"""Run clang-format on the given file and save the result to a git blob.
Runs on the file in `revision` if not None, or on the file in the working
directory if `revision` is None.
directory if `revision` is None. Revision can be set to an empty string to run
clang-format on the file in the index.
Returns the object ID (SHA-1) of the created blob."""
clang_format_cmd = [binary]
Expand All @@ -461,10 +487,10 @@ def clang_format_to_blob(filename, line_ranges, revision=None,
clang_format_cmd.extend([
'-lines=%s:%s' % (start_line, start_line+line_count-1)
for start_line, line_count in line_ranges])
if revision:
if revision is not None:
clang_format_cmd.extend(['-assume-filename='+filename])
git_show_cmd = ['git', 'cat-file', 'blob', '%s:%s' % (revision, filename)]
git_show = subprocess.Popen(git_show_cmd, stdin=subprocess.PIPE,
git_show = subprocess.Popen(git_show_cmd, env=env, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
git_show.stdin.close()
clang_format_stdin = git_show.stdout
Expand Down Expand Up @@ -536,8 +562,8 @@ def print_diff(old_tree, new_tree):
# We also only print modified files since `new_tree` only contains the files
# that were modified, so unmodified files would show as deleted without the
# filter.
subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
'--'])
return subprocess.run(['git', 'diff', '--diff-filter=M',
'--exit-code', old_tree, new_tree]).returncode

def print_diffstat(old_tree, new_tree):
"""Print the diffstat between the two trees to stdout."""
Expand All @@ -548,8 +574,8 @@ def print_diffstat(old_tree, new_tree):
# We also only print modified files since `new_tree` only contains the files
# that were modified, so unmodified files would show as deleted without the
# filter.
subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree,
'--'])
return subprocess.run(['git', 'diff', '--diff-filter=M', '--exit-code',
'--stat', old_tree, new_tree]).returncode

def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
"""Apply the changes in `new_tree` to the working directory.
Expand All @@ -575,11 +601,11 @@ def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
# better message, "Apply ... to index and worktree". This is not quite
# right, since it won't be applied to the user's index, but oh well.
with temporary_index_file(old_tree):
subprocess.check_call(['git', 'checkout', '--patch', new_tree])
subprocess.run(['git', 'checkout', '--patch', new_tree], check=True)
index_tree = old_tree
else:
with temporary_index_file(new_tree):
run('git', 'checkout-index', '-a', '-f')
run('git', 'checkout-index', '-f', '--', *changed_files)
return changed_files


Expand Down

0 comments on commit 74192a3

Please sign in to comment.