Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/local-build-package
blob: c6fb02955bcedecb68ecad91eb85defca62fd4a3 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/sh

# build one package to test if modifications are ok (before opening a pull
# request in https://github.com/archlinux32/packages)
# package is built directly on a i486/i686/pentium4 host without any chroots

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

# TODO: remove hard-coded package suffixes

# shellcheck disable=SC2016
usage() {
  >&2 echo ''
  >&2 echo 'test-build-package <repository> <package>: build package for testing'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -h|--help:   Show this help and exit.'
  >&2 echo '  -a|--arch "i486" | "i686" | "pentium4"'
  >&2 echo '    Build locally for this architecture.'
  >&2 echo '  -b|--bootstrap'
  >&2 echo '    Publishes signed package to the bootstrap directory.'
  >&2 echo '  -H|--host <user>@<host>: host and user for bootstrapping'
  >&2 echo '  -D|--dir <dir>: bootstrapping directory'
  >&2 echo '    $arch and $repo are attached to this path.'
  >&2 echo '  -p|--port <SSH port>: the SSH port for bootstrapping.'
  >&2 echo '  -n|--nocheck:'
  >&2 echo '    Normally execute all checks and do all tests.'
  >&2 echo '    This switches off check() and all integrity checks.'
  >&2 echo '  -t|--tmpdir <dir>:'
  >&2 echo '    Specify tmpdir instead of using a random one, usually with -N'
  >&2 echo '  -N|--nobuild:'
  >&2 echo '    Assume packages have already been built, just upload them.'
  >&2 echo '  --signkey:'
  >&2 echo '    Use explicit sign key instead of the one from the configuration.'
  >&2 echo '  -s|--straw $straw:'
  >&2 echo '               Use this straw instead of the preconfigured ones. -- May be'
  >&2 echo '               given multiple times to allow using multiple straws.'
  >&2 echo ''
  >&2 echo 'known straws (separated by and enclosed in ":", sets of straws separated by " "):'
  >&2 echo '  :with_build_support:'
  >&2 echo '    allow using [build-support]'
  [ -z "$1" ] && exit 1 || exit "$1"
}

eval set -- "$(
  getopt -o a:bhnNp:H:D:t:s: \
    --long arch \
    --long bootstrap \
    --long nocheck \
    --long nobuild \
    --long port \
    --long dir \
    --long host \
    --long tmpdir \
    --long signkey \
    --long straw \
    --long help \
    -n "$(basename "$0")" -- "$@" || \
  echo usage
)"

arch=$(uname -m)
bootstrap=false
nocheck=false
nobuild=false
bootstrap_port=22
bootstrap_host=''
bootstrap_dir=''
tmp_dir=$(mktemp -d "${work_dir}/tmp.XXXXXX")
signkey="${package_key}"
declare -A straws
while true
do
  case "$1" in
    -a|--arch)
      shift
      arch="$1"
    ;;
    -b|--bootstrap)
      bootstrap=true
    ;;
    -H|--host)
      shift
      bootstrap_host="$1"
    ;;
    -D|--dir)
      shift
      bootstrap_dir="$1"
    ;;
    -n|--nocheck)
      nocheck=true
    ;;
    -N|--nobuild)
      nobuild=true
    ;;
    -p|--port)
      shift
      bootstrap_port="$1"
    ;;
    -t|--tmpdir)
      shift
      tmp_dir="$1"
    ;;
    --signkey)
      shift
      signkey="$1"
    ;;
    -s|--straw)
      shift
      straws["$1"]=1
    ;;
    -h|--help)
      usage 0
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 2 ]; then
  >&2 echo 'Too few or too many arguments. Expecting exactly a repository and a package name of the package to test.'
  usage
fi

if [ "$arch" != "any" ] && [ "$arch" != "i486" ] && [ "$arch" != "i686" ] && [ "$arch" != "pentium4" ]; then
  >&2 echo "Illegal architecture '$arch', epxecting one of 'any', 'i486', 'i686' or 'pentium4'."
  usage
fi

if ${bootstrap}; then
  if [ -z "${bootstrap_host}" ]; then
    >&2 echo -- '-b option requires a bootstrapping host to be set with -H'
    usage
  fi
  if [ -z "${bootstrap_dir}" ]; then
    >&2 echo -- '-b option requires a bootstrapping directory to be set with -d'
    usage
  fi
fi

if ! ${nobuild}; then
  # Update git repositories (official packages, community packages and the repository of package customizations).
  for repo_name in ${repo_names}; do
    eval repo_path='"${repo_paths__'"${repo_name}"'}"'
    git -C "${repo_path}" pull
  done

  repository=$1
  package=$2
  case $repository in
    core)
      repo_path='../work/repos/packages'
      ;;
    extra)
      repo_path='../work/repos/packages'
      ;;
    community)
      repo_path='../work/repos/community'
      ;;
    *)
      >&2 echo 'Repository is either "core", "extra" or "community"'
      usage
  esac
  git_revision=$(git -C "${repo_path}" rev-parse HEAD)

  mod_git_revision=$(git -C "${repo_paths__archlinux32}" stash create)
  if [ -z "${mod_git_revision}" ]; then
    mod_git_revision=$(git -C "${repo_paths__archlinux32}" rev-parse HEAD)
  fi

  if [[ -z "${straws[:with_build_support:]}" ]]; then
    build_command="staging-${arch}-build"
  else
    build_command='staging-with-build-support-'"${arch}"'-build'
  fi  

  parameters="-r ${archbuild_chroots}"
  if ${nocheck}; then
    parameters='-- -- --nocheck'
  fi

  git_repo=$(find_repository_with_commit "${git_revision}")
  find_pkgbuilds "${package}" "${repository}" "${git_repo}" "${git_revision}" "${mod_git_revision}"

  extract_source_directory "${git_repo}" "${git_revision}" "${mod_git_revision}" "${tmp_dir}"

  rm -f \
    ./*"-${arch}.pkg.tar.xz" ./*"-${arch}.pkg.tar.xz.sig" \
    ./*"-${arch}.pkg.tar.zst" ./*"-${arch}.pkg.tar.zst.sig"

  cd "${tmp_dir}" || exit 1

  makepkg_parameters=''
  if ${nocheck}; then
     makepkg_parameters='--skippgpcheck'
  fi
  makepkg ${makepkg_parameters} --verifysource

  # shellcheck disable=SC2086
  "${build_command}" ${parameters}
else
  cd "${tmp_dir}" || exit 1
fi

if ${bootstrap}; then
  rm -f \
    ./*"-${arch}.pkg.tar.xz.sig" \
    ./*"-${arch}.pkg.tar.zst.sig"

  find . -maxdepth 1 -type f -name "*${arch}.pkg.tar.zst" \
    -execdir gpg --local-user="${signkey}" --detach-sign '{}' \;

  case "$repository" in
    core|extra)
      staging_repo="staging"
      ;;
    community)
      staging_repo="community-staging"
      ;;
    *)
      staging_repo="staging"
      ;;
  esac

  scp -P "${bootstrap_port}" -rC "${tmp_dir}/"*"-${arch}.pkg.tar.zst" "${tmp_dir}/"*"-${arch}.pkg.tar.zst.sig" "${bootstrap_host}:${bootstrap_dir}/${staging_repo}/."
  ssh -p "${bootstrap_port}" "${bootstrap_host}" bash -l -c "'cd ${bootstrap_dir}/${staging_repo} && repo-add -n bootstrap-${staging_repo}.db.tar.gz *-${arch}.pkg.tar.zst'"
fi

# do not delete build reports, why might actually to want to have a look for things
# like checksums, logfiles, etc.
#recursively_umount_and_rm "${tmp_dir}"