Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
swiftmpistepsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
swiftmpistepsim
Commits
5ae4842f
Commit
5ae4842f
authored
5 years ago
by
Peter W. Draper
Browse files
Options
Downloads
Patches
Plain Diff
Add formatting script and support
parent
c1f30119
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.clang-format
+6
-0
6 additions, 0 deletions
.clang-format
format.sh
+80
-0
80 additions, 0 deletions
format.sh
with
86 additions
and
0 deletions
.clang-format
0 → 100644
+
6
−
0
View file @
5ae4842f
---
Language: Cpp
BasedOnStyle: Google
KeepEmptyLinesAtTheStartOfBlocks: true
PenaltyBreakAssignment: 2
...
This diff is collapsed.
Click to expand it.
format.sh
0 → 100755
+
80
−
0
View file @
5ae4842f
#!/bin/bash
# Clang format command, can be overridden using CLANG_FORMAT_CMD.
# We currrently use version 5.0 so any overrides should provide that.
clang
=
${
CLANG_FORMAT_CMD
:
=
"clang-format-5.0"
}
# Formatting command
cmd
=
"
$clang
-style=file
$(
git ls-files |
grep
'\.[ch]$'
)
"
# Test if `clang-format-5.0` works
command
-v
$clang
>
/dev/null
if
[[
$?
-ne
0
]]
then
echo
"ERROR: cannot find
$clang
"
exit
1
fi
# Print the help
function
show_help
{
echo
-e
"This script formats SWIFT according to Google style"
echo
-e
" -h, --help
\t
Show this help"
echo
-e
" -t, --test
\t
Test if SWIFT is well formatted"
}
# Parse arguments (based on https://stackoverflow.com/questions/192249)
TEST
=
0
while
[[
$#
-gt
0
]]
do
key
=
"
$1
"
case
$key
in
# print the help and exit
-h
|
--help
)
show_help
exit
;;
# check if the code is well formatted
-t
|
--test
)
TEST
=
1
shift
;;
# unknown option
*
)
echo
"Argument '
$1
' not implemented"
show_help
exit
;;
esac
done
# Run the required commands
if
[[
$TEST
-eq
1
]]
then
# Note trapping the exit status from both commands in the pipe. Also note
# do not use -q in grep as that closes the pipe on first match and we get
# a SIGPIPE error.
echo
"Testing if SWIFT is correctly formatted"
$cmd
-output-replacements-xml
|
grep
"<replacement "
>
/dev/null
status
=(
"
${
PIPESTATUS
[@]
}
"
)
# Trap if first command failed. Note 141 is SIGPIPE, that happens when no
# output
if
[[
${
status
[0]
}
-ne
0
]]
then
echo
"ERROR:
$clang
command failed"
exit
1
fi
# Check formatting
if
[[
${
status
[1]
}
-eq
0
]]
then
echo
"ERROR: needs formatting"
exit
1
else
echo
"...is correctly formatted"
fi
else
echo
"Formatting SWIFT"
$cmd
-i
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment