diff --git a/brew-common.sh b/brew-common.sh index 653be9c..7834b64 100755 --- a/brew-common.sh +++ b/brew-common.sh @@ -117,13 +117,17 @@ get_fixed_length_path() { # Use the Git SHA1 of the Homebrew repository as a filler. if [[ -z $sha1 ]]; then - if [[ ! -d $path/.git ]]; then - fatal "Directory '$path' is not a Git repository, cannot get SHA1" + if [[ -f $path/GIT_SHA1 ]]; then + sha1=$( cat $path/GIT_SHA1 ) + else + if [[ ! -d $path/.git ]]; then + fatal "Directory '$path' is not a Git repository, cannot get SHA1" + fi + sha1=$( cd "$path" && git rev-parse HEAD ) fi - sha1=$( cd "$path" && git rev-parse HEAD ) fi if [[ ! $sha1 =~ ^[0-9a-f]{40}$ ]]; then - fatal "Invalid Git SHA1: '$sha1'" + fatal "Invalid Git SHA1: '$sha1', expected 40 hex characters" fi fixed_length_path=\ diff --git a/post_install.template b/post_install.template index d968239..fc17763 100644 --- a/post_install.template +++ b/post_install.template @@ -30,10 +30,11 @@ fi readonly orig_brew_home="{{ orig_brew_home }}" declare -i -r ORIG_LEN=${#orig_brew_home} -brew_home=$PWD +brew_home=$script_dir +cd "$brew_home" LEN=${#brew_home} if [[ $LEN -gt $ORIG_LEN ]]; then - fatal "Homebrew/Linuxbrew absolute path should be no more than $ORIG_LEN bytes, but actual " \ + fatal "Homebrew/Linuxbrew absolute path should be no more than $ORIG_LEN bytes, but actual" \ "length is $LEN bytes: $brew_home" fi diff --git a/test.sh b/test.sh index 5e4b7e0..53239fd 100755 --- a/test.sh +++ b/test.sh @@ -45,6 +45,20 @@ cleanup() { exit "$exit_code" } +find_latest_brew_dir() { + latest_brew_dir=$( + ls -td $( + find . -mindepth 1 -maxdepth 1 -type d -name "$YB_BREW_TYPE_LOWERCASE-*" + ) | head -1 + ) + if [[ ! -d $latest_brew_dir ]]; then + log "In directory $PWD, found latest brew directory: $latest_brew_dir" + ( set -x; ls -l ) + fatal "Unable to find the latest Homebrew/Linuxbrew installation in $PWD" + fi + latest_brew_dir=$( cd "$latest_brew_dir" && pwd ) +} + # ------------------------------------------------------------------------------------------------- # Parsing command-line arguments # ------------------------------------------------------------------------------------------------- @@ -87,7 +101,7 @@ if [[ -z ${work_dir:-} ]]; then tmp_dir=$HOME/tmp mkdir -p "$tmp_dir" fi - work_dir=$tmp_dir/ybbrewtest-$$-$(date +%Y-%m-%dT%H_%M_%S) + work_dir=$tmp_dir/ybbrewtst-$$-$(date +%Y%m%dT%H%M) trap cleanup EXIT fi mkdir -p "$work_dir" @@ -96,13 +110,26 @@ cd "$work_dir" export YB_BREW_BUILD_UNIT_TEST_MODE=1 "$script_dir/brew-clone-and-build-all.sh" +find_latest_brew_dir +brew_home=$latest_brew_dir +log "Will use the directory $brew_home for further testing" + +heading "Testing post_install.sh" + +( set -x; cd /; rm -rf "$brew_home/.git"; "$brew_home/post_install.sh" ) + heading "Testing brew-copy.sh" -brew_home=$( - find . -mindepth 1 -maxdepth 1 -type d -name "$YB_BREW_TYPE_LOWERCASE-*" | sort | head -1 -) + if [[ -z $brew_home ]]; then fatal "Could not find a subdirectory starting with '$YB_BREW_TYPE_LOWERCASE-' in $PWD" fi "$script_dir/brew-copy.sh" "$brew_home" +heading "Testing post_install.sh after brew-copy.sh" +find_latest_brew_dir +if [[ $latest_brew_dir == $brew_home ]]; then + fatal "brew-copy.sh failed to produce a new Homebrew/Linuxbrew directory in $PWD" +fi +( set -x; "$latest_brew_dir/post_install.sh" ) + log "TEST SUCCEEDED"