| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Common constants for build scripts | 5 # Common constants for build scripts |
| 6 # This must evaluate properly for both /bin/bash and /bin/sh | 6 # This must evaluate properly for both /bin/bash and /bin/sh |
| 7 | 7 |
| 8 # All scripts should die on error unless commands are specifically excepted | 8 # All scripts should die on error unless commands are specifically excepted |
| 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. | 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. |
| 10 # TODO: Re-enable this once shflags is less prone to dying. | 10 # TODO: Re-enable this once shflags is less prone to dying. |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 local file=$1 | 248 local file=$1 |
| 249 local whitelist="$FLAGS_whitelist" | 249 local whitelist="$FLAGS_whitelist" |
| 250 test -f "$whitelist" || (echo "Whitelist file missing ($whitelist)" && exit 1) | 250 test -f "$whitelist" || (echo "Whitelist file missing ($whitelist)" && exit 1) |
| 251 | 251 |
| 252 local checksum=$(md5sum "$file" | awk '{ print $1 }') | 252 local checksum=$(md5sum "$file" | awk '{ print $1 }') |
| 253 local count=$(sed -e "s/#.*$//" "${whitelist}" | grep -c "$checksum" \ | 253 local count=$(sed -e "s/#.*$//" "${whitelist}" | grep -c "$checksum" \ |
| 254 || /bin/true) | 254 || /bin/true) |
| 255 test $count -ne 0 | 255 test $count -ne 0 |
| 256 } | 256 } |
| 257 | 257 |
| 258 # Check that all arguments are flags; that is, there are no remaining arguments |
| 259 # after parsing from shflags. Allow (with a warning) a single empty-string |
| 260 # argument. |
| 261 # |
| 262 # TODO: fix buildbot so that it doesn't pass the empty-string parameter, |
| 263 # then change this function. |
| 264 # |
| 265 # Usage: check_flags_only_and_allow_null_arg "$@" && set -- |
| 266 function check_flags_only_and_allow_null_arg { |
| 267 do_shift=1 |
| 268 if [[ $# == 1 && -z "$@" ]]; then |
| 269 echo "$0: warning: ignoring null argument" >&2 |
| 270 shift |
| 271 do_shift=0 |
| 272 fi |
| 273 if [[ $# -gt 0 ]]; then |
| 274 echo "error: invalid arguments: \"$@\"" >&2 |
| 275 flags_help |
| 276 exit 1 |
| 277 fi |
| 278 return $do_shift |
| 279 } |
| 280 |
| 258 V_RED="\e[31m" | 281 V_RED="\e[31m" |
| 259 V_YELLOW="\e[33m" | 282 V_YELLOW="\e[33m" |
| 260 | 283 |
| 261 function warn { | 284 function warn { |
| 262 echo -e "${V_YELLOW}Warning..: $1${V_VIDOFF}" | 285 echo -e "${V_YELLOW}Warning..: $1${V_VIDOFF}" |
| 263 } | 286 } |
| 264 | 287 |
| 265 function error { | 288 function error { |
| 266 echo -e "${V_RED}Error....: $1${V_VIDOFF}" | 289 echo -e "${V_RED}Error....: $1${V_VIDOFF}" |
| 267 } | 290 } |
| OLD | NEW |