blob: d3a88f71e99994f1287e2ded6e3a80f32f51487b [file] [log] [blame]
Fam Zheng6b560c72017-09-05 10:11:52 +08001#!/bin/bash
2#
3# Author: Fam Zheng <famz@redhat.com>
4#
5# Archive source tree, including submodules. This is created for test code to
6# export the source files, in order to be built in a different environment,
7# such as in a docker instance or VM.
8#
9# This code is licensed under the GPL version 2 or later. See
10# the COPYING file in the top-level directory.
11
12error() {
13 printf %s\\n "$*" >&2
14 exit 1
15}
16
17if test $# -lt 1; then
18 error "Usage: $0 <output tarball>"
19fi
20
Mao Zhongyi934821e2018-10-15 17:17:34 +080021tar_file=$(realpath "$1")
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010022list_file="${tar_file}.list"
23vroot_dir="${tar_file}.vroot"
Fam Zheng6b560c72017-09-05 10:11:52 +080024
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010025# We want a predictable list of submodules for builds, that is
26# independent of what the developer currently has initialized
27# in their checkout, because the build environment is completely
28# different to the host OS.
Alex Bennée1627a362019-01-08 11:51:53 +000029submodules="dtc ui/keycodemapdb tests/fp/berkeley-softfloat-3 tests/fp/berkeley-testfloat-3"
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010030
31trap "status=$?; rm -rf \"$list_file\" \"$vroot_dir\"; exit \$status" 0 1 2 3 15
32
33if git diff-index --quiet HEAD -- &>/dev/null
34then
35 HEAD=HEAD
36else
Mao Zhongyi934821e2018-10-15 17:17:34 +080037 HEAD=$(git stash create)
Fam Zheng6b560c72017-09-05 10:11:52 +080038fi
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010039git clone --shared . "$vroot_dir"
40test $? -ne 0 && error "failed to clone into '$vroot_dir'"
Philippe Mathieu-Daudéd3b44262019-01-24 02:00:23 +010041for sm in $submodules; do
42 if test -d "$sm/.git"
43 then
44 git clone --shared "$sm" "$vroot_dir/$sm"
45 test $? -ne 0 && error "failed to clone submodule $sm"
46 fi
47done
Fam Zheng6b560c72017-09-05 10:11:52 +080048
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010049cd "$vroot_dir"
50test $? -ne 0 && error "failed to change into '$vroot_dir'"
51
52git checkout $HEAD
53test $? -ne 0 && error "failed to checkout $HEAD revision"
54
55for sm in $submodules; do
56 git submodule update --init $sm
57 test $? -ne 0 && error "failed to init submodule $sm"
58done
Fam Zheng6b560c72017-09-05 10:11:52 +080059
60if test -n "$submodules"; then
61 {
62 git ls-files || error "git ls-files failed"
63 for sm in $submodules; do
64 (cd $sm; git ls-files) | sed "s:^:$sm/:"
65 if test "${PIPESTATUS[*]}" != "0 0"; then
66 error "git ls-files in submodule $sm failed"
67 fi
68 done
69 } | grep -x -v $(for sm in $submodules; do echo "-e $sm"; done) > "$list_file"
70else
71 git ls-files > "$list_file"
72fi
73
74if test $? -ne 0; then
75 error "failed to generate list file"
76fi
77
78tar -cf "$tar_file" -T "$list_file" || error "failed to create tar file"
79
80exit 0