-
Notifications
You must be signed in to change notification settings - Fork 10
/
build_all
executable file
·124 lines (105 loc) · 3.34 KB
/
build_all
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
#!/usr/bin/env bash
set -x -o nounset -o pipefail -o errexit
# Source directories
TOP_LEVEL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
BUILD_SYSTEM_DIR="${TOP_LEVEL_DIR}/Buildsystem"
SRC_DIR="${TOP_LEVEL_DIR}/src"
SUBMODULES_DIR="${TOP_LEVEL_DIR}/Submodules"
PYINSTALLER_DIR="${SUBMODULES_DIR}/Pyinstaller"
# Common files
VERSION_SCRIPT="${SRC_DIR}/Common/Version.py"
# Buildsystem files
CREATE_VERSION_FILE_SCRIPT="${BUILD_SYSTEM_DIR}/CreateVersionFile.py"
CREATE_RELEASE_VERSION_FILE_SCRIPT="${BUILD_SYSTEM_DIR}/CreateReleaseVersionFile.py"
REQUIREMENTS_TXT="${BUILD_SYSTEM_DIR}/requirements.txt"
SPEC_FILE="${BUILD_SYSTEM_DIR}/BedLeveler5000.spec"
# Generated directories
BUILD_DIR="${TOP_LEVEL_DIR}/Build"
INSTALL_DIR="${TOP_LEVEL_DIR}/Install"
INTERNAL_DIR="${INSTALL_DIR}/BedLeveler5000/_internal"
BUILD_VENV="${BUILD_DIR}/build_venv"
GIT_HASH_FILE="${BUILD_DIR}/GIT_HASH"
# Setup PYTHONPATH
export PYTHONPATH="${SRC_DIR}":"${SUBMODULES_DIR}"
KERNEL_NAME="$(uname -s)"
case "${KERNEL_NAME}" in
M*) PYTHON_EXE=python
ACTIVATE_PATH="${BUILD_VENV}/Scripts/activate"
WINDOWS_SPECIFIC=true
;;
*) PYTHON_EXE=python3
ACTIVATE_PATH="${BUILD_VENV}/bin/activate"
WINDOWS_SPECIFIC=false
esac
usage() {
printf "$0 [options]...\n\n"
printf "Build the Bed Leveler 5000 software suite\n\n"
printf "options:\n"
printf " -h, --help show this message and exit\n"
printf " -t [TAG], --tag [TAG] use tag\n"
exit 0
}
TAG=""
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
;;
-t|--tag)
TAG="$2"
shift
shift
;;
-*|--*)
error "Unknown option ($1)"
;;
*)
error "Unexpected argument ($1)"
;;
esac
done
rm -rf "${BUILD_DIR}"
rm -rf "${INSTALL_DIR}"
# Create BUILD_DIR
mkdir -p "${BUILD_DIR}"
# Create a clean venv
${PYTHON_EXE} -m venv "${BUILD_VENV}"
source "${ACTIVATE_PATH}"
${PYTHON_EXE} -m pip install -r "${REQUIREMENTS_TXT}"
# Static analysis
pylint --rcfile .pylintrc --errors-only src
# Run unit tests
pytest src/Printers/Marlin2/Commands/Tests
pytest src/Widgets/BedLeveler5000/Tests
# Ensure pip cache is empty
pip cache purge
# Build and install Pyinstaller
mkdir -p "${BUILD_DIR}/Pyinstaller"
cp "${PYINSTALLER_DIR}/setup.cfg" "${BUILD_DIR}/Pyinstaller"
cp "${PYINSTALLER_DIR}/setup.py" "${BUILD_DIR}/Pyinstaller"
cp -r "${PYINSTALLER_DIR}/bootloader" "${BUILD_DIR}/Pyinstaller"
cp -r "${PYINSTALLER_DIR}/PyInstaller" "${BUILD_DIR}/Pyinstaller"
cp -r "${PYINSTALLER_DIR}/scripts" "${BUILD_DIR}/Pyinstaller"
(
cd "${BUILD_DIR}/Pyinstaller/bootloader"
${PYTHON_EXE} ./waf distclean all
cd ..
pip install .
)
if [ ${WINDOWS_SPECIFIC} = true ]; then
# Create version files
for FILE in "BedLeveler5000.py" \
"PrinterInfoWizard.py" \
"InspectorG-Code.py" \
"PrinterTester.py"
do
"${PYTHON_EXE}" "${CREATE_VERSION_FILE_SCRIPT}" "${SRC_DIR}/${FILE}" "${BUILD_DIR}" ${TAG:+--tag "${TAG}"}
done
fi
# Create GIT_VERSION file
${PYTHON_EXE} "${VERSION_SCRIPT}" --git-hash > "${GIT_HASH_FILE}"
pyinstaller "${SPEC_FILE}" --workpath="${BUILD_DIR}" --distpath="${INSTALL_DIR}"
# Create RELEASE_VERSION file if a tag was specified
if [ ! -z "${TAG}" ]; then
${PYTHON_EXE} "${CREATE_RELEASE_VERSION_FILE_SCRIPT}" "${TAG}" "${INTERNAL_DIR}"
fi