Diff of /build_release_binaries.sh [000000] .. [5a4941]

Switch to unified view

a b/build_release_binaries.sh
1
#!/bin/bash
2
# Copyright 2017 Google LLC.
3
#
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions
6
# are met:
7
#
8
# 1. Redistributions of source code must retain the above copyright notice,
9
#    this list of conditions and the following disclaimer.
10
#
11
# 2. Redistributions in binary form must reproduce the above copyright
12
#    notice, this list of conditions and the following disclaimer in the
13
#    documentation and/or other materials provided with the distribution.
14
#
15
# 3. Neither the name of the copyright holder nor the names of its
16
#    contributors may be used to endorse or promote products derived from this
17
#    software without specific prior written permission.
18
#
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
30
31
#
32
# Build release binaries using our standard compiler flags.
33
# Note we use the lowest common denominator compiler optimization options (For
34
# Google Cloud Engine chipsets lowest possible is Sandy Bridge).
35
36
# NOLINT
37
source settings.sh
38
39
set -e
40
41
# Bazel's --build_python_zip replaces our carefully engineered symbolic links
42
# with copies.  This function puts the symbolic links back.
43
function fix_zip_file {
44
  orig_zip_file=$1
45
46
  # Step 1:  Copy the zip file to a temporary place.
47
  TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXXX)
48
  # The .zip version of the binary doesn't have the header that makes it
49
  # self-executable.  We use that version because otherwise unzip would
50
  # complain and raise an error code.
51
  cp "${orig_zip_file}.zip" "${TMPDIR}"
52
53
  # Step 2: Unzip it.
54
  pushd "${TMPDIR}" > /dev/null
55
  BN=$(basename "${orig_zip_file}")
56
  unzip -qq "${BN}.zip"
57
58
  # Step 3: Restore the symbolic links.
59
  find "runfiles/com_google_deepvariant" -name '*.so' ! -name 'examples_from_stream.so' -exec ln --force -s --relative "runfiles/com_google_protobuf/python/google/protobuf/pyext/_message.so" {} \;
60
61
  # Step 4: Fix the __main__.py's use of zipfile, which can't handle
62
  # symbolic links.  Replace it with an invocation of unzip, which can.
63
  # The lines we replace are
64
  # with zipfile.ZipFile(zip_path) as zf:
65
  #   for info in zf.infolist():
66
  #     zf.extract(info, dest_dir)
67
  #     # UNC-prefixed paths must be absolute/normalized. See
68
69
  sed -i 's/  with zipfile.ZipFile(zip_path) as zf:/  if True:/' __main__.py
70
  sed -i 's/  for info in zf.infolist():/  if True:/' __main__.py
71
  sed -i 's/  zf.extract(info, dest_dir)/  os.system("unzip -qq " + zip_path + " -d " + dest_dir)/' __main__.py
72
  sed -i 's/  # UNC-prefixed paths must be absolute\/normalized. See/  return/' __main__.py
73
74
  # Step 5: Zip it back up, with zip --symbolic
75
  rm -f "${BN}.zip"
76
  ZIP_OUT="/tmp/${BN}.zip"
77
  rm -f "${ZIP_OUT}"
78
  zip -q --symlinks -r "${ZIP_OUT}" *
79
80
  # Step 6: Make the zip file self-executable
81
  SELF_ZIP="/tmp/${BN}"
82
  # If the Python interpreter discovers it is being run from part of a zip
83
  # file, it will uncompress and run the __main__.py.  This is the trick that
84
  # bazel uses to make a self-executable zip, see for example
85
  # https://github.com/bazelbuild/bazel/blob/558b717e906156477b1c6bd29d049a0fb8e18b27/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L193
86
  echo '#!/usr/bin/env python3' | cat - "${ZIP_OUT}" > "${SELF_ZIP}"
87
88
  # Step 7: Copy it back and make it executable.
89
  popd > /dev/null
90
  rm -f "${orig_zip_file}"
91
  mv "${SELF_ZIP}" "${orig_zip_file}"
92
  chmod +x "${orig_zip_file}"
93
94
  # Step 8: DeepVariant also uses "${orig_zip_file}.zip" in many of its
95
  # instructions, so make sure that we also copy that.
96
  rm -f "${orig_zip_file}.zip"
97
  mv "${ZIP_OUT}" "${orig_zip_file}.zip"
98
  # No executable bit because the .zip version is not self-executing and
99
  # must be invoked as
100
  #   python3 ${orig_zip_file}.zip
101
}
102
103
# Building examples_from_stream.so C++ library. It cannot be built correctly
104
# with the default bazel setup, so we build it manually.
105
# examples_from_stream.so is used by call_variants target therefore it has to
106
# be built before :binaries.
107
TF_CFLAGS=( $(python3 -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
108
TF_LFLAGS=( $(python3 -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
109
110
# shellcheck disable=SC2068
111
g++ -std=c++14 -shared \
112
        deepvariant/stream_examples_kernel.cc  \
113
        deepvariant/stream_examples_ops.cc \
114
        -o deepvariant/examples_from_stream.so \
115
        -fPIC \
116
        -l:libtensorflow_framework.so.2  \
117
        -I. \
118
        ${TF_CFLAGS[@]} \
119
        ${TF_LFLAGS[@]} \
120
        -D_GLIBCXX_USE_CXX11_ABI=1 \
121
        --std=c++17 \
122
        -DEIGEN_MAX_ALIGN_BYTES=64 \
123
        -O2
124
125
# shellcheck disable=SC2086
126
bazel build -c opt \
127
  //deepvariant:fast_pipeline
128
129
# shellcheck disable=SC2086
130
bazel build -c opt \
131
  --output_filter=DONT_MATCH_ANYTHING \
132
  --noshow_loading_progress \
133
  --show_result=0 \
134
  ${DV_COPT_FLAGS} \
135
  --build_python_zip \
136
  :binaries
137
138
# shellcheck disable=SC2086
139
bazel build -c opt \
140
  --output_filter=DONT_MATCH_ANYTHING \
141
  --noshow_loading_progress \
142
  --show_result=0 \
143
  ${DV_COPT_FLAGS} \
144
  --build_python_zip \
145
  //deepvariant/labeler:labeled_examples_to_vcf
146
147
# shellcheck disable=SC2086
148
bazel build -c opt \
149
  --output_filter=DONT_MATCH_ANYTHING \
150
  --noshow_loading_progress \
151
  --show_result=0 \
152
  ${DV_COPT_FLAGS} \
153
  --build_python_zip \
154
  :binaries-deeptrio
155
156
# shellcheck disable=SC2086
157
bazel build  -c opt \
158
  --output_filter=DONT_MATCH_ANYTHING \
159
  --noshow_loading_progress \
160
  --show_result=0 \
161
  --noshow_progress \
162
  ${DV_COPT_FLAGS} \
163
  :licenses_zip
164
165
# Bazel understandably doesn't like it when its output files are edited, so
166
# make sure all the builds are done before we fix things.
167
168
# TODO: Replace this hand-made list with a find command.
169
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/train"
170
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/call_variants"
171
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/load_gbz_into_shared_memory"
172
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/make_examples"
173
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/make_examples_pangenome_aware_dv"
174
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/make_examples_somatic"
175
fix_zip_file "bazel-out/k8-opt/bin/deeptrio/make_examples"
176
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/postprocess_variants"
177
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/vcf_stats_report"
178
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/show_examples"
179
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/runtime_by_region_vis"
180
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/multisample_make_examples"
181
fix_zip_file "bazel-out/k8-opt/bin/deepvariant/labeler/labeled_examples_to_vcf"