forked from google/deepvariant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_release_binaries.sh
executable file
·154 lines (135 loc) · 6.15 KB
/
build_release_binaries.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
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
148
149
150
151
152
153
154
#!/bin/bash
# Copyright 2017 Google LLC.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Build release binaries using our standard compiler flags.
# Note we use the lowest common denominator compiler optimization options (For
# Google Cloud Engine chipsets lowest possible is Sandy Bridge).
# NOLINT
source settings.sh
set -e
# Bazel's --build_python_zip replaces our carefully engineered symbolic links
# with copies. This function puts the symbolic links back.
function fix_zip_file {
orig_zip_file=$1
# Step 1: Copy the zip file to a temporary place.
TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXXX)
# The .zip version of the binary doesn't have the header that makes it
# self-executable. We use that version because otherwise unzip would
# complain and raise an error code.
cp "${orig_zip_file}.zip" "${TMPDIR}"
# Step 2: Unzip it.
pushd "${TMPDIR}" > /dev/null
BN=$(basename "${orig_zip_file}")
unzip -qq "${BN}.zip"
# Step 3: Restore the symbolic links.
find "runfiles/com_google_deepvariant" -name '*.so' -exec ln --force -s --relative "runfiles/com_google_protobuf/python/google/protobuf/pyext/_message.so" {} \;
# Step 4: Fix the __main__.py's use of zipfile, which can't handle
# symbolic links. Replace it with an invocation of unzip, which can.
# The lines we replace are
# with zipfile.ZipFile(zip_path) as zf:
# for info in zf.infolist():
# zf.extract(info, dest_dir)
# # UNC-prefixed paths must be absolute/normalized. See
sed -i 's/ with zipfile.ZipFile(zip_path) as zf:/ if True:/' __main__.py
sed -i 's/ for info in zf.infolist():/ if True:/' __main__.py
sed -i 's/ zf.extract(info, dest_dir)/ os.system("unzip -qq " + zip_path + " -d " + dest_dir)/' __main__.py
sed -i 's/ # UNC-prefixed paths must be absolute\/normalized. See/ return/' __main__.py
# Step 5: Zip it back up, with zip --symbolic
rm -f "${BN}.zip"
ZIP_OUT="/tmp/${BN}.zip"
rm -f "${ZIP_OUT}"
zip -q --symlinks -r "${ZIP_OUT}" *
# Step 6: Make the zip file self-executable
SELF_ZIP="/tmp/${BN}"
# If the Python interpreter discovers it is being run from part of a zip
# file, it will uncompress and run the __main__.py. This is the trick that
# bazel uses to make a self-executable zip, see for example
# https://github.com/bazelbuild/bazel/blob/558b717e906156477b1c6bd29d049a0fb8e18b27/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L193
echo '#!/usr/bin/env python3' | cat - "${ZIP_OUT}" > "${SELF_ZIP}"
# Step 7: Copy it back and make it executable.
popd > /dev/null
rm -f "${orig_zip_file}"
mv "${SELF_ZIP}" "${orig_zip_file}"
chmod +x "${orig_zip_file}"
# Step 8: DeepVariant also uses "${orig_zip_file}.zip" in many of its
# instructions, so make sure that we also copy that.
rm -f "${orig_zip_file}.zip"
mv "${ZIP_OUT}" "${orig_zip_file}.zip"
# No executable bit because the .zip version is not self-executing and
# must be invoked as
# python3 ${orig_zip_file}.zip
}
# shellcheck disable=SC2086
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
${DV_COPT_FLAGS} \
--build_python_zip \
:binaries
# shellcheck disable=SC2086
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
${DV_COPT_FLAGS} \
--build_python_zip \
//deepvariant/labeler:labeled_examples_to_vcf
# shellcheck disable=SC2086
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
${DV_COPT_FLAGS} \
--build_python_zip \
:binaries-deeptrio
# shellcheck disable=SC2086
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
--noshow_progress \
${DV_COPT_FLAGS} \
:licenses_zip
# Bazel understandably doesn't like it when its output files are edited, so
# make sure all the builds are done before we fix things.
# TODO: Replace this hand-made list with a find command.
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/train"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/call_variants"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/call_variants_slim"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/make_examples"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/make_examples_somatic"
fix_zip_file "bazel-out/k8-opt/bin/deeptrio/make_examples"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/postprocess_variants"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/vcf_stats_report"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/show_examples"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/runtime_by_region_vis"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/multisample_make_examples"
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/labeler/labeled_examples_to_vcf"