Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / installer / linux / rpm / build.sh
blobf58799b89223afc981408246abd4b3060aecaacd
1 #!/bin/bash
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # TODO(mmoss) This currently only works with official builds, since non-official
8 # builds don't add the "${BUILDDIR}/installer/" files needed for packaging.
10 set -e
11 if [ "$VERBOSE" ]; then
12 set -x
14 set -u
16 gen_spec() {
17 rm -f "${SPEC}"
18 # Trunk packages need to install to a custom path so they don't conflict with
19 # release channel packages.
20 local PACKAGE_FILENAME="${PACKAGE}"
21 if [ "$CHANNEL" != "stable" ]; then
22 local INSTALLDIR="${INSTALLDIR}-${CHANNEL}"
23 PACKAGE_FILENAME="${PACKAGE}-${CHANNEL}"
24 local MENUNAME="${MENUNAME} (${CHANNEL})"
26 process_template "${SCRIPTDIR}/chrome.spec.template" "${SPEC}"
29 # Setup the installation directory hierachy in the package staging area.
30 prep_staging_rpm() {
31 prep_staging_common
32 install -m 755 -d "${STAGEDIR}/etc/cron.daily"
35 # Put the package contents in the staging area.
36 stage_install_rpm() {
37 # TODO(phajdan.jr): Deduplicate this and debian/build.sh .
38 # For now duplication is going to help us avoid merge conflicts
39 # as changes are frequently merged to older branches related to SxS effort.
40 if [ "$CHANNEL" != "stable" ]; then
41 # This would ideally be compiled into the app, but that's a bit too
42 # intrusive of a change for these limited use channels, so we'll just hack
43 # it into the wrapper script. The user can still override since it seems to
44 # work to specify --user-data-dir multiple times on the command line, with
45 # the last occurrence winning.
46 local SXS_USER_DATA_DIR="\${XDG_CONFIG_HOME:-\${HOME}/.config}/${PACKAGE}-${CHANNEL}"
47 local DEFAULT_FLAGS="--user-data-dir=\"${SXS_USER_DATA_DIR}\""
49 # Avoid file collisions between channels.
50 local PACKAGE="${PACKAGE}-${CHANNEL}"
51 local INSTALLDIR="${INSTALLDIR}-${CHANNEL}"
53 # Make it possible to distinguish between menu entries
54 # for different channels.
55 local MENUNAME="${MENUNAME} (${CHANNEL})"
57 prep_staging_rpm
58 stage_install_common
59 echo "Staging RPM install files in '${STAGEDIR}'..."
60 process_template "${BUILDDIR}/installer/common/rpmrepo.cron" \
61 "${STAGEDIR}/etc/cron.daily/${PACKAGE}"
62 chmod 755 "${STAGEDIR}/etc/cron.daily/${PACKAGE}"
65 # Actually generate the package file.
66 do_package() {
67 echo "Packaging ${ARCHITECTURE}..."
68 PROVIDES="${PACKAGE}"
69 local REPS="$REPLACES"
70 REPLACES=""
71 for rep in $REPS; do
72 if [ -z "$REPLACES" ]; then
73 REPLACES="$PACKAGE-$rep"
74 else
75 REPLACES="$REPLACES $PACKAGE-$rep"
77 done
79 # The symbols in libX11.so are not versioned, so when a newer version has new
80 # symbols like _XGetRequest, RPM's find-requires tool does not detect it, and
81 # there is no way to specify a libX11.so version number to prevent
82 # installation on affected distros like OpenSUSE 12.1 and Fedora 16.
83 # Thus there has to be distro-specific conflict here.
84 # TODO(thestig) Remove these in the future when other requirements prevent
85 # installation on affected distros.
86 ADDITIONAL_CONFLICTS="xorg-x11-libX11 < 7.6_1 libX11 < 1.4.99"
87 REPLACES="$REPLACES $ADDITIONAL_CONFLICTS"
89 # If we specify a dependecy of foo.so below, we would depend on both the
90 # 32 and 64-bit versions on a 64-bit machine. The current version of RPM
91 # we use is too old and doesn't provide %{_isa}, so we do this manually.
92 if [ "$ARCHITECTURE" = "x86_64" ] ; then
93 local EMPTY_VERSION="()"
94 local PKG_ARCH="(64bit)"
95 elif [ "$ARCHITECTURE" = "i386" ] ; then
96 local EMPTY_VERSION=""
97 local PKG_ARCH=""
100 # Use find-requires script to make sure the dependencies are complete
101 # (especially libc and libstdc++ versions).
102 DETECTED_DEPENDS="$(echo "${BUILDDIR}/chrome" | /usr/lib/rpm/find-requires)"
104 # Compare the expected dependency list to the generated list.
105 BAD_DIFF=0
106 diff "$SCRIPTDIR/expected_deps_$ARCHITECTURE" \
107 <(echo "${DETECTED_DEPENDS}") || BAD_DIFF=1
108 if [ $BAD_DIFF -ne 0 ] && [ -z "${IGNORE_DEPS_CHANGES:-}" ]; then
109 echo
110 echo "ERROR: Shared library dependencies changed!"
111 echo "If this is intentional, please update:"
112 echo "chrome/installer/linux/rpm/expected_deps_i386"
113 echo "chrome/installer/linux/rpm/expected_deps_x86_64"
114 echo
115 exit $BAD_DIFF
118 # libgdk_pixbuf is added in LSB 3.2 and no longer explicitly required.
119 # libcairo, libpangocairo, libasound are in LSB 4. and no longer explicitly
120 # required.
121 # xdg-utils is still optional in LSB 4.0.
122 # nss (bundled) is optional in LSB 4.0.
124 # We want to depend on the system SSL certs so wget can upload crash reports
125 # securely, but there's no common capability between the distros. Bugs filed:
126 # https://qa.mandriva.com/show_bug.cgi?id=55714
127 # https://bugzilla.redhat.com/show_bug.cgi?id=538158
128 # https://bugzilla.novell.com/show_bug.cgi?id=556248
130 # We want to depend on liberation-fonts as well, but there is no such package
131 # for Fedora. https://bugzilla.redhat.com/show_bug.cgi?id=1252564
132 DEPENDS="lsb >= 4.0, \
133 libcurl.so.4${EMPTY_VERSION}${PKG_ARCH}, \
134 libnss3.so(NSS_3.14.3)${PKG_ARCH}, \
135 wget, \
136 xdg-utils, \
137 zlib, \
138 $(echo "${DETECTED_DEPENDS}" | tr '\n' ',')"
139 gen_spec
141 # Create temporary rpmbuild dirs.
142 RPMBUILD_DIR=$(mktemp -d -t rpmbuild.XXXXXX) || exit 1
143 mkdir -p "$RPMBUILD_DIR/BUILD"
144 mkdir -p "$RPMBUILD_DIR/RPMS"
146 # '__os_install_post ${nil}' disables a bunch of automatic post-processing
147 # (brp-compress, etc.), which by default appears to only be enabled on 32-bit,
148 # and which doesn't gain us anything since we already explicitly do all the
149 # compression, symbol stripping, etc. that we want.
150 fakeroot rpmbuild -bb --target="$ARCHITECTURE" --rmspec \
151 --define "_topdir $RPMBUILD_DIR" \
152 --define "_binary_payload w9.xzdio" \
153 --define "__os_install_post %{nil}" \
154 "${SPEC}"
155 PKGNAME="${PACKAGE}-${CHANNEL}-${VERSION}-${PACKAGE_RELEASE}"
156 mv "$RPMBUILD_DIR/RPMS/$ARCHITECTURE/${PKGNAME}.${ARCHITECTURE}.rpm" \
157 "${OUTPUTDIR}"
158 # Make sure the package is world-readable, otherwise it causes problems when
159 # copied to share drive.
160 chmod a+r "${OUTPUTDIR}/${PKGNAME}.$ARCHITECTURE.rpm"
161 rm -rf "$RPMBUILD_DIR"
164 # Remove temporary files and unwanted packaging output.
165 cleanup() {
166 rm -rf "${STAGEDIR}"
167 rm -rf "${TMPFILEDIR}"
170 usage() {
171 echo "usage: $(basename $0) [-c channel] [-a target_arch] [-o 'dir']"
172 echo " [-b 'dir'] -d branding"
173 echo "-c channel the package channel (trunk, asan, unstable, beta, stable)"
174 echo "-a arch package architecture (ia32 or x64)"
175 echo "-o dir package output directory [${OUTPUTDIR}]"
176 echo "-b dir build input directory [${BUILDDIR}]"
177 echo "-d brand either chromium or google_chrome"
178 echo "-h this help message"
181 # Check that the channel name is one of the allowable ones.
182 verify_channel() {
183 case $CHANNEL in
184 stable )
185 CHANNEL=stable
186 # TODO(phajdan.jr): Remove REPLACES completely.
187 REPLACES="dummy"
189 unstable|dev|alpha )
190 CHANNEL=unstable
191 # TODO(phajdan.jr): Remove REPLACES completely.
192 REPLACES="dummy"
194 testing|beta )
195 CHANNEL=beta
196 # TODO(phajdan.jr): Remove REPLACES completely.
197 REPLACES="dummy"
199 trunk|asan )
200 # This is a special package, mostly for development testing, so don't make
201 # it replace any installed release packages.
202 # TODO(phajdan.jr): Remove REPLACES completely.
203 REPLACES="dummy"
204 # Setting this to empty will prevent it from updating any existing configs
205 # from release packages.
206 REPOCONFIG=""
209 echo
210 echo "ERROR: '$CHANNEL' is not a valid channel type."
211 echo
212 exit 1
214 esac
217 process_opts() {
218 while getopts ":o:b:c:a:d:h" OPTNAME
220 case $OPTNAME in
222 OUTPUTDIR=$(readlink -f "${OPTARG}")
223 mkdir -p "${OUTPUTDIR}"
226 BUILDDIR=$(readlink -f "${OPTARG}")
229 CHANNEL="$OPTARG"
230 verify_channel
233 TARGETARCH="$OPTARG"
236 BRANDING="$OPTARG"
239 usage
240 exit 0
242 \: )
243 echo "'-$OPTARG' needs an argument."
244 usage
245 exit 1
248 echo "invalid command-line option: $OPTARG"
249 usage
250 exit 1
252 esac
253 done
256 #=========
257 # MAIN
258 #=========
260 SCRIPTDIR=$(readlink -f "$(dirname "$0")")
261 OUTPUTDIR="${PWD}"
262 STAGEDIR=$(mktemp -d -t rpm.build.XXXXXX) || exit 1
263 TMPFILEDIR=$(mktemp -d -t rpm.tmp.XXXXXX) || exit 1
264 CHANNEL="trunk"
265 # Default target architecture to same as build host.
266 if [ "$(uname -m)" = "x86_64" ]; then
267 TARGETARCH="x64"
268 else
269 TARGETARCH="ia32"
271 SPEC="${TMPFILEDIR}/chrome.spec"
273 # call cleanup() on exit
274 trap cleanup 0
275 process_opts "$@"
276 BUILDDIR=${BUILDDIR:=$(readlink -f "${SCRIPTDIR}/../../../../out/Release")}
278 source ${BUILDDIR}/installer/common/installer.include
280 get_version_info
282 if [ "$BRANDING" = "google_chrome" ]; then
283 source "${BUILDDIR}/installer/common/google-chrome.info"
284 else
285 source "${BUILDDIR}/installer/common/chromium-browser.info"
287 eval $(sed -e "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/" \
288 "${BUILDDIR}/installer/theme/BRANDING")
290 REPOCONFIG="http://dl.google.com/linux/${PACKAGE#google-}/rpm/stable"
291 SSLREPOCONFIG="https://dl.google.com/linux/${PACKAGE#google-}/rpm/stable"
292 verify_channel
293 export USR_BIN_SYMLINK_NAME="${PACKAGE}-${CHANNEL}"
295 # Make everything happen in the OUTPUTDIR.
296 cd "${OUTPUTDIR}"
298 case "$TARGETARCH" in
299 ia32 )
300 export ARCHITECTURE="i386"
301 stage_install_rpm
303 x64 )
304 export ARCHITECTURE="x86_64"
305 stage_install_rpm
308 echo
309 echo "ERROR: Don't know how to build RPMs for '$TARGETARCH'."
310 echo
311 exit 1
313 esac
315 do_package