Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
b95bf86d
Commit
b95bf86d
authored
Aug 07, 2017
by
Christian Convey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds clang-format style check/enforcement scripts.
parent
e214f01d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
0 deletions
+131
-0
README.md
README.md
+13
-0
apply-code-format.sh
maint/apply-code-format.sh
+49
-0
check-code-format.sh
maint/check-code-format.sh
+69
-0
No files found.
README.md
View file @
b95bf86d
...
...
@@ -36,3 +36,16 @@ TBD
## External library requirements
TBD
# Maintaining `libngraph`
## Code formatting
All C/C++ source code in the
`libngraph`
repository, including the test code when practical,
should adhere to the project's source-code formatting guidelines.
The script
`maint/apply-code-format.sh`
enforces that formatting at the C/C++ syntactic level.
The script
`maint/check-code-format.sh`
verifies that the formatting rules are met by all C/C++
code (again, at the syntax level.) The script has an exit code of 0 when this all code meets
the standard, and non-zero otherwise. This script does _not_ modify the source code.
maint/apply-code-format.sh
0 → 100755
View file @
b95bf86d
#!/bin/bash
set
-e
set
-u
# Copyright 2017 Nervana Systems Inc.
# Licensed 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.
# NOTE: The results of `clang-format` depend _both_ of the following factors:
# - The `.clang-format` file, and
# - The particular version of the `clang-format` program being used.
#
# For this reason, this script specifies the exact version of clang-format to be used.
declare
CLANG_FORMAT_BASENAME
=
"clang-format-3.9"
declare
THIS_SCRIPT_DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
declare
CLANG_FORMAT_PROG
if
!
CLANG_FORMAT_PROG
=
"
$(
which
"
${
CLANG_FORMAT_BASENAME
}
"
)
"
;
then
echo
"Unable to find program
${
CLANG_FORMAT_BASENAME
}
"
>
&2
exit
1
fi
pushd
"
${
THIS_SCRIPT_DIR
}
/.."
declare
ROOT_SUBDIR
for
ROOT_SUBDIR
in
src
test
;
do
if
!
[[
-d
"
${
ROOT_SUBDIR
}
"
]]
;
then
echo
"In directory '
$(
pwd
)
', no subdirectory named '
${
ROOT_SUBDIR
}
' was found."
>
&2
exit
1
fi
echo
"About to format C/C++ code in directory tree '
$(
pwd
)
/
${
ROOT_SUBDIR
}
' ..."
find
"
${
ROOT_SUBDIR
}
"
-name
'*.cpp'
-or
-name
'*.hpp'
| xargs
"
${
CLANG_FORMAT_PROG
}
"
-i
-style
=
file
echo
"Done."
done
popd
maint/check-code-format.sh
0 → 100755
View file @
b95bf86d
#!/bin/bash
set
-e
set
-u
# Copyright 2017 Nervana Systems Inc.
# Licensed 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.
# NOTE: The results of `clang-format` depend _both_ of the following factors:
# - The `.clang-format` file, and
# - The particular version of the `clang-format` program being used.
#
# For this reason, this script specifies the exact version of clang-format to be used.
declare
CLANG_FORMAT_BASENAME
=
"clang-format-3.9"
declare
THIS_SCRIPT_DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
declare
CLANG_FORMAT_PROG
if
!
CLANG_FORMAT_PROG
=
"
$(
which
"
${
CLANG_FORMAT_BASENAME
}
"
)
"
;
then
echo
"Unable to find program
${
CLANG_FORMAT_BASENAME
}
"
>
&2
exit
1
fi
declare
-a
FAILED_FILES
=()
declare
NUM_FILES_CHECKED
=
0
pushd
"
${
THIS_SCRIPT_DIR
}
/.."
declare
ROOT_SUBDIR
for
ROOT_SUBDIR
in
src
test
;
do
if
!
[[
-d
"
${
ROOT_SUBDIR
}
"
]]
;
then
echo
"In directory '
$(
pwd
)
', no subdirectory named '
${
ROOT_SUBDIR
}
' was found."
>
&2
exit
1
fi
echo
"About to format C/C++ code in directory tree '
$(
pwd
)
/
${
ROOT_SUBDIR
}
' ..."
declare
SRC_FILE
for
SRC_FILE
in
$(
find
"
${
ROOT_SUBDIR
}
"
-name
'*.cpp'
-or
-name
'*.hpp'
)
;
do
if
"
${
CLANG_FORMAT_PROG
}
"
-style
=
file
-output-replacements-xml
"
${
SRC_FILE
}
"
|
grep
-c
"<replacement "
>
/dev/null
;
then
FAILED_FILES+
=(
"
${
SRC_FILE
}
"
)
fi
NUM_FILES_CHECKED
=
$((
NUM_FILES_CHECKED+1
))
done
done
popd
if
[[
${#
FAILED_FILES
[@]
}
-eq
0
]]
;
then
echo
"All
${
NUM_FILES_CHECKED
}
C/C++ files pass the code-format check."
exit
0
else
echo
"
${#
FAILED_FILES
[@]
}
of
${
NUM_FILES_CHECKED
}
source files failed the code-format check:"
declare
FAILED_SRC_FILE
for
FAILED_SRC_FILE
in
${
FAILED_FILES
[@]
}
;
do
echo
"
${
FAILED_SRC_FILE
}
"
done
exit
1
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment