summaryrefslogtreecommitdiffstats
path: root/tools/valgrind/build-valgrind-for-chromium.sh
blob: 06b6ef6ce8acd9b024233c1c40ef72a6c3d2db8b (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
#!/bin/sh

# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Script to build valgrind for use with chromium
#
# Can also be used to just prepare patched source tarball with MAKE_TARBALL=yes
# or to just build from a patched source tarball with USE_TARBALL=yes.
# These are useful when configuring jailed buildbots which are not allowed to
# fetch valgrind source via svn.  Most users won't need those options.

# Checkout by date doesn't work unless you specify the friggin' timezone
VALGRIND_SVN_REV=10771
# And svn isn't smart enough to figure out what rev of the linked tree to get
VEX_SVN_REV=1913
# and TSAN may be out of sync, so you have to check that out by rev anyway
TSAN_SVN_REV=1111

THISDIR=$(dirname "${0}")
THISDIR=$(cd "${THISDIR}" && /bin/pwd)

case "x${1}" in
x|x/*) ;;
*)
  echo "Usage: sh build-valgrind-for-chromium.sh [prefix]"
  echo "Prefix is optional, but if present, must be the absolute path to where"
  echo "you want to install valgrind's bin, include, and lib directories."
  echo "Prefix defaults to /usr/local/valgrind-${VALGRIND_SVN_REV}, where"
  echo "${VALGRIND_SVN_REV} is the revision used when retrieving valgrind from svn."
  echo "Will use sudo to do the install if you don't own the parent of prefix."
  exit 1
  ;;
esac

set -x
set -e

if test "x${USE_TARBALL}" = "xyes" && test "x${MAKE_TARBALL}" = "xyes"
then
  echo Set only one of MAKE_TARBALL or USE_TARBALL to yes
  exit 1
fi

# Clean checkout our untar
rm -rf "valgrind-${VALGRIND_SVN_REV}"

if test "x${USE_TARBALL}" != "xyes"
then
  # Check out latest version that following patches known to apply against
  svn co -r "${VALGRIND_SVN_REV}" "svn://svn.valgrind.org/valgrind/trunk" "valgrind-${VALGRIND_SVN_REV}"

  cd "valgrind-${VALGRIND_SVN_REV}"

  # Make sure svn gets the right version of the external VEX repo, too
  svn update -r "${VEX_SVN_REV}" VEX/

  # Work around bug https://bugs.kde.org/show_bug.cgi?id=162848
  # "fork() not handled properly"
  patch -p0 < "${THISDIR}/fork.patch"

  # Add feature bug https://bugs.kde.org/show_bug.cgi?id=201170
  # "Want --show-possible option so I can ignore the bazillion possible leaks..."
  patch -p0 < "${THISDIR}/possible.patch"

  if [ "${INSTALL_TSAN}" = "yes" ]
  then
    # Add ThreadSanitier to the installation.
    # ThreadSanitizer is an experimental dynamic data race detector.
    # See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer
    svn checkout -r "${TSAN_SVN_REV}" http://data-race-test.googlecode.com/svn/trunk/tsan tsan
    mkdir tsan/{docs,tests}
    touch tsan/{docs,tests}/Makefile.am
    patch -p 0 < tsan/valgrind.patch
  fi

  sh autogen.sh
  cd ..
fi

if test "x${MAKE_TARBALL}" = "xyes"
then
  tar -czvf "valgrind-${VALGRIND_SVN_REV}.tgz" "valgrind-${VALGRIND_SVN_REV}"
fi

if test "x${USE_TARBALL}" = "xyes"
then
  tar -xzvf "valgrind-${VALGRIND_SVN_REV}.tgz"
fi

if test "x${MAKE_TARBALL}" != "xyes"
then
  cd "valgrind-${VALGRIND_SVN_REV}"

  OVERRIDE_LD_DIR="${THISDIR}/override_ld"
  if ld --version | grep gold
  then
    # build/install-build-deps leaves original ld around, try using that
    if test -x /usr/bin/ld.orig
    then
      echo "Using /usr/bin/ld.orig instead of gold to link valgrind"
      test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}"
      mkdir "${OVERRIDE_LD_DIR}"
      ln -s /usr/bin/ld.orig "${OVERRIDE_LD_DIR}/ld"
      PATH="${OVERRIDE_LD_DIR}:${PATH}"
    else
      echo "Cannot build valgrind with gold.  Please switch to normal /usr/bin/ld, rerun this script, then switch back to gold."
      exit 1
    fi
  fi

  # Desired parent directory for valgrind's bin, include, etc.
  PREFIX="${1:-/usr/local/valgrind-${VALGRIND_SVN_REV}}"
  parent_of_prefix=$(dirname "${PREFIX}")
  if test ! -d "${parent_of_prefix}"
  then
    echo "Directory ${parent_of_prefix} does not exist"
    exit 1
  fi

  ./configure --prefix="${PREFIX}"
  make -j4

  if ./vg-in-place true
  then
    echo built valgrind passes smoke test, good
  else
    echo built valgrind fails smoke test
    exit 1
  fi

  test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}"

  # Don't use sudo if we own the destination
  if test -w "${parent_of_prefix}"
  then
     make install
  else
     sudo make install
  fi
fi