aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Kotucek <pavel.kotucek@pantheon.tech>2019-04-29 15:58:24 +0200
committerHongjun Ni <hongjun.ni@intel.com>2019-05-15 00:40:40 +0000
commit6f6ea23e7114520fe25245effd4120294841f3a2 (patch)
tree7de83ff92c0dc9df0cf39e397ea28c7997b9c215
parent28bb25aee9898b50468233e896aab018e68bf787 (diff)
Docker build improvements
Added small changes to create dev docker image. Fixed checkstyle. Change-Id: I0ea1a0bad114578903073526fa12b84702072e3a Signed-off-by: Pavel Kotucek <pavel.kotucek@pantheon.tech>
-rw-r--r--.clang-format38
-rw-r--r--Makefile6
-rw-r--r--scripts/Dockerfile (renamed from Dockerfile)11
-rwxr-xr-xscripts/checkstyle.sh (renamed from build-root/scripts/checkstyle.sh)33
-rwxr-xr-xscripts/docker.sh (renamed from build-root/scripts/docker.sh)16
-rwxr-xr-xscripts/fix-coding-style.el173
-rwxr-xr-xscripts/run_test.sh46
-rwxr-xr-xtest/run_test.sh77
8 files changed, 290 insertions, 110 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..977ed2d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,38 @@
+---
+AlignEscapedNewlinesLeft: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+AlwaysBreakBeforeMultilineStrings: false
+BreakBeforeBinaryOperators: false
+BreakBeforeTernaryOperators: true
+BinPackParameters: true
+BreakBeforeBraces: GNU
+ColumnLimit: 79
+IndentCaseLabels: false
+MaxEmptyLinesToKeep: 1
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 60
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 120
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerBindsToType: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: Always
+SpacesBeforeTrailingComments: 1
+SpacesInParentheses: false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterControlStatementKeyword: true
+Cpp11BracedListStyle: true
+Standard: Cpp11
+SortIncludes: false
+IndentWidth: 2
+TabWidth: 4
+UseTab: Never
+IndentFunctionDeclarationAfterType: false
+ContinuationIndentWidth: 4
+...
diff --git a/Makefile b/Makefile
index bd9ad05..28226a7 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,6 @@
export WS_ROOT=$(CURDIR)
export BR=$(WS_ROOT)/build-root
PLATFORM?=sweetcomb
-REBUILD_DOCKER_IMAGE?=no
##############
#OS Detection#
@@ -108,6 +107,7 @@ help:
@echo " docker-test - run test in docker enviroment"
@echo " clean - clean all build"
@echo " distclean - remove all build directory"
+ @echo " checkstyle - check coding style"
install-dep:
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
@@ -289,7 +289,7 @@ distclean:
@rm -rf $(BR)/build-gnmi
docker:
- @build-root/scripts/docker.sh $(REBUILD_DOCKER_IMAGE)
+ @scripts/docker.sh
docker-test:
- @test/run_test.sh
+ @scripts/run_test.sh \ No newline at end of file
diff --git a/Dockerfile b/scripts/Dockerfile
index 1354f5c..b07382c 100644
--- a/Dockerfile
+++ b/scripts/Dockerfile
@@ -5,7 +5,8 @@ FROM ubuntu:18.04
# Layer2: Install sweetcomb
#Layer 0
-RUN mkdir -p /opt/dev && apt-get update && apt-get install -y build-essential sudo
+RUN mkdir -p /opt/dev && apt-get update &&\
+ apt-get install -y build-essential sudo
COPY . /opt/dev
WORKDIR /opt/dev
RUN make install-dep && make install-dep-extra
@@ -13,15 +14,17 @@ RUN rm -rf /opt/dev/*
#Layer1
RUN apt-get install -y \
- #build utils
sudo curl \
- #test utils
inetutils-ping \
&& curl -s https://packagecloud.io/install/repositories/fdio/1904/script.deb.sh | sudo bash \
&& apt-get -y --force-yes install vpp libvppinfra* vpp-plugin-* vpp-dev
+RUN apt-get update; \
+ apt-get install -y clang-format python3-pip; \
+ pip3 install pexpect pyroute2 psutil;
+
#Layer2
COPY . /root/src/sweetcomb
WORKDIR /root/src/sweetcomb
-RUN make install-dep && make build-scvpp && make build-plugins
+RUN make install-dep && make build-scvpp && make build-plugins \ No newline at end of file
diff --git a/build-root/scripts/checkstyle.sh b/scripts/checkstyle.sh
index fb0cb96..6091725 100755
--- a/build-root/scripts/checkstyle.sh
+++ b/scripts/checkstyle.sh
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-SWEETCOMB_DIR=`dirname $0`/../../
+SWEETCOMB_DIR="./"
EXIT_CODE=0
FIX="0"
FULL="0"
@@ -21,8 +21,6 @@ CHECKSTYLED_FILES=""
UNCHECKSTYLED_FILES=""
# If the user provides --fix, then actually fix things
-# Note: this is meant for use outside of the CI Jobs, by users cleaning things up
-
while true; do
case ${1} in
--fix)
@@ -41,8 +39,8 @@ else
FILELIST=$((git diff HEAD~1.. --name-only; git ls-files -m ) | sort -u)
fi
-# Check to make sure we have indent. Exit if we don't with an error message, but
-# don't *fail*.
+# Check to make sure we have indent. Exit if we don't with an error message,
+# but don't *fail*.
command -v indent > /dev/null
if [ $? != 0 ]; then
echo "Cound not find required command \"indent\". Checkstyle aborted"
@@ -50,12 +48,12 @@ if [ $? != 0 ]; then
fi
indent --version
-# Check to make sure we have clang-format. Exit if we don't with an error message, but
-# don't *fail*.
+# Check to make sure we have clang-format. Exit if we don't with an error
+# message, but don't *fail*.
HAVE_CLANG_FORMAT=0
command -v clang-format > /dev/null
if [ $? != 0 ]; then
- echo "Could not find command \"clang-format\". Checking C++ files will cause abort"
+ echo "Could not find command \"clang-format\"."
else
clang-format --version
x=$(echo "" | clang-format 2>&1)
@@ -64,27 +62,25 @@ else
else
echo "Output produced while formatting empty file (expected empty string):"
echo "$x"
- echo "Could not find working \"clang-format\". Checking C++ files will cause abort"
+ echo "Could not find working \"clang-format\"."
fi
fi
-cd ${SWEETCOMB_DIR}
git status
for i in ${FILELIST}; do
- if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "extras/emacs/fix-coding-style.el" ]; then
- grep -q "fd.io coding-style-patch-verification: ON" ${i}
- if [ $? == 0 ]; then
+ if [ -f ${i} ] && [ ${i} != "scripts/checkstyle.sh" ] && [ ${i} != "scripts/fix-coding-style.el" ]; then
EXTENSION=`basename ${i} | sed 's/^\w\+.//'`
case ${EXTENSION} in
- hpp|cpp|cc|hh)
+ hpp|cpp|cc|hh|c|h)
CMD="clang-format"
if [ ${HAVE_CLANG_FORMAT} == 0 ]; then
- echo "C++ file detected. Abort. (missing clang-format)"
+ echo "C++ file detected. Abort, missing clang-format"
exit ${EXIT_CODE}
fi
;;
*)
CMD="indent"
+ continue
;;
esac
CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
@@ -128,9 +124,6 @@ for i in ${FILELIST}; do
if [ -f ${i}.out2 ]; then
rm ${i}.out2
fi
- else
- UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
- fi
else
UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
fi
@@ -144,7 +137,7 @@ else
echo "*******************************************************************"
echo "* SWEETCOMB CHECKSTYLE FAILED"
echo "* CONSULT FAILURE LOG ABOVE"
- echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue"
+ echo "* NOTE: Running 'scripts/checkstyle.sh --fix' *MAY* fix the issue"
echo "*******************************************************************"
fi
-exit ${EXIT_CODE}
+exit ${EXIT_CODE} \ No newline at end of file
diff --git a/build-root/scripts/docker.sh b/scripts/docker.sh
index dce238a..3d211e3 100755
--- a/build-root/scripts/docker.sh
+++ b/scripts/docker.sh
@@ -14,15 +14,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
IMAGE="sweetcomb_img"
CONTAINER="sweetcomb"
-# rebuild env if neccessary
echo "Remove previous container and image"
-docker rm ${CONTAINER} -f
-docker rmi ${IMAGE} -f
+FIND=`docker container ls -a | grep ${CONTAINER}`
+if [ -n "${FIND}" ]; then
+ docker stop ${CONTAINER}
+ docker rm ${CONTAINER} -f
+fi
+FIND=`docker images | grep ${IMAGE}`
+if [ -n "${FIND}" ]; then
+ docker rmi ${IMAGE} -f
+fi
echo "Rebuild image and start container"
-docker build -t ${IMAGE} .
-docker run -id --privileged --name ${CONTAINER} ${IMAGE} \ No newline at end of file
+docker build -t ${IMAGE} -f ./scripts/Dockerfile . \ No newline at end of file
diff --git a/scripts/fix-coding-style.el b/scripts/fix-coding-style.el
new file mode 100755
index 0000000..2eb1c9e
--- /dev/null
+++ b/scripts/fix-coding-style.el
@@ -0,0 +1,173 @@
+#!/usr/bin/emacs --script
+
+;;; Copyright (c) 2016 Cisco and/or its affiliates.
+;;; 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.
+
+;; Insert style boilerplate if it's not already there
+;;
+;; Breaking the string in half keeps emacs
+;; from trying to interpret the local variable
+;; settings e.g. when it reads the lisp source code
+
+(defun insert-style-boilerplate () (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (if (eq nil (search-forward "coding-style-patch-verification"
+ (point-max) t))
+ (let ((junk 0)) (goto-char (point-max))
+ (insert "
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Var" "iables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */")))))
+
+;; (cons xxx <list>) means insert xxx at the head of <list>
+;; Build a sorted list of *INDENT-OFF* lines, by searching
+;; backwards. The initial (setq indent-offset-list nil)
+;; results in (cdr <last-cell>) nil, which makes it a proper list
+
+(defun find-indent-offs () (interactive)
+ (save-excursion
+ (if (boundp 'indent-offset-list)
+ (makunbound 'indent-offset-list))
+ (setq indent-offset-list nil)
+ (goto-char (point-max))
+ (while (search-backward "*INDENT-OFF*" (point-min) t)
+ (move-beginning-of-line nil)
+ (setq indent-offset-list (cons (point) indent-offset-list))
+ (previous-line))))
+
+;; Insert indent-off ... indent-on brackets around
+;; a certain xxx_foreach macro, etc. which "indent"
+;; completely screws up. Doesn't handle nesting, of which there
+;; are few examples (fortunately).
+
+(defun fix-initializer (what) (interactive)
+ (find-indent-offs)
+ (save-excursion
+ (goto-char (point-min))
+ (while (search-forward-regexp what (point-max) t)
+ (move-beginning-of-line nil)
+ (previous-line)
+ (let ((index 0)(pointval 0))
+ (while (and (< pointval (point))(elt indent-offset-list index))
+ (setq pointval (elt indent-offset-list index))
+ (setq index (1+ index)))
+ (if (not (eq pointval (point)))
+ (let ((junk 0))
+ (next-line)
+ (open-line 1)
+ (c-indent-line-or-region)
+ (insert "/* *INDENT-OFF* */")
+ (search-forward "{")
+ (backward-char)
+ (forward-sexp)
+ (move-end-of-line nil)
+ (newline 1)
+ (c-indent-line-or-region)
+ (insert "/* *INDENT-ON* */")
+ (find-indent-offs))
+ (search-forward "*INDENT-ON*"))))))
+
+(defun fix-pool-foreach () (interactive)
+ (fix-initializer "pool_foreach *("))
+
+(defun fix-pool-foreach-index () (interactive)
+ (fix-initializer "pool_foreach_index *("))
+
+(defun fix-hash-foreach () (interactive)
+ (fix-initializer "hash_foreach *("))
+
+(defun fix-hash-foreach-pair () (interactive)
+ (fix-initializer "hash_foreach_pair *("))
+
+(defun fix-hash-foreach-mem () (interactive)
+ (fix-initializer "hash_foreach_mem *("))
+
+(defun fix-clib-fifo-foreach () (interactive)
+ (fix-initializer "clib_fifo_foreach *("))
+
+(defun fix-clib-bitmap-foreach () (interactive)
+ (fix-initializer "clib_bitmap_foreach *("))
+
+(defun fix-foreach-ip-interface-address () (interactive)
+ (fix-initializer "foreach_ip_interface_address *("))
+
+(defun fix-vlib-register-thread () (interactive)
+ (fix-initializer "VLIB_REGISTER_THREAD *("))
+
+(defun fix-vlib-cli-command () (interactive)
+ (fix-initializer "VLIB_CLI_COMMAND *("))
+
+(defun fix-vlib-register-node () (interactive)
+ (fix-initializer "VLIB_REGISTER_NODE *("))
+
+(defun fix-reply-macro2 () (interactive)
+ (fix-initializer "REPLY_MACRO2 *("))
+
+(defun fix-vnet-device-class () (interactive)
+ (fix-initializer "VNET_DEVICE_CLASS *("))
+
+(defun fix-vnet-hw-interface-class () (interactive)
+ (fix-initializer "VNET_HW_INTERFACE_CLASS *("))
+
+(defun fix-clib-packed () (interactive)
+ (fix-initializer "CLIB_PACKED *("))
+(defun fix-vl-api-packed () (interactive)
+ (fix-initializer "VL_API_PACKED *("))
+
+;; Driver routine which runs the set of functions
+;; defined above, as well as the bottom boilerplate function
+
+(defun fd-io-styleify () (interactive)
+ (fix-pool-foreach)
+ (fix-pool-foreach-index)
+ (fix-hash-foreach)
+ (fix-hash-foreach-pair)
+ (fix-hash-foreach-mem)
+ (fix-foreach-ip-interface-address)
+ (fix-clib-fifo-foreach)
+ (fix-clib-bitmap-foreach)
+ (fix-vlib-register-thread)
+ (fix-vlib-cli-command)
+ (fix-vlib-register-node)
+ (fix-reply-macro2)
+ (fix-vnet-device-class)
+ (fix-vnet-hw-interface-class)
+ (fix-clib-packed)
+ (fix-vl-api-packed)
+ (insert-style-boilerplate)
+ (if (boundp 'indent-offset-list)
+ (makunbound 'indent-offset-list)))
+
+;; When run as a script, this sexp
+;; walks the list of files supplied on the command line.
+;;
+;; (elt argv index) returns nil if you M-x eval-buffer
+;; or M-x load-file the file, so we won't accidentally
+;; evaluate (save-buffers-kill-emacs)...
+
+(let ((file-index 0))
+ (if (elt argv file-index)
+ (while (elt argv file-index)
+ (find-file (elt argv file-index))
+ (fd-io-styleify)
+ (message "Done %s..." (elt argv file-index))
+ (setq file-index (1+ file-index))))
+ (if (> file-index 0)
+ (let ((junk 0))
+ (message "Save and quit...")
+ (save-buffers-kill-emacs t))))
diff --git a/scripts/run_test.sh b/scripts/run_test.sh
new file mode 100755
index 0000000..ca6c6b6
--- /dev/null
+++ b/scripts/run_test.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# Copyright (c) 2019 PANTHEON.tech.
+#
+# 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.
+
+IMAGE="sweetcomb_img"
+CONTAINER="sweetcomb_test"
+
+FIND=`docker container ls -a | grep ${CONTAINER}`
+if [ -n "${FIND}" ]; then
+ echo "Remove previous test container"
+ docker stop ${CONTAINER} > /dev/null
+ docker rm ${CONTAINER} -f > /dev/null
+fi
+
+FIND=`docker images | grep ${IMAGE}`
+if [ -z "${FIND}" ]; then
+ ./scripts/docker.sh
+fi
+
+echo "Start container"
+docker run -id --privileged --name ${CONTAINER} ${IMAGE}
+docker cp . ${CONTAINER}:/root/src/sweetcomb
+docker exec -it ${CONTAINER} bash -c "
+ cd /root/src/sweetcomb &&
+ make build-scvpp &&
+ make build-plugins"
+if [ "$?" == 0 ]; then
+ echo "Run tests"
+ docker exec -it ${CONTAINER} bash -c "
+ echo -e \"0000\n0000\" | passwd
+ mkdir /var/log/vpp"
+fi
+
+docker exec -it ${CONTAINER} bash -c "/root/src/sweetcomb/test/run_test.py" \ No newline at end of file
diff --git a/test/run_test.sh b/test/run_test.sh
deleted file mode 100755
index 8df2f3a..0000000
--- a/test/run_test.sh
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2019 PANTHEON.tech.
-#
-# 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.
-
-
-IMAGE="sweetcomb_img"
-CONTAINER="sweetcomb_test"
-
-function build_enviroment {
- FIND=`docker images | grep ${IMAGE}`
-
- if [ -n "${FIND}" ]; then
- return
- fi
-
- docker build -t ${IMAGE} .
-}
-
-function create_container {
- docker run -id --privileged --name ${CONTAINER} \
- -v $(pwd)/../sweetcomb:/root/src/sweetcomb ${IMAGE}
-}
-
-function start_container {
- FIND=`docker container ls -a | grep ${CONTAINER}`
-
- if [ -z "${FIND}" ]; then
- create_container
- else
- FIND=`docker container ps | grep ${CONTAINER}`
- if [ -z "${FIND}" ]; then
- docker start ${CONTAINER}
- fi
- fi
-}
-
-function build_sweetcomb {
- docker exec -it ${CONTAINER} bash -c "apt-get install -y python3-pip && pip3 install pexpect && pip3 install pyroute2"
-}
-
-function main {
- build_enviroment
- start_container
- build_sweetcomb
-
- docker exec -it ${CONTAINER} bash -c "
-
- apt-get install -y python3-pip
-
- pip3 install pyroute2 pexpect psutil
-
- echo -e \"0000\n0000\" | passwd
- "
-
-
- docker exec -it ${CONTAINER} bash -c "/root/src/sweetcomb/test/run_test.py"
-
- echo "Wait 20s, then remove the container."
- sleep 20
-
- docker stop ${CONTAINER}
- docker container rm ${CONTAINER}
-}
-
-main $@