2
#==========================================================================
4
# Copyright Insight Software Consortium
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0.txt
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
18
#==========================================================================*/
21
die 'USAGE: SourceTarball.bash [(--tgz|--txz|--zip)...] \
22
[--verbose] [-v <version>] build_dir [<tag>|<commit>]'
30
echo "$@" 1>&2; exit 1
33
return_pipe_status() {
34
echo ${PIPESTATUS[@]} |grep -q -v "[1-9]"
38
git ls-tree --full-tree -r "$1" |
40
while read mode type obj path; do
42
*.md5) echo MD5/$(git cat-file blob $obj) ;;
43
*) die "Unknown ExternalData content link: $path" ;;
50
md5sum=$(md5sum "$1" | sed 's/ .*//') &&
51
if test "$md5sum" != "$2"; then
52
die "Object MD5/$2 is corrupt: $1"
57
algo="$1" ; hash="$2" ; path="$3"
58
mkdir -p $(dirname "$path") &&
59
if wget "https://www.itk.org/files/ExternalData/$algo/$hash" -O "$path.tmp$$" 1>&2; then
60
mv "$path.tmp$$" "$path"
61
elif wget "http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=$hash&algorithm=$algo" -O "$path.tmp$$" 1>&2; then
62
mv "$path.tmp$$" "$path"
69
index_data_objects() {
70
# Input lines have format <algo>/<hash>
71
while IFS=/ read algo hash; do
72
# Final path in source tarball
73
path=".ExternalData/$algo/$hash"
74
# Find the object file on disk
75
if test -f "$path"; then
76
file="$path" # available in place
77
elif test -f ~/"$path" ; then
78
file=~/"$path" # available in home dir
80
download_object "$algo" "$hash" "$path" &&
83
validate_$algo "$file" "$hash" &&
84
obj=$(git hash-object -t blob -w "$file") &&
85
echo "100644 blob $obj $path" ||
88
git update-index --index-info
92
index_additional_object() {
96
test -n "$2" && path=$2/$(basename $file)
98
obj=$(git hash-object -t blob -w "$file") &&
99
echo "100644 blob $obj $path" |
100
git update-index --index-info
107
# NOTE: this methods exports the GIT_ALTERNATE_OBJECT_DIRECTORIES variable to effect later processes
108
index_submodule_objects() {
110
SUBMODULE_LIST=$(git submodule foreach --quiet 'echo $(git rev-parse --git-dir)/objects')
111
export GIT_ALTERNATE_OBJECT_DIRECTORIES=$SUBMODULE_LIST
113
git submodule foreach --quiet 'git ls-tree --full-tree -r $sha1 | awk -v path=$path '"'"'{ print path, $1, $2, $3, path "/" $4 }'"'"'' |
114
while read path mode type object file; do
115
echo "$mode $type $object $file" ||
118
git update-index --index-info
122
load_data_objects() {
123
find_data_objects "$@" |
129
git ls-tree -r "$1" -- '.ExternalData' |
130
git update-index --index-info
135
out="$2.tar.gz" && tmp="$out.tmp$$" &&
136
if test -n "$3"; then prefix="$3"; else prefix="$2"; fi &&
137
git -c core.autocrlf=false archive $verbose --format=tar --prefix=$prefix/ $1 |
144
out="$2.tar.xz" && tmp="$out.tmp$$" &&
145
if test -n "$3"; then prefix="$3"; else prefix="$2"; fi &&
146
git -c core.autocrlf=false archive $verbose --format=tar --prefix=$prefix/ $1 |
153
out="$2.zip" && tmp="$out.tmp$$" &&
154
if test -n "$3"; then prefix="$3"; else prefix="$2"; fi &&
155
git -c core.autocrlf=true archive $verbose --format=zip --prefix=$prefix/ $1 > "$tmp" &&
160
#-----------------------------------------------------------------------------
168
# Parse command line options.
169
while test $# != 0; do
171
--tgz) formats="$formats tgz" ;;
172
--txz) formats="$formats txz" ;;
173
--zip) formats="$formats zip" ;;
174
--verbose) verbose=-v ;;
176
-v) shift; version="$1" ;;
178
*) { test -z "$build_dir" && build_dir="$1"; } ||
179
{ test -z "$commit" && commit="$1"; } ||
185
test -n "$commit" || commit=HEAD
186
test -n "$formats" || formats=tgz
188
test -n "$build_dir" ||
189
die "Missing required build_dir argument."
191
test -e "${build_dir}/SimpleITKConfig.cmake" ||
192
die "invalid build directory."
195
if ! git rev-parse --verify -q "$commit" >/dev/null ; then
196
die "'$commit' is not a valid commit"
198
if test -z "$version"; then
199
desc=$(git describe $commit) &&
200
if test "${desc:0:1}" != "v"; then
201
die "'git describe $commit' is '$desc'; use -v <version>"
204
echo "$commit is version $version"
207
# Create temporary git index to construct source tree
208
export GIT_INDEX_FILE="$(pwd)/tmp-$$-index" &&
209
trap "rm -f '$GIT_INDEX_FILE'" EXIT &&
215
info "Loading source tree from $commit..." &&
216
rm -f "$GIT_INDEX_FILE" &&
217
git read-tree -m -i $commit &&
218
git rm -rf -q --cached '.ExternalData' &&
219
index_additional_object "${build_dir}/sitkSourceVersionVars.cmake" "CMake" &&
222
tree=$(git write-tree) &&
223
info "Generating source archive(s)..." &&
224
for fmt in $formats; do
225
git_archive_$fmt $tree "SimpleITK-$version" || result=1
228
info "Loading data for $commit..." &&
229
rm -f "$GIT_INDEX_FILE" &&
230
load_data_objects $commit &&
231
load_data_files $commit &&
232
tree=$(git write-tree) &&
235
info "Generating data archive(s)..." &&
236
for fmt in $formats; do
237
git_archive_$fmt $tree "SimpleITKData-$version" "SimpleITK-$version" || result=1