已合并
!2644 clang edits #55
pavelmironchik创建于 2025年10月27日
!2644 clang edits #55
已合并
共 6 个文件变更+48-41
Dclang-format/apply-correct-format.sh+0-16
| @@ -1,16 +0,0 @@ | |||
| 1 | -#!/bin/bash | ||
| 2 | - | ||
| 3 | -# $1 - filePath to patch (default - `./patches/clang-format.patch`) | ||
| 4 | - | ||
| 5 | -patchFile=${1:-$curDir"/patches/clang-format.patch"} | ||
| 6 | -patchFile=$(readlink -m $patchFile) | ||
| 7 | - | ||
| 8 | -curDir="$(pwd)" | ||
| 9 | -rootDir="$(git rev-parse --show-toplevel)" | ||
| 10 | - | ||
| 11 | -cd $rootDir | ||
| 12 | - | ||
| 13 | -echo "Try to apply patch: "$patchFile | ||
| 14 | -git apply --stat --apply --unsafe-paths --verbose $patchFile | ||
| 15 | - | ||
| 16 | -cd $curDir | ||
Dclang-format/package.json+0-17
| @@ -1,17 +0,0 @@ | |||
| 1 | -{ | ||
| 2 | - "private": true, | ||
| 3 | - "version": "2.1.7", | ||
| 4 | - "description": "format code with clang-format tool", | ||
| 5 | - "license": "Apache-2.0", | ||
| 6 | - "keywords": [], | ||
| 7 | - "config": { | ||
| 8 | - "sig_path": "../external/arkoala-arkts/framework/native/src ../external/arkoala-arkts/arkui/src/ani/native/", | ||
| 9 | - "patch_path": "./patches/sig_patch.patch" | ||
| 10 | - }, | ||
| 11 | - "scripts": { | ||
| 12 | - "check-format": "bash ./check-format.sh ${PATCH_FILE} ${DIR_PATH}", | ||
| 13 | - "apply-format": "bash ./apply-correct-format.sh ${PATCH_FILE}", | ||
| 14 | - "check-format:external": "DIR_PATH=$npm_package_config_sig_path PATCH_FILE=$npm_package_config_patch_path npm run check-format", | ||
| 15 | - "apply-format:external": "PATCH_FILE=$npm_package_config_patch_path npm run apply-format" | ||
| 16 | - } | ||
| 17 | -} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +# $1 - search path (file or directory or multiple) | ||
| 4 | + | ||
| 5 | +curDir="$(pwd)" | ||
| 6 | +rootDir="$(git rev-parse --show-toplevel)" | ||
| 7 | + | ||
| 8 | +searchDir=($@) | ||
| 9 | +searchDir=${searchDir[@]:0} | ||
| 10 | +searchDir=$(readlink -m $searchDir) | ||
| 11 | + | ||
| 12 | +cd $rootDir | ||
| 13 | +searchDir=$(realpath -m --relative-to=$rootDir $searchDir) | ||
| 14 | +echo "Search paths: "$searchDir | ||
| 15 | +files=($(find $searchDir -not -iname "*.ttf.cc" -and -type f -and \( -iname '*.h' -or -iname '*.cc' \))) | ||
| 16 | + | ||
| 17 | +for file in ${files[*]} | ||
| 18 | +do | ||
| 19 | + echo "Applying clang format: "$file | ||
| 20 | + clang-format $file --style=file -i | ||
| 21 | +done | ||
| 22 | +cd $curDir | ||
| @@ -1,25 +1,25 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | 2 | ||
| 3 | -# $1 - filePath to save patch | 3 | +# $1 - search path (file or directory or multiple) |
| 4 | -# $2 - search path (file or directory or multiple) | ||
| 5 | 4 | ||
| 6 | curDir="$(pwd)" | 5 | curDir="$(pwd)" |
| 7 | rootDir="$(git rev-parse --show-toplevel)" | 6 | rootDir="$(git rev-parse --show-toplevel)" |
| 8 | 7 | ||
| 9 | -patchFile=${1:-$curDir"/patches/clang-format.patch"} | 8 | +mkfile() { mkdir -p "$(dirname "$1")" && touch "$1" ; } |
| 9 | + | ||
| 10 | +patchFile="./patches/clang-format.patch" | ||
| 10 | patchFile=$(readlink -m $patchFile) | 11 | patchFile=$(readlink -m $patchFile) |
| 12 | +mkfile $patchFile | ||
| 11 | > $patchFile | 13 | > $patchFile |
| 12 | 14 | ||
| 13 | searchDir=($@) | 15 | searchDir=($@) |
| 14 | -searchDir=${searchDir[@]:1} | 16 | +searchDir=${searchDir[@]:0} |
| 15 | searchDir=$(readlink -m $searchDir) | 17 | searchDir=$(readlink -m $searchDir) |
| 16 | 18 | ||
| 17 | cd $rootDir | 19 | cd $rootDir |
| 18 | searchDir=$(realpath -m --relative-to=$rootDir $searchDir) | 20 | searchDir=$(realpath -m --relative-to=$rootDir $searchDir) |
| 19 | echo "Search paths: "$searchDir | 21 | echo "Search paths: "$searchDir |
| 20 | -files=($(find $searchDir -type f -iname '*.h' -o -iname '*.cpp')) | 22 | +files=($(find $searchDir -not -iname "*.ttf.cc" -and -type f -and \( -iname '*.h' -or -iname '*.cpp' \))) |
| 21 | - | ||
| 22 | -# find idlize-copy/external/arkoala-arkts/ \( \( -iname '*.h' -or -iname '*.cpp' \) -and -not -path "*/node_modules/*" -and -not -path "*/tools/*" \) | ||
| 23 | 23 | ||
| 24 | for file in ${files[*]} | 24 | for file in ${files[*]} |
| 25 | do | 25 | do |
| @@ -34,4 +34,3 @@ done | |||
| 34 | cd $curDir | 34 | cd $curDir |
| 35 | 35 | ||
| 36 | echo "Patch saved: "$patchFile | 36 | echo "Patch saved: "$patchFile |
| 37 | - | ||
| @@ -0,0 +1,18 @@ | |||
| 1 | +{ | ||
| 2 | + "private": true, | ||
| 3 | + "version": "2.1.7", | ||
| 4 | + "description": "format code with clang-format tool", | ||
| 5 | + "license": "Apache-2.0", | ||
| 6 | + "keywords": [], | ||
| 7 | + "config": { | ||
| 8 | + "sig_path": "../../external/interop/src/cpp/ ../../external/incremental/graphics/native/platform/cpp ../../external/subset/arkoala-arkts/framework/native/src/generated ../../external/libarkts/native/src", | ||
need to think carefully about relative paths, migration to repo sync is planned to be initialized soon and we must not forget about all of this ![]() ![]()
![]() ![]() | |||
| 9 | + "patch_path": "./tools/clang-format/patches/clang-format.patch" | ||
| 10 | + }, | ||
| 11 | + "scripts": { | ||
| 12 | + "check-format": "bash ./check-format.sh ${DIR_PATH}", | ||
| 13 | + "apply-format": "bash ./apply-correct-format.sh ${DIR_PATH}", | ||
| 14 | + "check-format:external": "DIR_PATH=$npm_package_config_sig_path npm run check-format", | ||
| 15 | + "apply-format:external": "DIR_PATH=$npm_package_config_sig_path npm run apply-format", | ||
| 16 | + "apply-patch": "cd ../../ && git apply --stat --apply --unsafe-paths --verbose $npm_package_config_patch_path" | ||
| 17 | + } | ||
| 18 | +} | ||


Bash script is not really "cross-platform" solution. Maybe one day we could think about rewrite this script to something more windows-friendly.