xref: /spdk/.githooks/pre-push (revision 3359bf34d682202107c227ea42ace1c600a04657)
1#!/bin/sh
2#  SPDX-License-Identifier: BSD-3-Clause
3#  All rights reserved.
4
5# Verify what is about to be pushed.  Called by "git
6# push" after it has checked the remote status, but before anything has been
7# pushed.  If this script exits with a non-zero status nothing will be pushed.
8#
9# This hook is called with the following parameters:
10#
11# $1 -- Name of the remote to which the push is being done
12# $2 -- URL to which the push is being done
13#
14# If pushing without using a named remote those arguments will be equal.
15
16#   <local ref> <local sha1> <remote ref> <remote sha1>
17#
18
19rc=0
20SYSTEM=`uname -s`
21
22# Redirect output to stderr.
23exec 1>&2
24
25if [ "$SYSTEM" = "FreeBSD" ]; then
26	MAKE="gmake MAKE=gmake -j $(sysctl -a | grep -E -i 'hw.ncpu' | awk '{print $2}')"
27	COMP="clang"
28else
29	MAKE="make -j $(nproc)"
30	COMP="gcc"
31fi
32
33echo "Running make with $COMP ..."
34echo "${MAKE} clean " > make.log
35$MAKE clean  >> make.log 2>&1
36
37echo "${MAKE} CONFIG_DEBUG=n CONFIG_WERROR=y " >> make.log
38$MAKE CONFIG_DEBUG=n CONFIG_WERROR=y  >> make.log 2>&1
39rc=$?
40if [ $rc -ne 0 ]; then
41	tail -20 make.log
42	echo ""
43	echo "ERROR make returned errors!"
44	echo "ERROR Fix the problem and use 'git commit' to update your changes."
45	echo "ERROR See `pwd`/make.log for more information."
46	echo ""
47	exit $rc
48fi
49
50echo "${MAKE} SKIP_DPDK_BUILD=1 clean " >> make.log
51$MAKE clean SKIP_DPDK_BUILD=1 >> make.log 2>&1
52echo "${MAKE} CONFIG_DEBUG=y CONFIG_WERROR=y SKIP_DPDK_BUILD=1 " >> make.log
53$MAKE CONFIG_DEBUG=y CONFIG_WERROR=y SKIP_DPDK_BUILD=1  >> make.log 2>&1
54rc=$?
55if [ $rc -ne 0 ]; then
56	tail -20 make.log
57	echo ""
58	echo "ERROR make returned errors!"
59	echo "ERROR Fix the problem and use 'git commit' to update your changes."
60	echo "ERROR See `pwd`/make.log for more information."
61	echo ""
62	exit $rc
63fi
64
65echo "Running unittest.sh ..."
66echo "./test/unit/unittest.sh" >> make.log
67"./test/unit/unittest.sh" >> make.log 2>&1
68rc=$?
69if [ $rc -ne 0 ]; then
70	tail -20 make.log
71	echo ""
72	echo "ERROR unittest returned errors!"
73	echo "ERROR Fix the problem and use 'git commit' to update your changes."
74	echo "ERROR See `pwd`/make.log for more information."
75	echo ""
76	exit $rc
77fi
78
79echo "$MAKE clean " >> make.log
80$MAKE clean  >> make.log 2>&1
81
82echo "Pushing to $1 $2"
83
84exit $rc
85