diff options
author | Simon Rettberg | 2013-12-30 15:04:38 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-12-30 15:04:38 +0100 |
commit | 20f825b4cc559e5c90fcaad3e1c7876c51c4540f (patch) | |
tree | cd5d138d3b14fa0ef38f2a4661cf9f68b0daa44b | |
parent | [systemd] Comment about the environment patching (diff) | |
download | tm-scripts-20f825b4cc559e5c90fcaad3e1c7876c51c4540f.tar.gz tm-scripts-20f825b4cc559e5c90fcaad3e1c7876c51c4540f.tar.xz tm-scripts-20f825b4cc559e5c90fcaad3e1c7876c51c4540f.zip |
<setup_target> Minor refactoring.
Remove some pinfo calls that aren't too interesting. Improve pinfo output when
processing dependencies. Expand some one-line conditionals to real if-then-else.
Change some other messages.
-rwxr-xr-x | remote/setup_target | 181 |
1 files changed, 103 insertions, 78 deletions
diff --git a/remote/setup_target b/remote/setup_target index 86da6d4c..be35e0fe 100755 --- a/remote/setup_target +++ b/remote/setup_target @@ -1,6 +1,6 @@ #!/bin/bash # ----------------------------------------------------------------------------- -# +# # Copyright (c) 2011 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. @@ -10,10 +10,10 @@ # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ -# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # # This file contains the functions needed to setup a target. -# The main function is 'generate_target' which will go over all +# The main function is 'generate_target' which will go over all # activated modules (symlinks found under remote/targets/<target>) # and run the module-specific 'fetch_source', 'build' and 'post_copy' # functions of the modules. @@ -22,10 +22,10 @@ # can process any module, as long as following requirements are met: # # - Modules need to have a build-script and a config file, -# i.e. remote/module/kernel/kernel.build +# i.e. remote/module/kernel/kernel.build # and remote/module/kernel/kernel.conf # as these will be read by 'process_module'. -# +# # - Modules need to generate a 'build'-directory in their # own sub-directory (i.e. remote/modules/sshd/build/ # as 'copy_files_with_deps' will look for the files in @@ -48,13 +48,14 @@ # remote/modules/<module>/data which will be copied as is to the target build directory. # # Moreover modules do not need to specify the dynamic dependencies of given binaries -# as these will be determined automaticly by the helper function 'get_dynamic_dependencies' +# as these will be determined automaticly by the helper function 'get_dynamic_dependencies' # ----------------------------------------------------------------------------- # MODE_DIR="${ROOT_DIR}/remote" MODULES_DIR="${MODE_DIR}/modules" EXPORT_DIR="/export/build" -# Keep track of processed modules +# Keep track of processed modules so we don't +# build a module multiple times when following dependencies PROCESSED_MODULES="" initial_checks () { @@ -88,10 +89,12 @@ read_config () { # a specific tool.conf seems to exist, use it to override/extend certain vars validate_config "${MODULE_CONFIG}.${FILE}" . "${MODULE_CONFIG}.${FILE}" || perror "Sourcing '${MODULE_CONFIG}.${FILE}' failed." - pinfo "Sourced distribution specific ${MODULE_CONFIG}.${FILE}" - break + pinfo "Sourced distribution specific config (${MODULE_CONFIG##*/}.${FILE})" + return # end function fi done + # reaching here means no specific config + pinfo "Sourced genereal module config only (${MODULE_CONFIG##*/})" } validate_config () { @@ -118,12 +121,13 @@ read_build () { export_builds() { [ ! -d "${MODE_DIR}/builds" ] && perror "No ${MODE_DIR}/builds, nothing to export." pinfo "Mounting ${MODE_DIR}/builds to ${EXPORT_DIR}. This will make the local builds syncable from another machine." - [ ! -d "${EXPORT_DIR}" ] && mkdir -p "${EXPORT_DIR}" - mount --bind ${MODE_DIR}/builds ${EXPORT_DIR} || perror "Failed to bind mount ${MODE_DIR}/builds to ${EXPORT_DIR}" + [ ! -d "${EXPORT_DIR}" ] && mkdir -p "${EXPORT_DIR}" + mount --bind ${MODE_DIR}/builds ${EXPORT_DIR} || perror "Failed to bind mount ${MODE_DIR}/builds to ${EXPORT_DIR}" } # # main function which copies all files, directories, binaries and external libraries to TARGET_BUILD_DIR +# called after building the module # copy_files_with_deps () { @@ -133,7 +137,6 @@ copy_files_with_deps () { COPYFILES_LIST="list_wanted_stage3.2" [ -e "${COPYFILES_LIST}" ] && rm "${COPYFILES_LIST}" - [ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..." local OPTIONAL for FILENAME in ${REQUIRED_BINARIES} @@ -156,11 +159,11 @@ copy_files_with_deps () { done FINAL_LIST=$(trim "$FINAL_LIST") if [ -z "$FINAL_LIST" ]; then - pwarning "\tNo Binary found for ${FILENAME}. Skipping." + pwarning "\tNo Binary found for ${FILENAME}. Skipping." continue fi if [[ "$FINAL_LIST" == *" "* ]]; then - pwarning "Found more than one match for required file '$FILENAME': $FINAL_LIST" + pdebug "Found more than one match for required file '$FILENAME': $FINAL_LIST" else pdebug "\tFound ${FILENAME} at ${FILE}" fi @@ -172,7 +175,7 @@ copy_files_with_deps () { fi for FILE in $FINAL_LIST; do pdebug "* $FILE" - strip "$FILE" || pwarning "Could not strip '${FILE}'" + strip "$FILE" || pdebug "Could not strip '${FILE}'" get_link_chain "${MODULE_BUILD_DIR}/${FILE}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${FILE}" >> "${COPYFILES_LIST}" done @@ -184,7 +187,7 @@ copy_files_with_deps () { [ -z "$FILE_CANDIDATES" ] && perror "Cannot find required library $LIB" for LOCATION in $FILE_CANDIDATES; do pdebug "* $LOCATION" - strip "$LOCATION" || pwarning "Could not strip '${LOCATION}'" + strip "$LOCATION" || pdebug "Could not strip '${LOCATION}'" get_link_chain "${MODULE_BUILD_DIR}/${LOCATION}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${LOCATION}" >> "${COPYFILES_LIST}" done @@ -192,8 +195,7 @@ copy_files_with_deps () { [ ! -z "${REQUIRED_DIRECTORIES}" ] && pinfo "Gathering required directories from config file..." local CURRENT_PWD=$(pwd) # Prevent calling pwd 50000 times inside the loop below - for ENTRY in ${REQUIRED_DIRECTORIES} - do + for ENTRY in ${REQUIRED_DIRECTORIES}; do pdebug "* .$ENTRY" echo "./${ENTRY}" >> "${COPYFILES_LIST}" for BIN in $(find ".${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF') @@ -203,10 +205,9 @@ copy_files_with_deps () { get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${BIN}" >> "${COPYFILES_LIST}" done done - + [ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..." - for ENTRY in ${REQUIRED_FILES} - do + for ENTRY in ${REQUIRED_FILES}; do get_link_chain "${MODULE_BUILD_DIR}/${ENTRY}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${MODULE_BUILD_DIR}/.${ENTRY}" >> "${COPYFILES_LIST}" done @@ -218,7 +219,7 @@ copy_files_with_deps () { pinfo "Copying $CLISTCOUNT files to '${TARGET_BUILD_DIR}'." tarcopy "$(cat "$COPYFILES_LIST"|sort -u)" "${TARGET_BUILD_DIR}" fi - + } # @@ -226,23 +227,23 @@ copy_files_with_deps () { # main public function. Requires the TARGET to be given as argument. # this will simply go over all the modules as found in the remote/target/<TARGET> # and run following functions: -# +# # generate_target() { initial_checks - + TARGET=$1 && shift TARGET_DIR="${MODE_DIR}/targets/${TARGET}" TARGET_BUILD_DIR="${MODE_DIR}/builds/${TARGET}" - [ -e "${ROOT_DIR}/logs/${TARGET}.size" ] && . "${ROOT_DIR}/logs/${TARGET}.size" || echo "declare -A BUILD_SIZE" >> "${ROOT_DIR}/logs/${TARGET}.size" + [ -e "${ROOT_DIR}/logs/${TARGET}.size" ] && . "${ROOT_DIR}/logs/${TARGET}.size" || echo "declare -A BUILD_SIZE" >> "${ROOT_DIR}/logs/${TARGET}.size" [ -d "$TARGET_DIR" ] || perror "Given target directory does not exist: $TARGET_DIR" [[ "$TARGET" == "builds" || "$TARGET" == "modules" ]] && \ perror "Target directory cannot be named 'builds' or 'modules'." - - pinfo "Generating '$TARGET_BUILD_DIR' for '$TARGET'" + + pdebug "Generating '$TARGET_BUILD_DIR' for '$TARGET'" # if no arguments assume all. if [ "x$1" = "x" -o "x$1" = "xall" ]; then @@ -281,84 +282,108 @@ generate_target() { pinfo "Copying libc and ld-linux used by ${SHELL}" tarcopy "$(list_basic_libs)" "${TARGET_BUILD_DIR}" - [ -d "$TARGET_BUILD_DIR" ] && TARGET_BUILD_SIZE=$(du -bc "${TARGET_BUILD_DIR}" | awk 'END {print $1}') || TARGET_BUILD_SIZE=0 + if [ -d "$TARGET_BUILD_DIR" ]; then + TARGET_BUILD_SIZE=$(du -bc "${TARGET_BUILD_DIR}" | awk 'END {print $1}') + else + TARGET_BUILD_SIZE=0 + fi # now iterate over given tools and copy them while (( "$#" )); do process_module "$1" shift done - - post_process_target + + post_process_target pinfo "Target completed. Total size: $(du -bsh "${TARGET_BUILD_DIR}" | awk 'END {print $1}')" TOOL_STR="" } process_module() { - [ "$#" -ne "1" ] && perror "process_module: want 1 param." + [ "$#" -lt "1" ] && perror "process_module: want >= 1 param." + if [ "x$1" = "x--dep-of" ]; then + shift + local DEPOF=" $1" + shift + else + local DEPOF="" + fi local MODULE="$1" + [ -z "$MODULE" ] && perror "No module given when calling process_module" [[ "$PROCESSED_MODULES" == *"!${MODULE}!"* ]] && return # Already processed this module PROCESSED_MODULES="${PROCESSED_MODULES}!${MODULE}!" local MODULE_DIR="${TARGET_DIR}/${MODULE}" local MODULE_BUILD_DIR="${MODULE_DIR}/build" local TOOL_STR="" - pinfo ">>>>>>>>>>>>>>>>> Processing module [ $MODULE ]" TOOL_STR="[${MODULE}]" - if [ -d "${MODULE_DIR}" ]; then - cd "${MODULE_DIR}" || perror "Module dir '${MODULE_DIR}' seems to exist, but cd to it failed." - pinfo "## Reading config" - read_config - # Check if this module has a dependency that wasn't built yet: - if [ ! -z "$REQUIRED_MODULES" ]; then - pinfo "$MODULE depends on ${REQUIRED_MODULES}...." - for DEP in $REQUIRED_MODULES; do - process_module "$DEP" - done - # Read old config again, as it got overwritten by the deps - cd "${MODULE_DIR}" || perror "Tool dir '${MODULE_DIR}' seems to exist, but cd to it failed (after building deps)." - read_config - pinfo "<<<<<<<<<<<<<<<<< Dependency modules processed, back to module [ $MODULE ]" + if [ ! -d "${MODULE_DIR}" ]; then + if [ -z "$DEPOF" ]; then + perror "Module directory for '$MODULE' not found in ${TAREGET_DIR}" fi - pinfo "## Reading build" - read_build - pinfo "## Installing dependencies" - cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." - install_dependencies + perror "Module directory for '$MODULE' not found in ${TARGET_DIR} (is a dependency of${DEPOF})" + return + fi + cd "${MODULE_DIR}" || perror "Module dir '${MODULE_DIR}' seems to exist, but cd to it failed." + pdebug "## Reading config of $MODULE" + read_config + # Check if this module has a dependency that wasn't built yet: + if [ ! -z "$REQUIRED_MODULES" ]; then + pdebug "$MODULE depends on ${REQUIRED_MODULES}...." + for DEP in $REQUIRED_MODULES; do + process_module --dep-of "${MODULE}${DEPOF}" "$DEP" + done + # Read old config again, as it got overwritten by the deps + cd "${MODULE_DIR}" || perror "Tool dir '${MODULE_DIR}' seems to exist, but cd to it failed (after building deps)." + read_config + fi + [ -n "$DEPOF" ] && local DEPOF_STR="(dependency of${DEPOF})" + pinfo ">>>>>>>>>>>>>>>>> Processing module [ $MODULE ] $DEPOF_STR" + pdebug "## Reading build of $MODULE" + read_build + pdebug "## Installing dependencies" + cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." + install_dependencies + if [ ! -e "${MODULE_DIR}/.fetched_source" ]; then pinfo "## Fetching source" - [ -e "${MODULE_DIR}/.fetched_source" ] || { fetch_source && touch "${MODULE_DIR}/.fetched_source"; } - if [ -e "${MODULE_DIR}/.built" -a -d "${MODULE_BUILD_DIR}" ]; then - pinfo "# built-flag is set, skipping build..." - else - pinfo "## Building" - mkdir -p "${MODULE_BUILD_DIR}" || perror "Could not create build dir" - cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." - build # calls perror if something fails, no need to do that here - touch "${MODULE_DIR}/.built" || pwarning "Error setting built-flag" - fi - # remove *.la files as they might confuse libtool/linker of other tool packages - [ -d "${MODULE_BUILD_DIR}" ] && find "${MODULE_BUILD_DIR}" -name '*.la' -exec rm -f {} \; - [ -d "${TARGET_BUILD_DIR}" ] && TARGET_BUILD_SIZE=$(du -bc "${TARGET_BUILD_DIR}" | awk 'END {print $1}') || TARGET_BUILD_SIZE=0 - pinfo "## Copying files with dependencies" + fetch_source && touch "${MODULE_DIR}/.fetched_source" + fi + if [ ! -e "${MODULE_DIR}/.built" -a -d "${MODULE_BUILD_DIR}" ]; then + pinfo "## Building" + mkdir -p "${MODULE_BUILD_DIR}" || perror "Could not create build dir" cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." - copy_files_with_deps + build # calls perror if something fails, no need to do that here + touch "${MODULE_DIR}/.built" || pwarning "Error setting built-flag" + fi + # remove *.la files as they might confuse libtool/linker of other tool packages + [ -d "${MODULE_BUILD_DIR}" ] && find "${MODULE_BUILD_DIR}" -name '*.la' -exec rm -f {} \; + # update size of target build dir + if [ -d "${TARGET_BUILD_DIR}" ]; then + TARGET_BUILD_SIZE=$(du -bc "${TARGET_BUILD_DIR}" | awk 'END {print $1}') + else + TARGET_BUILD_SIZE=0 + fi + pinfo "## Copying files with dependencies" + cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." + copy_files_with_deps + if [ -n "$REQUIRED_SYSTEM_FILES" ]; then pinfo "## Copying required system files" # REQUIRED_SYSTEM_FILES cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." copy_system_files + fi + if [ -d "${MODULE_DIR}/data" ]; then pinfo "## Copying static module files" copy_static_data - pinfo "## Post copy" - cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." - post_copy - # Sanity checks - [ -e "$TARGET_BUILD_DIR/var/run" -a ! -L "$TARGET_BUILD_DIR/var/run" ] && perror "Messup datected: $TARGET_BUILD_DIR/var/run exists and is not a symlink!" - [ -e "$TARGET_BUILD_DIR/var/lock" -a ! -L "$TARGET_BUILD_DIR/var/lock" ] && perror "Messup datected: $TARGET_BUILD_DIR/var/lock exists and is not a symlink!" - [ -n "$(ls -A "$TARGET_BUILD_DIR/run")" ] && perror "Messup detected: $TARGET_BUILD_DIR/run is not empty. You cannot place static files there, use /etc/tmpfiles.d instead!" - # set MODULE_BUILD_SIZE - calc_size - pinfo "Module completed. Total size: ${MODULE_BUILD_SIZE}" - else - pwarning "Module directory for '$MODULE' not found." fi + pinfo "## Post copy" + cd "${MODULE_DIR}" || perror "cd to '${MODULE_DIR}' failed." + post_copy + # Sanity checks + [ -e "$TARGET_BUILD_DIR/var/run" -a ! -L "$TARGET_BUILD_DIR/var/run" ] && perror "Messup datected: $TARGET_BUILD_DIR/var/run exists and is not a symlink!" + [ -e "$TARGET_BUILD_DIR/var/lock" -a ! -L "$TARGET_BUILD_DIR/var/lock" ] && perror "Messup datected: $TARGET_BUILD_DIR/var/lock exists and is not a symlink!" + [ -n "$(ls -A "$TARGET_BUILD_DIR/run")" ] && perror "Messup detected: $TARGET_BUILD_DIR/run is not empty. You cannot place static files there, use /etc/tmpfiles.d instead!" + # set MODULE_BUILD_SIZE + calc_size + pinfo "Module completed. Total size: ${MODULE_BUILD_SIZE}" } post_process_target() { |