Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[Feature][Master] Clang-format tool to perform additional formatting …
Browse files Browse the repository at this point in the history
…and semantic checking of code. (#20433)

* Clang-format hook

* Added: workflow file

* tools/lint/clang_format_ci.sh was added

* Permision was set on +x

* Jenkins clang-format runner

* Update runtime_funciton.sh file

* Master last commit sha

* Set BASE_SHA in greetings

* GITHUB_BASE_REF and GITHUB_RUN_ID: set varaibles

* Runtime function, os_x_static_build stores configuration

* Greetings contains env variables

* Check env params

* White space between breackets

* Show all refs

* Correct refs to master

* End up if []

* Git clang format rat-excludes

* LICENCE file was modifed to exclude clang-format-13 file

* Greetings, update env

* Remove unnecessary condition

* Update LICENSE

* Fix licence checker

* Clang-format file update

* Error message is shifted

Co-authored-by: Sheng Zha <szha@users.noreply.github.com>
  • Loading branch information
mozga-intel and szha authored Oct 9, 2021
1 parent 7be60ca commit 4b73646
Show file tree
Hide file tree
Showing 9 changed files with 723 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
DerivePointerAlignment: false
SortIncludes: true
MaxEmptyLinesToKeep: 1
PointerAlignment: Left
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
SortIncludes: false
4 changes: 4 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
env:
GITHUB_PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_PR_RUN_ID: ${{ github.run_id }}
GITHUB_PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: |
Expand Down
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,10 @@
=======================================================================================

docs/python_docs/themes/mx-theme/mxtheme/static/webfonts/ (Copy of the License available at licenses/OFL1_1)

=======================================================================================
Apache-2.0 WITH LLVM-exception
=======================================================================================

tools/lint/git-clang-format-13

38 changes: 38 additions & 0 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ build_ubuntu_gpu_large_tensor() {

sanity_check() {
set -ex
sanity_clang
sanity_license
sanity_python
sanity_cpp
Expand All @@ -716,6 +717,43 @@ sanity_cpp() {
3rdparty/dmlc-core/scripts/lint.py mxnet cpp include src plugin cpp-package tests --exclude_path src/operator/contrib/ctc_include include/onednn
}

sanity_clang() {
set -ex
# .github/workgflows/greetings.yml passes BASE_SHA, GITHUB_RUN_ID, GITHUB_BASE_REF for pull requests.
BASE_SHA="${GITHUB_PR_BASE_SHA}"
GITHUB_RUN_ID="${GITHUB_PR_RUN_ID}"
GITHUB_BASE_REF="${GITHUB_PR_BASE_REF}"

if [ "${BASE_SHA}" == "" ]; then
BASE_SHA=`git show-ref --hash refs/remotes/origin/master`
if [ "${GITHUB_RUN_ID}" == "" ] || [ "${GITHUB_BASE_REF}" == "" ]; then
GITHUB_RUN_ID=`(git log --pretty=format:'%h' -n 1)`
GITHUB_BASE_REF="master"
fi
fi

git remote add "${GITHUB_RUN_ID}" https://github.com/apache/incubator-mxnet.git
git fetch "${GITHUB_RUN_ID}" "$GITHUB_BASE_REF"

tools/lint/clang_format_ci.sh "${BASE_SHA}"
GIT_DIFFERENCE=$(git diff)
if [[ -z $GIT_DIFFERENCE ]]; then
git remote remove "${GITHUB_RUN_ID}" # temporary remote is removed
exit 0
fi

echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "| clang-format failures found! Run: "
echo "| tool/lint/clang_format_ci.sh ${BASE_SHA} "
echo "| to fix this error. "
echo "| For more info, see: "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

echo "$GIT_DIFFERENCE"
git remote remove "${GITHUB_RUN_ID}" # temporary remote is removed
exit 1
}

sanity_python() {
set -ex
export DMLC_LOG_STACK_TRACE_DEPTH=100
Expand Down
3 changes: 3 additions & 0 deletions rat-excludes
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ DartConfiguration.tcl
.*\.egg-info
.*\.t

# SPDX-License-Identifier: git-clang-format-13
git-clang-format-13

# Files generated by Cython
core.cpp
symbol.cpp
Expand Down
22 changes: 22 additions & 0 deletions tools/git-pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#!/bin/bash
set -e

echo "Running pre-commit clang-format"
tools/lint/git-clang-format HEAD~ --force
3 changes: 3 additions & 0 deletions tools/license_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
'3rdparty/ps-lite',
'3rdparty/tvm',

# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
'tools/lint/git-clang-format-13',

# 3rdparty headerfiles under different licenses
'include/onednn',

Expand Down
20 changes: 20 additions & 0 deletions tools/lint/clang_format_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#!/bin/sh
set -eux
tools/lint/git-clang-format-13 --verbose "$1" --
Loading

0 comments on commit 4b73646

Please sign in to comment.