• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -e
2
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.
6
7SCRIPTDIR="$(dirname "$(readlink -f "$0")")"
8PACKAGE_NAME="chrome-remote-desktop"
9
10guess_filename() {
11  ARCH=$(dpkg-architecture | awk -F '=' '/DEB_BUILD_ARCH=/{print $2}')
12  VERSION_FULL=$(get_version_full)
13  echo ${PACKAGE_NAME}_${VERSION_FULL}_${ARCH}.deb
14}
15
16get_version_full() {
17  src_root=${src_root:-./../../../..}
18  remoting_version_path=$src_root/remoting/VERSION
19  chrome_version_path=$src_root/chrome/VERSION
20  version_helper=$src_root/chrome/tools/build/version.py
21
22  # TODO(lambroslambrou): Refactor to share the logic with remoting.gyp.
23  version_major=$($version_helper -f $chrome_version_path \
24                  -f $remoting_version_path -t "@MAJOR@")
25  version_minor=$($version_helper -f $remoting_version_path \
26                  -t "@REMOTING_PATCH@")
27  version_build=$($version_helper -f $chrome_version_path \
28                  -f $remoting_version_path -t "@BUILD@")
29  version_patch=$($version_helper -f $chrome_version_path \
30                  -f $remoting_version_path -t "@PATCH@")
31  version_full="$version_major.$version_minor.$version_build.$version_patch"
32  echo $version_full
33}
34
35usage() {
36  echo "usage: $(basename $0) [-hp] [-o path] [-s path]"
37  echo "-h     this help message"
38  echo "-p     just print the expected DEB filename that this will build."
39  echo "-s     path to the top of the src tree."
40  echo "-o     path to write the DEB file to."
41}
42
43while getopts ":s:o:ph" OPTNAME
44do
45  case $OPTNAME in
46    s )
47      src_root="$(readlink -f "$OPTARG")"
48      ;;
49    o )
50      OUTPUT_PATH="$(readlink -f "$OPTARG")"
51      ;;
52    p )
53      PRINTDEBNAME=1
54      ;;
55    h )
56      usage
57      exit 0
58      ;;
59    \: )
60      echo "'-$OPTARG' needs an argument."
61      usage
62      exit 1
63      ;;
64    * )
65      echo "invalid command-line option: $OPTARG"
66      usage
67      exit 1
68      ;;
69  esac
70done
71shift $(($OPTIND - 1))
72
73# This just prints the expected package filename, then exits. It's needed so the
74# gyp packaging target can track the output file, to know whether or not it
75# needs to be built/rebuilt.
76if [[ -n "$PRINTDEBNAME" ]]; then
77  guess_filename
78  exit 0
79fi
80
81# TODO: Make this all happen in a temp dir to keep intermediate files out of the
82# build tree?
83cd "$SCRIPTDIR"
84
85if [[ -z "$version_full" ]]; then
86  version_full=$(get_version_full)
87fi
88
89if [[ ! "$version_full" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
90  echo "Error: Invalid \$version_full value: $version_full" >&2
91  exit 1
92fi
93
94# Include revision information in changelog when building from a local
95# git-based checkout.
96merge_head="$(git merge-base HEAD origin/git-svn 2>/dev/null || true)"
97if [[ -n "$merge_head" ]]; then
98  revision="$(git svn find-rev "$merge_head" 2>/dev/null || true)"
99else
100  # Official builders still use svn-based builds.
101  revision="$(svn info . | awk '/^Revision: /{print $2}')"
102fi
103if [[ -n "$revision" ]]; then
104  revision_text="(r$revision)"
105fi
106
107echo "Building version $version_full $revision_text"
108
109# Create a fresh debian/changelog.
110export DEBEMAIL="The Chromium Authors <chromium-dev@chromium.org>"
111rm -f debian/changelog
112debchange --create \
113  --package "$PACKAGE_NAME" \
114  --newversion "$version_full" \
115  --force-distribution \
116  --distribution unstable \
117  "New Debian package $revision_text"
118
119# TODO(mmoss): This is a workaround for a problem where dpkg-shlibdeps was
120# resolving deps using some of our build output shlibs (i.e.
121# out/Release/lib.target/libfreetype.so.6), and was then failing with:
122#   dpkg-shlibdeps: error: no dependency information found for ...
123# It's not clear if we ever want to look in LD_LIBRARY_PATH to resolve deps,
124# but it seems that we don't currently, so this is the most expediant fix.
125SAVE_LDLP=$LD_LIBRARY_PATH
126unset LD_LIBRARY_PATH
127dpkg-buildpackage -b -us -uc
128LD_LIBRARY_PATH=$SAVE_LDLP
129
130if [[ "$OUTPUT_PATH" ]]; then
131  mv ../${PACKAGE_NAME}_*.deb "$OUTPUT_PATH"/
132  mv ../${PACKAGE_NAME}_*.changes "$OUTPUT_PATH"/
133fi
134