-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev
executable file
·147 lines (126 loc) · 2.94 KB
/
dev
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set +e
: '
Copyright (C) 2021 IBM Corporation
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.
Contributors:
* Rafael Sene <[email protected]>
'
DIR=$(basename "$PWD")
usage(){
echo "Usage: $0 [ build | tests | install [--user] | release | run | clean | rpm | -h or --help ]"
}
createVirtEnv(){
python3 -m venv $DIR
source $DIR/bin/activate
return $TRUE
}
destroyVirtEnv(){
deactivate
clean
return $TRUE
}
clean(){
rm -rf ./*egg*
rm -rf ./build
rm -rf ./dist
}
buildTests(){
createVirtEnv
python3 ./setup.py test
destroyVirtEnv
clean
return $TRUE
}
buildRun(){
createVirtEnv
python3 ./setup.py install
cpi -h
destroyVirtEnv
clean
return $TRUE
}
buildInstall(){
if [ -z "$1" ]; then
SUDO=sudo
SCOPE=
elif [ "$1" == "--user" ]; then
SUDO=
SCOPE=--user
fi
clean
python3 ./setup.py sdist
python3 ./setup.py check -m
$SUDO pip3 install $SCOPE --upgrade ./dist/*.tar.gz
return $TRUE
}
buildClean(){
clean
python3 ./setup.py clean --all
python3 ./setup.py build
return $TRUE
}
buildCleanAll(){
clean
return $TRUE
}
buildRelease(){
clean
python3 ./setup.py sdist
python3 ./setup.py check -m
return $TRUE
}
buildRPM(){
if ! type "rpmbuild" > /dev/null 2>&1; then
echo "Please, install rpm-build and try again"
exit 0
fi
clean
python3 ./setup.py bdist_rpm
return $TRUE
}
#read the inputs
if [[ $# != 1 && "$1" != install && $# > 2 ]]; then
usage
exit 1
fi
# overwrite timestamp in setup.py file
buildtime=$(date +%Y%m%d%H%M%S)
sed -i -e "s/timestamp/$buildtime/g" setup.py
tool=${PWD##*/}
if [[ "$1" == "build" ]]; then
buildClean
elif [[ "$1" == "tests" ]]; then
buildTests
elif [[ "$1" == "install" ]]; then
shift 1
buildInstall $*
elif [[ "$1" == "run" ]]; then
buildRun $tool
elif [[ "$1" == "clean" ]]; then
buildCleanAll
elif [[ "$1" == "release" ]]; then
buildRelease
elif [[ "$1" == "rpm" ]]; then
buildRPM
elif [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
usage
echo " * build: Build tarball."
echo " * tests: Run all the unit tests inside a virtual environment."
echo " * release: Build and create all the necessary packages to distribute the application."
echo " * run: Create a virtual environment where the application is then installed and executed."
echo " * clean: Remove build-related artifacts. Useful for integrity verification."
echo " * rpm: Create installable RPM package."
else
echo "Command \"$1\" not recognized."
usage
exit 1
fi