Add init script

This commit is contained in:
John Zhao 2018-03-09 10:51:09 +08:00
parent 7f8de0b03c
commit f4245fd50f
6 changed files with 169 additions and 5 deletions

19
.clang-format Normal file
View File

@ -0,0 +1,19 @@
---
Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Right
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlignAfterOpenBracket: AlwaysBreak
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '.*'
Priority: 2
---
Language: Proto
BasedOnStyle: Google
...

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.DS_Store
/doc/output/
/get-pip.py

View File

@ -2,13 +2,18 @@ include CommonDefs.mk
.DEFAULT_GOAL := help
.PHONY: help apidoc
help:
@echo "Usage:"
@echo " make help show help message"
@echo " make apidoc make api doc"
@echo " make opendoc open api doc (html)"
@echo " make init init project"
@echo " make test build test and run"
@echo " make clean|cleanall clean generated or useless things"
.PHONY: help
# doc
apidoc:
@$(call echo,Make $@)
@ -22,6 +27,52 @@ opendoc: apidoc
[ -f "$$html" ] && sh ./scripts/open.sh $$html; \
done
.PHONY: apidoc opendoc
# init
init:
@$(call echo,Make $@)
@sh ./scripts/init.sh
.PHONY: init
# deps
submodules:
@git submodule update --init
third_party: submodules
@$(call echo,Make $@)
@$(call echo,Make glog,33)
@$(call cmake_build,./third_party/glog/_build)
.PHONY: submodules third_party
# test
test: submodules
@$(call echo,Make $@)
@$(call echo,Make gtest,33)
@$(call cmake_build,./tests/gtest/_build)
.PHONY: test
# clean
clean:
@$(call echo,Make $@)
@$(call rm,./tests/gtest/_build/)
@$(call rm,./third_party/glog/_build/)
cleanall: clean
@$(call rm,./doc/output/)
@$(FIND) . -type f -name ".DS_Store" -print0 | xargs -0 rm -f
.PHONY: clean cleanall
# others
host:
@$(call echo,Make $@)
@echo HOST_OS: $(HOST_OS)
@ -35,3 +86,5 @@ host:
@echo LDD: $(LDD)
@echo CMAKE: $(CMAKE)
@#$(FIND) . -name READ*
.PHONY: host

View File

@ -18,6 +18,10 @@ _detect() {
fi
}
_detect_cmd() {
[ -x "$(command -v $1)" ]
}
_detect_fn() {
[ `type -t $1`"" == "function" ]
}

View File

@ -21,6 +21,7 @@ COLOR_INFO="1;34" # Blue
COLOR_DONE="1;32" # Green
COLOR_ERROR="1;31" # Red
# action colors
COLOR_STRONG_NORMAL="35"
COLOR_INFO_NORMAL="34"
COLOR_DONE_NORMAL="32"
COLOR_ERROR_NORMAL="31"
@ -57,6 +58,10 @@ _echo_e() {
_echo_e_ "$1" "$COLOR_ERROR"
}
_echo_sn() {
_echo_ "$1" "$COLOR_STRONG_NORMAL"
}
_echo_in() {
_echo_ "$1" "$COLOR_INFO_NORMAL"
}

81
scripts/init.sh Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env sh
# _FORCE_INSRALL_=1
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(realpath "$BASE_DIR/..")
source "$BASE_DIR/common/echo.sh"
source "$BASE_DIR/common/detect.sh"
source "$BASE_DIR/common/host.sh"
_detect curl
_detect python
_install_deps() {
_cmd="$1"; shift; _deps_all=($@)
_echo "Install cmd: $_cmd"
_echo "Install deps: ${_deps_all[*]}"
if [ -n "${_FORCE_INSRALL_}" ]; then
_echo_d "$_cmd ${_deps_all[*]}"
$_cmd ${_deps_all[@]}
return
fi
_deps=()
for _dep in "${_deps_all[@]}"; do
_detect_cmd $_dep || _deps+=($_dep)
done
if [ ${#_deps[@]} -eq 0 ]; then
_echo_i "All deps already exist"
else
_echo_d "$_cmd ${_deps[*]} (not exists)"
$_cmd ${_deps[@]}
fi
}
## deps
_echo_s "Init deps"
if [ "$HOST_OS" = "Linux" ]; then
# detect apt-get
_detect apt-get
# apt-get install
_install_deps "sudo apt-get install" build-essential cmake git clang-format
# sudo
SUDO="sudo"
elif [ "$HOST_OS" = "Mac" ]; then
# detect brew
if ! _detect_cmd brew; then
_echo_sn "Install brew"
_detect ruby
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# brew install
_install_deps "brew install" cmake git clang-format
# link clang-format-diff (if not compatible with Python 3, fix it by yourself)
[ -f "/usr/local/bin/clang-format-diff" ] || \
ln -s /usr/local/share/clang/clang-format-diff.py /usr/local/bin/clang-format-diff
# elif [ "$HOST_OS" = "Win" ]; then
else # unexpected
_echo_e "Unknown host os :("
exit 1
fi
## pip
# detect pip
if ! _detect_cmd pip; then
_echo_sn "Install pip"
[ -f "get-pip.py" ] || curl -O https://bootstrap.pypa.io/get-pip.py
$SUDO python get-pip.py
fi
# pip install
_echo_d "pip install --upgrade autopep8 cpplint pylint requests"
$SUDO pip install --upgrade autopep8 cpplint pylint requests
## init
_echo_s "Init git hooks"
python "$ROOT_DIR/tools/linter/init-git-hooks.py"
exit 0