Skip to content

Commit 087c865

Browse files
authored
Improve clang-format-lint (#3207)
1 parent 8389185 commit 087c865

36 files changed

Lines changed: 866 additions & 343 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ on:
1111
- 'docs/**'
1212
- '.github/workflows/publish.yml'
1313
- '.github/workflows/debian.yml'
14-
- 'tools/ci/make-pkg.ps1'
14+
- '.github/workflows/clang-format.yml'
15+
- 'tools/cmdline/make-pkg.ps1'
1516
pull_request:
1617
types: [opened, synchronize, reopened]
1718
paths-ignore:

.github/workflows/clang-format.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ on:
3939
issue_comment:
4040
types: [created] # Listen for new comments on issues/PRs
4141

42+
env:
43+
LLVM_VER: '21'
44+
4245
jobs:
4346
clang-format-lint:
4447
runs-on: ubuntu-latest
@@ -140,15 +143,18 @@ jobs:
140143
ref: ${{ steps.pp.outputs.head_ref }}
141144
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
142145

143-
- name: Run clang-format lint
146+
- name: Install llvm clang-format
144147
if: ${{ steps.pp.outputs.should_run == 'true' }}
145-
uses: DoozyX/clang-format-lint-action@v0.20
146-
with:
147-
source: './axmol ./extensions ./tests ./templates'
148-
exclude: './3rdparty ./extensions/ImGui/**/im* ./extensions/fairygui ./extensions/Live2D ./extensions/Effekseer ./extensions/scripting/lua-bindings/auto ./extensions/spine ./tests/cpp-tests/Source/Box2DTestBed/samples ./tests/fairygui-tests ./tests/live2d-tests ./extensions/**/*_generated.h'
149-
extensions: 'h,cpp,c,mm'
150-
clangFormatVersion: 20
151-
inplace: True
148+
shell: pwsh
149+
run: |
150+
# Install clang-format
151+
./1k/llvm.ps1 install $env:LLVM_VER clang-format
152+
153+
- name: Formating sources of Axmol
154+
if: ${{ steps.pp.outputs.should_run == 'true' }}
155+
shell: pwsh
156+
run: |
157+
./tools/cmdline/clang-format.ps1 -ver $env:LLVM_VER
152158
153159
# check_only mode
154160
- name: Check for uncommitted changes

.github/workflows/genbindings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- '**/*.md.in'
1111
- 'docs/**'
1212
- '.github/workflows/publish.yml'
13-
- 'tools/ci/make-pkg.ps1'
13+
- 'tools/cmdline/make-pkg.ps1'
1414
- '.github/workflows/debian.yml'
1515

1616
workflow_dispatch:
@@ -27,7 +27,7 @@ jobs:
2727
python-version: '3.12.10' # python-3.12 is last release that support axmol traditional binding generator
2828

2929
- name: Genbindings
30-
run: tools\ci\genbindings.ps1
30+
run: tools\cmdline\genbindings.ps1
3131

3232
- name: Create pull request
3333
if: ${{ env.BINDING_NO_CHANGES != 'true' }}

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
axmol -xc '-DAX_WITH_LZ4=ON,-DAX_WITH_CARES=ON,-DAX_WITH_YAML_CPP=ON,-DAX_WITH_KCP=ON' -c
5555
$input_commitish = "${{ github.event.inputs.commitish }}"
5656
if (!$input_commitish) { $input_commitish = $(git -C $AX_ROOT branch --show-current) }
57-
./tools/ci/publish.ps1 -version "${{ steps.check_ver.outputs.release_ver }}" -commitish $input_commitish
57+
./tools/cmdline/publish.ps1 -version "${{ steps.check_ver.outputs.release_ver }}" -commitish $input_commitish
5858
echo "commitish=$input_commitish" >> ${env:GITHUB_OUTPUT}
5959
6060
- name: Publish to github release page

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,5 @@ release_note_draft.txt
239239

240240
*.hprof
241241

242-
.env
242+
1k/.env
243+
1k/llvm.sh

1k/llvm.ps1

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env pwsh
2+
# This script is only for linux distro: debian or ubuntu
3+
# llvm package list: https://github.com/opencollab/llvm-jenkins.debian.net/blob/master/llvm.sh
4+
param(
5+
$action = '',
6+
$ver = 21,
7+
$tool = 'all'
8+
)
9+
10+
$ver = [int]$ver
11+
12+
if (!$tool -or $tool -eq 'all') {
13+
$llvm_packages = @("clang-$ver", "lldb-$ver", "lld-$ver", "clangd-$ver")
14+
$llvm_binaries = @(
15+
'clang'
16+
'clang++'
17+
'lldb'
18+
'llvm-ar'
19+
'llvm-ranlib'
20+
'llvm-nm'
21+
'llvm-objdump'
22+
'llvm-config'
23+
)
24+
if ($tool -eq 'all') {
25+
$llvm_packages += @(
26+
"clang-tidy-$ver"
27+
"clang-format-$ver"
28+
"clang-tools-$ver"
29+
"llvm-$ver-dev"
30+
"lld-$ver"
31+
"lldb-$ver"
32+
"llvm-$ver-tools"
33+
"libomp-$ver-dev"
34+
"libc++-$ver-dev"
35+
"libc++abi-$ver-dev"
36+
"libclang-common-$ver-dev"
37+
"libclang-$ver-dev"
38+
"libclang-cpp$ver-dev"
39+
"libunwind-$ver-dev"
40+
)
41+
if ($ver -gt 14) {
42+
$llvm_packages += "libclang-rt-$ver-dev", "libpolly-$ver-dev"
43+
}
44+
$llvm_binaries += @(
45+
'clang-format'
46+
'clang-tidy'
47+
'clangd'
48+
'lldb-dap'
49+
)
50+
}
51+
}
52+
else {
53+
$llvm_packages = @("$tool-$ver")
54+
$llvm_binaries = @($tool)
55+
}
56+
57+
if (!$tool -or $tool -eq 'all') {
58+
$llvm_tool = 'clang'
59+
$llvm_tool_real = "clang-$ver"
60+
}
61+
else {
62+
$llvm_tool = $tool
63+
$llvm_tool_real = "$tool-$ver"
64+
}
65+
66+
function find_llvm_tool() {
67+
$verStr = $(& $llvm_tool --version 2>$null) | Select-Object -First 1
68+
$matchInfo = [Regex]::Match($verStr, '(\d+\.)+(\*|\d+)(\-[a-z0-9]+)?')
69+
$foundVer = $matchInfo.Value
70+
return $foundVer
71+
}
72+
73+
function active_llvm($ver) {
74+
echo "Activating llvm-$ver ..."
75+
76+
77+
# list available llvm versions
78+
sudo update-alternatives --display $llvm_tool
79+
80+
$actived_ver = [Version]$(find_llvm_tool)
81+
82+
if ($actived_ver.Major -ne $ver) {
83+
# force set llvm to the specific version
84+
echo "Forcing switch actived llvm $($actived_ver.Major) => $ver ..."
85+
foreach ($exe_name in $llvm_binaries) {
86+
echo "Active alternative: $exe_name /usr/bin/$exe_name-$ver"
87+
sudo update-alternatives --set $exe_name /usr/bin/$exe_name-$ver
88+
}
89+
90+
$actived_ver = [Version]$(find_llvm_tool)
91+
}
92+
93+
# check result llvm version
94+
$llvm_tool_cmd = Get-Command $llvm_tool -ErrorAction SilentlyContinue
95+
echo "Activated llvm tool: $($llvm_tool_cmd.Source), version: $actived_ver"
96+
}
97+
98+
# install
99+
if ($action -eq 'install') {
100+
$llvm_tool_cmd = Get-Command $llvm_tool_real -ErrorAction SilentlyContinue
101+
if (!$llvm_tool_cmd) {
102+
echo "Installing llvm $llvm_tool_real..."
103+
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
104+
$codename = (lsb_release -cs)
105+
$repoName = "deb http://apt.llvm.org/$codename/ llvm-toolchain-$codename-$ver main"
106+
sudo add-apt-repository -y $repoName
107+
sudo apt-get update
108+
sudo apt-get install --allow-unauthenticated --yes $llvm_packages
109+
}
110+
111+
# config installed llvm to alternatives
112+
$priority = $ver * 10
113+
$success_count = 0
114+
foreach ($exe_name in $llvm_binaries) {
115+
echo "Install alternative: /usr/bin/$exe_name $exe_name /usr/bin/$exe_name-$ver $priority"
116+
$actual_path = "/usr/bin/$exe_name-$ver"
117+
if (Test-Path $actual_path -PathType Leaf) {
118+
sudo update-alternatives --install /usr/bin/$exe_name $exe_name $actual_path $priority
119+
++$success_count
120+
}
121+
else {
122+
Write-Warning "llvm.ps1: warning: the executable: $actual_path not exist"
123+
}
124+
}
125+
if ($success_count -eq 0) {
126+
throw 'llvm.ps1: error: all packages install failed!'
127+
}
128+
}
129+
elseif ($action -eq 'uninstall') {
130+
# uninstall
131+
echo "Uninstalling llvm-$ver ..."
132+
133+
# remove alternatives
134+
foreach ($exe_name in $llvm_binaries) {
135+
echo "Remove alternative: $exe_name /usr/bin/$exe_name-$ver"
136+
sudo update-alternatives --remove $exe_name /usr/bin/$exe_name-$ver
137+
}
138+
139+
# uninstall llvm packages via apt
140+
echo "Removing llvm-$ver packages ..."
141+
sudo apt-get remove -y $llvm_packages
142+
sudo apt-get autoremove -y
143+
144+
echo "llvm packages: $llvm_packages has been uninstalled."
145+
}
146+
elseif ($action -eq 'list') {
147+
foreach ($exe_name in $llvm_binaries) {
148+
sudo update-alternatives --display $exe_name
149+
}
150+
}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ across different devices and orientations.
10921092
- Add ability to create console apps by @smilediver in https://github.com/axmolengine/axmol/pull/1859
10931093
- Add support for ensuring sprite content size does not change on new texture by @rh101 in https://github.com/axmolengine/axmol/pull/1897
10941094
- Remove obsolete `box2d-optimized` support by @aismann in https://github.com/axmolengine/axmol/pull/1913
1095-
- Add macOS, Linux support for `tools/ci/genbindings.ps1`
1095+
- Add macOS, Linux support for `tools/cmdline/genbindings.ps1`
10961096
- Fix `axmol` cmdline not raise error when cmake build fail
10971097
- Migrate wasm ci from appveyor to github actions
10981098
- Set AX_USE_METAL and AX_USE_GL to 1 if defined by @smilediver in https://github.com/axmolengine/axmol/pull/1916

axmol/math/Color.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct AX_DLL Color32
7171
std::is_same_v<decltype(_Other{}.r), decltype(_Other{}.g)> &&
7272
std::is_same_v<decltype(_Other{}.r), decltype(_Other{}.b)> &&
7373
std::is_same_v<decltype(_Other{}.r), decltype(_Other{}.a)>>>
74-
Color32& operator=(const _Other& other) noexcept
74+
Color32& operator=(const _Other & other) noexcept
7575
{
7676
set(static_cast<uint8_t>(other.r * 255.f + 0.5f), static_cast<uint8_t>(other.g * 255.f + 0.5f),
7777
static_cast<uint8_t>(other.b * 255.f + 0.5f), static_cast<uint8_t>(other.a * 255.f + 0.5f));

0 commit comments

Comments
 (0)