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

[Feature][Master] Clang-format tool to perform additional formatting and semantic checking of code. #20433

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
25e2a65
Clang-format hook
mozga-intel Jul 9, 2021
8130709
Added: workflow file
mozga-intel Jul 21, 2021
0f42f1e
tools/lint/clang_format_ci.sh was added
mozga-intel Jul 21, 2021
6889cb8
Permision was set on +x
mozga-intel Jul 21, 2021
4664143
Jenkins clang-format runner
mozga-intel Jul 23, 2021
9f8557a
Update runtime_funciton.sh file
mozga-intel Jul 23, 2021
b0861b5
Master last commit sha
mozga-intel Jul 27, 2021
8af334f
Set BASE_SHA in greetings
mozga-intel Jul 27, 2021
0b99629
GITHUB_BASE_REF and GITHUB_RUN_ID: set varaibles
mozga-intel Jul 27, 2021
6c0667a
Runtime function, os_x_static_build stores configuration
mozga-intel Jul 27, 2021
bcd39e2
Greetings contains env variables
mozga-intel Jul 27, 2021
ff89ed3
Check env params
mozga-intel Jul 27, 2021
e274014
White space between breackets
mozga-intel Jul 27, 2021
13a7f05
Show all refs
mozga-intel Jul 27, 2021
758b9ba
Correct refs to master
mozga-intel Jul 27, 2021
977447d
End up if []
mozga-intel Jul 27, 2021
a97a795
Git clang format rat-excludes
mozga-intel Jul 27, 2021
87d2d31
LICENCE file was modifed to exclude clang-format-13 file
mozga-intel Jul 29, 2021
3b06980
Greetings, update env
mozga-intel Jul 29, 2021
48d31c5
Remove unnecessary condition
mozga-intel Jul 29, 2021
dab49ba
Update LICENSE
szha Aug 2, 2021
2cd51cc
Merge branch 'master' into mozga-intel/auto_clang_format_checker_hook
mozga-intel Aug 2, 2021
13b9942
Merge remote-tracking branch 'origin/master' into mozga-intel/auto_cl…
mozga-intel Aug 13, 2021
3c6e531
Fix licence checker
mozga-intel Aug 13, 2021
cf14abf
Clang-format file update
mozga-intel Sep 13, 2021
054f98e
Error message is shifted
mozga-intel Sep 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -353,3 +353,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
mozga-intel marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -71,6 +71,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