summaryrefslogtreecommitdiffstats
path: root/rtems-release-package
blob: 2df2faed5cd9549821b0e2a81853e2730157413b (plain) (blame)
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
#! /bin/sh
#
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2015,2016,2019 Chris Johns (chrisj@rtems.org)
# All rights reserved.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
#
# 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.
#
# 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.
#

set -e

#
# This script packages a package in a tar file.
#

#
# Defaults.
#
. ${release_top}/rtems-release-defaults

#
# Common package start.
#
title="RTEMS Release Package"
. ./rtems-release-package-start

#
# Work in a package specific directory in the release directory.
#
echo "git clone ${git_remote} ${git_local}"
git clone ${git_remote} ${git_local}

stamped_tar=${prefix}-unstamped

#
# Clone the repo and then check if there are any submodules.
#
# If there are submodules, exclude the ones we do not wish to package, eg the
# whole of the FreeBSD source tree. For the ones to package get the commit
# (treeish) for the branch we releasing and then create an archive. The
# submodule archives are merged into the main archive once we have collected
# them all.
#
#
cd ${git_local}
 echo "git fetch origin"
 git fetch origin
 # Map the branch name to a specific package and release branch name
 remote_branch=$(rtems_map_branch ${package} ${version})
 echo "] Package ${package} ${version}: ${remote_branch}"
 git_submodules=$(git submodule | awk '{print $2}')
 if [ -n "${git_submodules}" ]; then
  echo "] git submodules found ...."
  echo "git submodules init"
  git submodule init
  echo "git checkout ${remote_branch}"
  git checkout ${remote_branch}
  for s in ${git_submodules}
  do
   ok=$(echo ${git_submodules_excludes} | sed -e "s/.*${s}.*/no/g")
   if [ "${ok}" != "no" ]; then
    echo "git submodule update ${s}"
    git submodule update ${s}
    treeish=$(git ls-tree HEAD ${s} | awk '{print $3}')
    cd ${s}
     echo "git archive --format=tar --prefix=${prefix}/${s}/ ${treeish}"
     git archive --format=tar --prefix=${prefix}/${s}/ ${treeish} > \
 	                                  ../../${stamped_tar}-${s}.tar
     cd ..   # ${s}
   else
    echo "git submodule ${s} excluded"
   fi
  done
  echo "git checkout master"
  git checkout master
 fi
 echo "git archive --format=tar --prefix=${prefix}/ ${remote_branch}"
 git archive --format=tar --prefix=${prefix}/ ${remote_branch} > \
                                          ../${stamped_tar}.tar
 cd ..   # ${git_local}

if [ ! -f ${stamped_tar}.tar ]; then
 echo "error: git archive failed, no tar file"
 exit 1
fi
echo "tar xf ${stamped_tar}.tar"
tar xf ${stamped_tar}.tar
if [ -n "${git_submodules}" ]; then
 for s in ${git_submodules}
 do
   ok=$(echo ${git_submodules_excludes} | sed -e "s/.*${s}.*/no/g")
   if [ "${ok}" != "no" ]; then
    echo "tar xf ${stamped_tar}-${s}.tar"
    tar xf ${stamped_tar}-${s}.tar
   fi
 done
fi

cd ${prefix}
 echo "] Creating VERSION: ${release}"
 echo "[version]" > VERSION
 echo "revision = ${release}" >> VERSION
 cd .. # ${prefix}

#
# Run the worker script if provided. It can perform any package
# specific set up functions. This is done before we finally
# package the release.
#
if [ -n "${worker}" ]; then
 wk_name=$(basename ${worker})
 echo "] Worker: ${wk_name}"
 ${worker} ${package} ${version} ${revision} ${release_url} ${top}
fi

#
# The '..' is the release directory.
#
echo "tar cf - ${prefix}"
tar cf - ${prefix} | ${comp} > ../${prefix}.tar.${comp_ext}

echo "] Created: ${release}/${prefix}.tar.${comp_ext}"

#
# Comman package end.
#
. ${top}/rtems-release-package-end

exit 0