Chromium Code Reviews
  | 
| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 #!/bin/bash | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 # Downloads, builds (with instrumentation) and installs shared libraries. | |
| 7 | |
| 8 # Colored print. | |
| 9 | |
| 10 RED_COLOR='\e[0;31m' | |
| 11 GREEN_COLOR='\e[0;32m' | |
| 12 NO_COLOR='\e[0m' | |
| 13 | |
| 14 function echo_red { | |
| 15 echo -e "${RED_COLOR}$1${NO_COLOR}" | |
| 16 } | |
| 17 | |
| 18 function echo_green { | |
| 19 echo -e "${GREEN_COLOR}$1${NO_COLOR}" | |
| 20 } | |
| 21 | |
| 22 # Default values. | |
| 23 | |
| 24 product_dir=$(pwd) | |
| 
 
Nico
2013/10/30 14:47:02
Scripts shouldn't depend on the pwd
 
alextaran1
2013/10/30 16:08:54
The library should be installed into <(product_dir
 
Alexander Potapenko
2013/10/31 12:18:16
As Nico suggested below, $(dirname "${0}") is bett
 
alextaran1
2013/11/01 11:17:00
Added cd $(dirname "${0}") in the beginning. After
 
 | |
| 25 intermediate_dir=$(pwd) | |
| 26 | |
| 27 # Should be without spaces to pass it to dpkg-buildpackage. | |
| 28 makejobs="-j14" | |
| 29 | |
| 30 # Parsing args. | |
| 31 | |
| 32 while getopts ":i:l:m:hp:s:j:" opt; do | |
| 33 case ${opt} in | |
| 34 p) | |
| 35 echo_green "Only installing dependencies (requires root access)" | |
| 36 echo_green "Installing dependencies for: ${OPTARG}" | |
| 37 sudo apt-get -y --no-remove build-dep ${OPTARG} | |
| 38 exit | |
| 39 ;; | |
| 40 h) | |
| 41 echo "Possible flags: | |
| 42 -p - install dependencies for packages, | |
| 43 -h - this help, | |
| 44 -l - which library to build, | |
| 45 -i - sets relative product_dir, | |
| 46 -s - sanitizer (only asan is supported now)." | |
| 47 echo "Environment variabless, which affect this script: CC and CXX" | |
| 48 exit | |
| 49 ;; | |
| 50 i) | |
| 51 product_dir="$(pwd)/${OPTARG}" | |
| 
 
Nico
2013/10/30 14:47:02
Does this need to be configurable? Can you just ha
 
alextaran1
2013/10/30 16:08:54
product_dir should be a path to chrome binary (or
 
 | |
| 52 ;; | |
| 53 l) | |
| 54 library="${OPTARG}" | |
| 55 ;; | |
| 56 m) | |
| 57 intermediate_dir="${OPTARG}" | |
| 58 ;; | |
| 59 j) | |
| 60 makejobs="-j${OPTARG}" | |
| 61 ;; | |
| 62 s) | |
| 63 sanitizer_type="${OPTARG}" | |
| 64 if [[ "${OPTARG}" == "asan" ]]; then | |
| 65 sanitizer_flag_string="address" | |
| 66 else | |
| 67 echo_red "Invalid sanitizer: ${OPTARG}" >&2 | |
| 68 exit 1 | |
| 69 fi | |
| 70 ;; | |
| 71 *) | |
| 72 echo_red "Invalid option: -${OPTARG}" >&2 | |
| 73 exit 1 | |
| 74 ;; | |
| 75 esac | |
| 76 done | |
| 77 | |
| 78 if [[ -z "${library}" ]]; then | |
| 79 echo_red "No library specified to build" >&2 | |
| 80 exit 1 | |
| 81 fi | |
| 82 | |
| 83 if [[ -z "${sanitizer_type}" ]]; then | |
| 
 
Nico
2013/10/30 14:47:02
Can this be python instead?
 
alextaran1
2013/10/30 16:08:54
Not sure what do you mean here..
 
Nico
2013/11/02 00:05:02
Could this whole script be a python script instead
 
Alexander Potapenko
2013/11/05 14:07:23
I support this, but maybe we can rewrite the scrip
 
 | |
| 84 echo_red "No sanitizer specified" >&2 | |
| 85 exit | |
| 86 fi | |
| 87 | |
| 88 export CFLAGS="-fsanitize=${sanitizer_flag_string} -g -fPIC -w" | |
| 89 export CXXFLAGS="-fsanitize=${sanitizer_flag_string} -g -fPIC -w" | |
| 90 export LDFLAGS="-Wl,-z,origin -Wl,-R,XORIGIN/." | |
| 91 | |
| 92 mkdir -p ${product_dir}/instrumented_libraries/${sanitizer_type} | |
| 93 | |
| 94 needed_dependencies=$(apt-get -s build-dep ${library} | grep Inst \ | |
| 95 | cut -d " " -f 2) | |
| 96 | |
| 97 if [[ -n "${needed_dependencies}" ]]; then | |
| 98 echo_red "Library ${library} needs dependencies: ${needed_dependencies}" >&2 | |
| 99 echo_red "Please, install dependencies using: | |
| 100 third_party/instrumented_libraries/download_build_install -p ${library}" >&2 | |
| 101 exit 1 | |
| 102 fi | |
| 103 | |
| 104 ( | |
| 105 # Downloading library | |
| 106 mkdir -p ${intermediate_dir}/${library} | |
| 107 cd ${intermediate_dir}/${library} | |
| 108 apt-get source ${library} 2>&1 | |
| 
 
Nico
2013/10/30 14:47:02
How does this work on non-apt systems?
 
alextaran1
2013/10/30 16:08:54
This will not work. Does anybody want to build chr
 
Alexander Potapenko
2013/10/31 12:18:16
Apt systems (namely Ubuntu) are first-class citize
 
 | |
| 109 | |
| 110 # cd into the only directory in the current folder | |
| 111 # where our package has been unpacked. | |
| 112 cd $(ls -F |grep \/$) | |
| 113 | |
| 114 # Build library | |
| 115 ./configure --prefix="${product_dir}/instrumented_libraries/${sanitizer_type}" | |
| 116 make ${makejobs} | |
| 117 | |
| 118 # Install library | |
| 119 make ${makejobs} install 2>&1 | |
| 120 ) > /dev/null | |
| 121 | |
| 122 # Mark that library is installed. | |
| 123 # This file is used by GYP as 'output' to mark that it's already build | |
| 124 # while making incremental build. | |
| 125 touch ${product_dir}/instrumented_libraries/${sanitizer_type}/${library}.txt | |
| 126 | |
| 127 # Clean up. | |
| 128 rm -rf ${intermediate_dir}/${library} | |
| OLD | NEW |