This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
forked from google/deepvariant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_release_binaries.sh
executable file
·124 lines (108 loc) · 4.97 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
#!/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/protobuf_archive/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
# zf = zipfile.ZipFile(GetWindowsPathWithUNCPrefix(os.path.dirname(__file__)))
# zf.extractall(GetWindowsPathWithUNCPrefix(temp_dir))
sed -i 's/ zf = zipfile\.ZipFile.*/ os.system("unzip -qq " + os.path.dirname(__file__) + " -d " + temp_dir)/' __main__.py
sed -i 's/ zf\.extractall.*//' __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 python' | 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
# python ${orig_zip_file}.zip
}
# shellcheck disable=SC2086
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
--noshow_progress \
${DV_COPT_FLAGS} \
--build_python_zip \
:binaries
bazel build -c opt \
--output_filter=DONT_MATCH_ANYTHING \
--noshow_loading_progress \
--show_result=0 \
--noshow_progress \
: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.
# redacted
fix_zip_file "bazel-bin/deepvariant/call_variants"
fix_zip_file "bazel-bin/deepvariant/make_examples"
fix_zip_file "bazel-bin/deepvariant/model_eval"
fix_zip_file "bazel-bin/deepvariant/model_train"
fix_zip_file "bazel-bin/deepvariant/postprocess_variants"
fix_zip_file "bazel-bin/deepvariant/vcf_stats_report"