forked from delphix/linux-pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpkg.sh
executable file
·113 lines (96 loc) · 3.19 KB
/
buildpkg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
#
# Copyright 2018, 2021 Delphix
#
# 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.
#
TOP="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "$TOP/lib/common.sh"
logmust check_running_system
logmust run_setup_if_needed
function usage() {
[[ $# != 0 ]] && echo "$(basename "$0"): $*"
echo "Usage: $(basename "$0") [-ch] [-g pkg_git_url]"
echo " [-b pkg_git_branch] [-r pkg_revision]"
echo " package"
echo ""
echo " This script builds a package based on its config.sh. If '-u'"
echo " is provided it will first attempt to merge the package with"
echo " upstream. If no options are provided it will fetch the package"
echo " source from the master branch of the url defined in config.sh"
echo " and then build it."
echo " Options:"
echo ""
echo " -g override default git url for the package."
echo " -b override default git branch for the package."
echo " -c also run package's checkstyle hook."
echo " -r override default revision for package."
echo " -h display this message and exit."
echo " -l use locally-built dependencies instead of s3 versions."
echo ""
exit 2
}
unset PARAM_PACKAGE_GIT_URL
unset PARAM_PACKAGE_GIT_BRANCH
unset PARAM_PACKAGE_REVISION
do_checkstyle=false
source="s3"
while getopts ':b:cg:hlr:' c; do
case "$c" in
g) export PARAM_PACKAGE_GIT_URL="$OPTARG" ;;
b) export PARAM_PACKAGE_GIT_BRANCH="$OPTARG" ;;
r) export PARAM_PACKAGE_REVISION="$OPTARG" ;;
c) do_checkstyle=true ;;
h) usage >&2 ;;
l) source="local" ;;
*) usage "illegal option -- $OPTARG" >&2 ;;
esac
done
shift $((OPTIND - 1))
[[ $# -lt 1 ]] && usage "package argument missing" >&2
[[ $# -gt 1 ]] && usage "too many arguments" >&2
PACKAGE=$1
logmust check_package_exists "$PACKAGE"
check_env DEFAULT_GIT_BRANCH
#
# DEFAULT_REVISION & DEFAULT_GIT_BRANCH will be set if called from buildlist.sh.
# If the script is called manually, we set it here.
#
DEFAULT_REVISION="${DEFAULT_REVISION:-$(default_revision)}"
echo ""
echo_bold "===================================================================="
echo_bold " PACKAGE $PACKAGE"
echo_bold "===================================================================="
echo ""
logmust load_package_config "$PACKAGE"
logmust create_workdir
logmust mkdir "$WORKDIR/artifacts"
logmust cd "$WORKDIR"
stage fetch
logmust cd "$WORKDIR"
stage fetch_dependencies $source
logmust cd "$WORKDIR"
stage prepare
if $do_checkstyle; then
logmust cd "$WORKDIR"
stage checkstyle
fi
logmust cd "$WORKDIR"
stage build
logmust cd "$WORKDIR"
stage store_build_info
logmust cd "$WORKDIR"
stage post_build_checks
echo_success "Package $PACKAGE has been built successfully."
echo "Build products are in $WORKDIR/artifacts"
echo ""