Skip to content

Commit

Permalink
chore: use clang-format (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Jul 1, 2024
1 parent bea626c commit 069eec6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# uses the same styling as V8
BasedOnStyle: Google
DerivePointerAlignment: false
MaxEmptyLinesToKeep: 1
11 changes: 11 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# clang format doesn't work properly with * and **
NativeScript/include/*
NativeScript/include/*/*
NativeScript/include/*/*/*
NativeScript/include/*/*/*/*
NativeScript/include/*/*/*/*/*
NativeScript/ada/*
NativeScript/inspector/third_party/*
NativeScript/inspector/third_party/*/*
NativeScript/inspector/third_party/*/*/*
NativeScript/inspector/third_party/*/*/*/*
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged || echo "Linting failed, verify your clang-format installation"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ To start diving into the v8 iOS runtime make sure you have Xcode and [Homebrew](
# Install CMake
brew install cmake

# (Optional) Install clang-format to format the code
brew install clang-format

# To avoid errors, you might need to link cmake to: /usr/local/bin/cmake
# xcode doesn't read your profile during the build step, which causes it to ignore the PATH
sudo ln -s /usr/local/bin/cmake $(which cmake)
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"**/*"
],
"scripts": {
"prepare": "husky",
"apply-patches": "./apply_patches.sh",
"build-v8-source": "./build_v8_source.sh",
"build-v8-source-catalyst": "./build_v8_source_catalyst.sh",
Expand All @@ -34,6 +35,13 @@
"devDependencies": {
"conventional-changelog-cli": "^2.1.1",
"dayjs": "^1.11.7",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"semver": "^7.5.0"
},
"lint-staged": {
"{NativeScript,metadata-generator/src,TestFixtures}/**/*.{h,hpp,c,cpp,mm,m}": [
"clang-format -i"
]
}
}
4 changes: 2 additions & 2 deletions update_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -e

# If a parameter is passed to this script then replace the version in package.json by appending $PACKAGE_VERSION
if [ -n "$1" ]; then
sed -i.bak "s/\"version\"[[:space:]]*:[[:space:]]*\"\(.*\)\"[[:space:]]*,/\"version\": \"\1-$PACKAGE_VERSION\",/g" package.json && rm package.json.bak
jq ".version = \"$PACKAGE_VERSION\"" package.json > package.json.tmp && rm package.json && mv package.json.tmp package.json
fi

# Read the version from package.json and replace it inside the NativeScript-Prefix.pch precompiled header
FULL_VERSION=$(sed -nE "s/.*(\"version\"[[:space:]]*:[[:space:]]*\"(.+)\"[[:space:]]*,).*/\2/p" package.json)
FULL_VERSION=$(jq -r .version package.json)
sed -i.bak "s/#define[[:space:]]*NATIVESCRIPT_VERSION[[:space:]]*\"\(.*\)\"/#define NATIVESCRIPT_VERSION \"$FULL_VERSION\"/g" NativeScript/NativeScript-Prefix.pch && rm NativeScript/NativeScript-Prefix.pch.bak

0 comments on commit 069eec6

Please sign in to comment.