forked from google-deepmind/launchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oss_build.sh
executable file
·110 lines (95 loc) · 3.3 KB
/
oss_build.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
#!/bin/bash
# Copyright 2020 DeepMind Technologies Limited. All rights reserved.
#
# 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.
# Designed to work with ./docker/build.dockerfile to build Launchpad.
# Exit if any process returns non-zero status.
set -e
set -o pipefail
cd "$(dirname "$0")"
# Flags
PYTHON_VERSIONS=3.9 # Options 3.7, 3.8, 3.9, 3.10
CLEAN=false # Set to true to run bazel clean.
OUTPUT_DIR=/tmp/launchpad/dist
INSTALL=true # Should the built package be installed.
PIP_PKG_EXTRA_ARGS="" # Extra args passed to `build_pip_package`.
while [[ $# -gt -0 ]]; do
key="$1"
case $key in
--release)
PIP_PKG_EXTRA_ARGS="${PIP_PKG_EXTRA_ARGS} --release" # Indicates this is a release build.
;;
--python)
PYTHON_VERSIONS="$2" # Python versions to build against.
shift
;;
--clean)
CLEAN="$2" # `true` to run bazel clean. False otherwise.
shift
;;
--install)
INSTALL="$2" # `true` to install built package. False otherwise.
shift
;;
--output_dir)
OUTPUT_DIR="$2"
shift
;;
*)
echo "Unknown flag: $key"
echo "Usage:"
echo "--release [Indicates this is a release build. Otherwise nightly.]"
echo "--python [3.7|3.8(default)|3.9]"
echo "--clean [true to run bazel clean]"
echo "--install [true to install built package]"
echo "--output_dir [location to copy .whl file.]"
exit 1
;;
esac
shift # past argument or value
done
for python_version in $PYTHON_VERSIONS; do
# Cleans the environment.
if [ "$CLEAN" = "true" ]; then
bazel clean
fi
if [ "$python_version" = "3.7" ]; then
ABI=cp37
elif [ "$python_version" = "3.8" ]; then
ABI=cp38
elif [ "$python_version" = "3.9" ]; then
ABI=cp39
elif [ "$python_version" = "3.10" ]; then
ABI=cp310
else
echo "Error unknown --python. Only [3.7|3.8|3.9|3.10]"
exit 1
fi
export PYTHON_BIN_PATH=`which python${python_version}`
export PYTHON_LIB_PATH=`${PYTHON_BIN_PATH} -c 'import site; print(site.getsitepackages()[0])'`
# Configures Bazel environment for selected Python version.
$PYTHON_BIN_PATH configure.py
# Build Launchpad and run all bazel Python tests. All other tests are executed
# later.
# bazel build -c opt --copt=-mavx --config=manylinux2014 --test_output=errors //...
bazel build -c opt --test_output=errors //... --verbose_failures --sandbox_debug --subcommands=pretty_print
# Builds Launchpad and creates the wheel package.
$(pwd)/launchpad/pip_package/build_pip_package.sh --dst $OUTPUT_DIR/fresh $PIP_PKG_EXTRA_ARGS
# Install built package.
if [ "$INSTALL" = "true" ]; then
$PYTHON_BIN_PATH -m pip install --upgrade $OUTPUT_DIR/fresh/* --force-reinstall
fi
chmod 666 $OUTPUT_DIR/fresh/*
mv $OUTPUT_DIR/fresh/* $OUTPUT_DIR/
rm -r $OUTPUT_DIR/fresh
done