mulle-bootstrap-scripts.sh
d7f96955
 #! /bin/sh
 #
 #   Copyright (c) 2015 Nat! - Mulle kybernetiK
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
 #   modification, are permitted provided that the following conditions are met:
 #
 #   Redistributions of source code must retain the above copyright notice, this
 #   list of conditions and the following disclaimer.
 #
 #   Redistributions in binary form must reproduce the above copyright notice,
 #   this list of conditions and the following disclaimer in the documentation
 #   and/or other materials provided with the distribution.
 #
 #   Neither the name of Mulle kybernetiK nor the names of its contributors
 #   may be used to endorse or promote products derived from this software
 #   without specific prior written permission.
 #
 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 #   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 #   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 #   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 #   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 #   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 #   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #
 
 find_fetch_setting_file()
 {
    local value
    local flag
 
    READ_SETTING_RETURNS_PATH="YES"
    export READ_SETTING_RETURNS_PATH
 
    value="`read_fetch_setting "$@"`"
    flag=$?
 
    READ_SETTING_RETURNS_PATH="NO"
 
    echo "$value"
    return $flag
 }
 
 
 find_repo_setting_file()
 {
    local value
    local flag
 
    READ_SETTING_RETURNS_PATH="YES"
    export READ_SETTING_RETURNS_PATH
 
    value="`read_repo_setting "$@"`"
    flag=$?
 
    READ_SETTING_RETURNS_PATH="NO"
 
    echo "$value"
    return $flag
 }
 
 
 find_build_root_setting_file()
 {
    local value
    local flag
 
    READ_SETTING_RETURNS_PATH="YES"
    export READ_SETTING_RETURNS_PATH
 
    value="`read_build_root_setting "$@"`"
    flag=$?
 
    READ_SETTING_RETURNS_PATH="NO"
 
    echo "$value"
    return $flag
 }
 
 
 find_build_setting_file()
 {
    local value
    local flag
 
    READ_SETTING_RETURNS_PATH="YES"
    export READ_SETTING_RETURNS_PATH
 
    value="`read_build_setting "$@"`"
    flag=$?
 
    READ_SETTING_RETURNS_PATH="NO"
 
    echo "$value"
    return $flag
 }
 
 
 is_inherited_setting_file()
 {
    echo "$1" | egrep -q -s "^${BOOTSTRAP_SUBDIR}.auto"
 }
 
 
 
 run_build_root_settings_script()
 {
    local  name
 
    scriptname="$1"
    shift
 
    [ -z "$scriptname" ] && internal_fail "scriptname is empty"
 
    local script
 
    script="`find_build_root_setting_file "bin/${scriptname}.sh"`"
    if [ ! -z "${script}" ]
    then
1b26e970
       run_script "${script}" "$@"
d7f96955
    fi
 }
 
 
 # run in subshell
 run_fake_environment_script()
 {
151d8edd
    local srcdir
d7f96955
    local script
 
151d8edd
    srcdir="$1"
d7f96955
    shift
    script="$1"
    shift
 
151d8edd
    ( owd="`pwd -P`"; cd "${srcdir}" ;
d7f96955
    CLONES_SUBDIR="${owd}/${CLONES_SUBDIR}" \
    CLONESBUILD_SUBDIR="${owd}/${CLONESBUILD_SUBDIR}" \
    DEPENDENCY_SUBDIR="${owd}/${DEPENDENCY_SUBDIR}" \
    run_script "${owd}/${script}" "$@" ) || exit 1
 }
 
 
 # repo setting scripts are treated as if inherrited
 run_repo_settings_script()
 {
    local name
    local scriptname
151d8edd
    local srcdir
d7f96955
 
    name="$1"
    shift
151d8edd
    srcdir="$1"
    shift
d7f96955
    scriptname="$1"
    shift
 
fe01cf28
    exekutor [ -e "$srcdir" ] || internal_fail "directory srcdir \"${srcdir}\" is wrong ($PWD)"
    [ ! -z "$name" ]          || internal_fail "name is empty"
    [ ! -z "$scriptname" ]    || internal_fail "scriptname is empty"
d7f96955
 
    local script
 
    script="`find_repo_setting_file "${name}" "bin/${scriptname}.sh"`"
    if [ ! -z "${script}" ]
    then
151d8edd
       run_fake_environment_script "${srcdir}" "${script}" "$@" || exit 1
1e8d5d86
    fi
 }
 
 
 run_build_settings_script()
 {
151d8edd
    local srcdir
1e8d5d86
    local name
    local scriptname
7fdfcd11
    local url
1e8d5d86
 
    name="$1"
    shift
7fdfcd11
    url="$1"
    shift
151d8edd
    srcdir="$1"
    shift
1e8d5d86
    scriptname="$1"
    shift
 
fe01cf28
    exekutor [ -e "$srcdir" ]  || internal_fail "srcdir \"${srcdir}\" is wrong ($PWD)"
151d8edd
    [ ! -z "$name" ]           || internal_fail "name is empty"
7fdfcd11
    [ ! -z "$url" ]            || internal_fail "url is empty"
151d8edd
    [ ! -z "$scriptname" ]     || internal_fail "scriptname is empty"
1e8d5d86
 
    local script
 
    script="`find_build_setting_file "${name}" "bin/${scriptname}.sh"`"
    if [ ! -z "${script}" ]
    then
57730883
       run_script "${script}" "${name}" "${url}" "${srcdir}" "$@" || exit 1
d7f96955
    fi
 }
 
 
 run_fetch_settings_script()
 {
    local  scriptname
 
    scriptname="$1"
    shift
 
    [ -z "$scriptname" ] && internal_fail "scriptname is empty"
 
    local script
 
    script="`find_fetch_setting_file "bin/${scriptname}.sh"`"
    if [ ! -z "${script}" ]
    then
       run_script "${script}" "$@"
       return $?
    fi
    return 0
 }