summaryrefslogtreecommitdiffstats
path: root/debian/autobake-deb.sh
blob: afe7181f5a54f972322d6cda461b7ca4c805b7ba (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
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
#
# Build MariaDB .deb packages for test and release at mariadb.org
#
# Purpose of this script:
# Always keep the actual packaging as up-to-date as possible following the latest
# Debian policy and targeting Debian Sid. Then case-by-case run in autobake-deb.sh
# tests for backwards compatibility and strip away parts on older builders or
# specific build environments.

# Exit immediately on any error
set -e

# On Buildbot, don't run the mysql-test-run test suite as part of build.
# It takes a lot of time, and we will do a better test anyway in
# Buildbot, running the test suite from installed .debs on a clean VM.
export DEB_BUILD_OPTIONS="nocheck $DEB_BUILD_OPTIONS"

# shellcheck source=/dev/null
source ./VERSION

# General CI optimizations to keep build output smaller
if [[ $GITLAB_CI ]]
then
  # On Gitlab the output log must stay under 4MB so make the
  # build less verbose
  sed '/Add support for verbose builds/,/^$/d' -i debian/rules
elif [ -d storage/columnstore/columnstore/debian ]
then
  # ColumnStore is explicitly disabled in the native Debian build. Enable it
  # now when build is triggered by autobake-deb.sh (MariaDB.org) and when the
  # build is not running on Gitlab-CI.
  sed '/-DPLUGIN_COLUMNSTORE=NO/d' -i debian/rules
  # Take the files and part of control from MCS directory
  if [ ! -f debian/mariadb-plugin-columnstore.install ]
  then
    cp -v storage/columnstore/columnstore/debian/mariadb-plugin-columnstore.* debian/
    echo >> debian/control
    sed "s/-10.6//" <storage/columnstore/columnstore/debian/control >> debian/control
  fi
fi

# Look up distro-version specific stuff
#
# Always keep the actual packaging as up-to-date as possible following the latest
# Debian policy and targeting Debian Sid. Then case-by-case run in autobake-deb.sh
# tests for backwards compatibility and strip away parts on older builders.

remove_rocksdb_tools()
{
  sed '/rocksdb-tools/d' -i debian/control
  sed '/sst_dump/d' -i debian/not-installed
  if ! grep -q sst_dump debian/mariadb-plugin-rocksdb.install
  then
    echo "usr/bin/sst_dump" >> debian/mariadb-plugin-rocksdb.install
  fi
}

add_lsb_base_depends()
{
  # Make sure one can run this multiple times remove
  # lines 'sysvinit-utils' and 'lsb-base'.
  sed -e '/sysvinit-utils/d' -e '/lsb-base/d' -i debian/control
  # Add back lsb-base before lsof
  sed -e 's#lsof #lsb-base (>= 3.0-10),\n         lsof #' -i debian/control
}

replace_uring_with_aio()
{
  sed 's/liburing-dev/libaio-dev/g' -i debian/control
  sed -e '/-DIGNORE_AIO_CHECK=ON/d' \
      -e '/-DWITH_URING=ON/d' -i debian/rules
}

disable_pmem()
{
  sed '/libpmem-dev/d' -i debian/control
  sed '/-DWITH_PMEM=ON/d' -i debian/rules
}

disable_libfmt()
{
  # 7.0+ required
  sed '/libfmt-dev/d' -i debian/control
}

architecture=$(dpkg-architecture -q DEB_BUILD_ARCH)

# Parse release name and number from Linux standard base release
# Example:
#   $ lsb_release -a
#   No LSB modules are available.
#   Distributor ID:	Debian
#   Description:	Debian GNU/Linux bookworm/sid
#   Release:	n/a
#   Codename:	n/a
LSBID="$(lsb_release -si  | tr '[:upper:]' '[:lower:]')"
LSBVERSION="$(lsb_release -sr | sed -e "s#\.##g")"
LSBNAME="$(lsb_release -sc)"

# If 'n/a', assume 'sid'
if [ "${LSBVERSION}" == "n/a" ] || [ "${LSBNAME}" == "n/a" ]
then
  LSBVERSION="sid"
  LSBNAME="sid"
fi

# If not known, use 'unknown' in .deb version identifier
if [ -z "${LSBID}" ]
then
  LSBID="unknown"
fi

case "${LSBNAME}"
in
  # Debian
  "buster")
    disable_libfmt
    replace_uring_with_aio
    if [ ! "$architecture" = amd64 ]
    then
      disable_pmem
    fi
    ;&
  "bullseye")
    add_lsb_base_depends
    ;&
  "bookworm")
    # mariadb-plugin-rocksdb in control is 4 arches covered by the distro rocksdb-tools
    # so no removal is necessary.
    if [[ ! "$architecture" =~ amd64|arm64|ppc64el ]]
    then
      disable_pmem
    fi
    if [[ ! "$architecture" =~ amd64|arm64|armel|armhf|i386|mips64el|mipsel|ppc64el|s390x ]]
    then
      replace_uring_with_aio
    fi
    ;&
  "trixie"|"sid")
    # The default packaging should always target Debian Sid, so in this case
    # there is intentionally no customizations whatsoever.
    ;;
  # Ubuntu
  "bionic")
    remove_rocksdb_tools
    [ "$architecture" != amd64 ] && disable_pmem
    ;&
  "focal")
    replace_uring_with_aio
    disable_libfmt
    ;&
  "jammy"|"kinetic")
    add_lsb_base_depends
    ;&
  "lunar"|"mantic")
    # mariadb-plugin-rocksdb s390x not supported by us (yet)
    # ubuntu doesn't support mips64el yet, so keep this just
    # in case something changes.
    if [[ ! "$architecture" =~ amd64|arm64|ppc64el|s390x ]]
    then
      remove_rocksdb_tools
    fi
    if [[ ! "$architecture" =~ amd64|arm64|ppc64el ]]
    then
      disable_pmem
    fi
    if [[ ! "$architecture" =~ amd64|arm64|armhf|ppc64el|s390x ]]
    then
      replace_uring_with_aio
    fi
    ;;
  *)
    echo "Error: Unknown release '$LSBNAME'" >&2
    exit 1
esac

if [ -n "${AUTOBAKE_PREP_CONTROL_RULES_ONLY:-}" ]
then
  exit 0
fi

# Adjust changelog, add new version
echo "Incrementing changelog and starting build scripts"

# Find major.minor version
UPSTREAM="${MYSQL_VERSION_MAJOR}.${MYSQL_VERSION_MINOR}.${MYSQL_VERSION_PATCH}${MYSQL_VERSION_EXTRA}"
PATCHLEVEL="+maria"
LOGSTRING="MariaDB build"
EPOCH="1:"
VERSION="${EPOCH}${UPSTREAM}${PATCHLEVEL}~${LSBID:0:3}${LSBVERSION}"

dch -b -D "${LSBNAME}" -v "${VERSION}" "Automatic build with ${LOGSTRING}." --controlmaint

echo "Creating package version ${VERSION} ... "

BUILDPACKAGE_DPKGCMD=()

# Fakeroot test
if fakeroot true; then
  BUILDPACKAGE_DPKGCMD+=( "fakeroot" "--" )
fi

# Use eatmydata is available to build faster with less I/O, skipping fsync()
# during the entire build process (safe because a build can always be restarted)
if command -v eatmydata > /dev/null
then
  BUILDPACKAGE_DPKGCMD+=("eatmydata")
fi

BUILDPACKAGE_DPKGCMD+=("dpkg-buildpackage")

# Using dpkg-buildpackage args
# -us Allow unsigned sources
# -uc Allow unsigned changes
# -I  Tar ignore
BUILDPACKAGE_DPKGCMD+=(-us -uc -I)

# There can be also extra flags that are appended to args
if [ -n "$BUILDPACKAGE_FLAGS" ]
then
  read -ra BUILDPACKAGE_TMP_ARGS <<< "$BUILDPACKAGE_FLAGS"
  BUILDPACKAGE_DPKGCMD+=( "${BUILDPACKAGE_TMP_ARGS[@]}" )
fi

# Build the package
# Pass -I so that .git and other unnecessary temporary and source control files
# will be ignored by dpkg-source when creating the tar.gz source package.
"${BUILDPACKAGE_DPKGCMD[@]}"

# If the step above fails due to missing dependencies, you can manually run
#   sudo mk-build-deps debian/control -r -i

# Don't log package contents on Gitlab-CI to save time and log size
if [[ ! $GITLAB_CI ]]
then
  echo "List package contents ..."
  cd ..
  for package in *.deb
  do
    echo "$package" | cut -d '_' -f 1
    # shellcheck disable=SC2034
    dpkg-deb -c "$package" | while IFS=" " read -r col1 col2 col3 col4 col5 col6 col7 col8
    do
        echo "$col1 $col2 $col6 $col7 $col8" | sort -k 3
    done
    echo "------------------------------------------------"
  done
fi

echo "Build complete"