Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: common.sh

Issue 6591056: Add check_for_file and check_for_tool functions to common.sh (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Added comment about padding. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 args="${args} --force_copy" 640 args="${args} --force_copy"
641 fi 641 fi
642 642
643 # Modify the image for test, creating a new test image 643 # Modify the image for test, creating a new test image
644 "${SCRIPTS_DIR}/mod_image_for_test.sh" --board=${FLAGS_board} \ 644 "${SCRIPTS_DIR}/mod_image_for_test.sh" --board=${FLAGS_board} \
645 --image="$1/$2" --noinplace ${args} 645 --image="$1/$2" --noinplace ${args}
646 646
647 # From now on we use the just-created test image 647 # From now on we use the just-created test image
648 CHROMEOS_RETURN_VAL="$1/${CHROMEOS_TEST_IMAGE_NAME}" 648 CHROMEOS_RETURN_VAL="$1/${CHROMEOS_TEST_IMAGE_NAME}"
649 } 649 }
650
651 # Check that the specified file exists. If the file path is empty or the file
652 # doesn't exist on the filesystem generate useful error messages. Otherwise
653 # show the user the name and path of the file that will be used. The padding
654 # parameter can be used to tabulate multiple name:path pairs. For example:
655 #
656 # check_for_file "really long name" "...:" "file.foo"
657 # check_for_file "short name" ".........:" "another.bar"
658 #
659 # Results in the following output:
660 #
661 # Using really long name...: file.foo
662 # Using short name.........: another.bar
663 #
664 # If tabulation is not required then passing "" for padding generates the
665 # output "Using <name> <path>"
666 check_for_file() {
667 local name=$1
668 local padding=$2
669 local path=$3
670
671 if [ -z "${path}" ]; then
672 die "No ${name} file specified."
673 fi
674
675 if [ ! -e "${path}" ]; then
676 die "No ${name} file found at: ${path}"
677 else
678 info "Using ${name}${padding} ${path}"
679 fi
680 }
681
682 # Check that the specified tool exists. If it does not exist in the PATH
683 # generate a useful error message indicating how to install the ebuild
684 # that contains the required tool.
685 check_for_tool() {
686 local tool=$1
687 local ebuild=$2
688
689 if ! which "${tool}" >/dev/null ; then
690 error "The ${tool} utility was not found in your path. Run the following"
691 error "command in your chroot to install it: sudo -E emerge ${ebuild}"
692 exit 1
693 fi
694 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698