diff options
Diffstat (limited to 'libs/project')
-rwxr-xr-x | libs/project | 420 |
1 files changed, 208 insertions, 212 deletions
diff --git a/libs/project b/libs/project index 20a6fe77..37a5973c 100755 --- a/libs/project +++ b/libs/project @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr> # @@ -15,20 +15,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -PROJECT_ACTIONS_GENERIC="usage download extract update build install release clean" -PROJECT_ACTIONS_HELPERS="arguments" -PROJECT_FUNCTIONS=$( for action in $PROJECT_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$PROJECT_ACTIONS_HELPERS" ) +PROJECT_ACTIONS_GENERIC=(usage download extract update build install release clean) +PROJECT_ACTIONS_GENERIC_IGNORE_CHECK=(usage clean) +PROJECT_ACTIONS_HELPERS=(arguments) -INSTALL_REGEX="\([^:]*\):\(.*\)" +INSTALL_REGEX='\([^:]*\):\(.*\)' project_include() { local project=$1 local project_path=$( project_path "$project" ) - unset -f $PROJECT_FUNCTIONS + unset -f "${PROJECT_ACTIONS[@]}" - . "$project_path/$project" + source "$project_path/$project" project_helper_include "$project" } @@ -41,16 +41,16 @@ project_helper_include() { if [ -f "$include" ] then - . "$include" + source "$include" fi } project_check() { local project="${1##*/}" - local project_path="$(project_path "${project}")" + local project_path="$(project_path "$project")" - if ! [[ -f "${project_path}/${project}" ]]; then + if ! [[ -f "$project_path/$project" ]]; then return 1 fi } @@ -70,162 +70,108 @@ project_function_check() { } project_action() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift - local arguments=$@ + local arguments="$*" ( set +e - if ! project_check "$project" - then - printf "Project $project check failed\n" >&2 - return 1 - fi - project_action_check "$action" "$project" "$@" - # Why is this here? Commented out for now. - # if [ $? -eq 0 ] - # then - # return 0 - # fi - - project_include "$project" - - if ! function_check "$action" - then - return 0 - fi - - printf "Project $project $action (with ${arguments:-no argument})\n" >&2 - - ( - set -e - "$action" "$@" - ) + printf '%s\n' "Project $project $action (with ${arguments:-no argument})" >&2 - if [ $? -ne 0 ] - then - printf "\nProject $project $action (with ${arguments:-no argument}) failed\n" >&2 - return 1 + if "$action" "$@"; then + printf '\n%s\n' "Project $project $action (with ${arguments:-no argument}) completed" >&2 else - printf "\nProject $project $action (with ${arguments:-no argument}) completed\n" >&2 + printf '\n%s\n' "Project $project $action (with ${arguments:-no argument}) failed" >&2 + return 1 fi ) } project_action_check() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift ( set +e - if ! project_check "$project" - then - printf "Project $project check failed\n" >&2 + if ! function_check "${action}_check"; then return 1 fi - project_include "$project" - - if ! function_check "$action""_check" - then - return 1 - fi - - for project_force in $PROJECTS_FORCE - do - if [ "$project_force" = "$project" ] - then + for project_force in $PROJECTS_FORCE; do + if [[ "$project_force" == "$project" ]]; then return 1 fi done ( set -e - "$action""_check" "$@" + "${action}_check" "$@" ) ) } project_action_helper() { - local helper=$1 + local helper="$1" shift - local project=$1 + local project="$1" shift - ( - set +e - - if ! project_check "$project" - then - printf "Project $project check failed\n" >&2 - return 1 - fi - - project_include "$project" - - if ! function_check "$helper" - then - return 0 - fi + if ! function_check "$helper"; then + return 0 + fi - ( - set -e - "$helper" "$@" - ) - ) + "$helper" "$@" } project_action_arguments() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift + project_include "$project" + project_action_arguments_verify_recursive "$action" "$project" "$@" project_action_arguments_recursive "$action" "$project" "$@" } project_action_arguments_verify_recursive() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift local action_helper_arguments # Store final argument. - local argument=${@:$#} + local argument="${*:$#}" local test - if [ $# -gt 1 ] - then + if [[ "$#" -gt 1 ]]; then # Set previous arguments. set "${@:1:$#-1}" - elif [ $# -eq 1 ] - then + elif [[ "$#" -eq 1 ]]; then shift else return 0 fi - action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" ) + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")" - if ! [ -z "$action_helper_arguments" ] - then - test=$( echo "$action_helper_arguments" | grep -P "^$argument$" || true ) + if [[ -n "$action_helper_arguments" ]]; then + test="$(printf '%s\n' "$action_helper_arguments" | grep -e "^$argument\$" || true)" - if [ -z "$test" ] - then - printf "Invalid argument $argument for project $project action $action\n" >&2 + if [[ -z "$test" ]]; then + printf '%s\n' "Invalid argument $argument for project $project action $action" >&2 return 1 fi fi @@ -234,62 +180,54 @@ project_action_arguments_verify_recursive() { } project_action_arguments_recursive() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift local action_helper_arguments local argument - local ifs_save - action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" ) + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@" || true)" - if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ] - then + if [[ -z "$action_helper_arguments" ]]; then project_action "$action" "$project" "$@" else - # This it to allow space characters in arguments. - ifs_save=$IFS - IFS=$'\n' + # This is to allow space characters in arguments. + local ifs_save="$IFS" + local IFS=$'\n' - for argument in $( echo "$action_helper_arguments" ) + for argument in $(printf '%s\n' "$action_helper_arguments") do - ( - IFS=$ifs_save + IFS="$ifs_save" - # Only a single argument at a time is returned by the helper. - project_action_arguments_recursive "$action" "$project" "$@" "$argument" - ) + # Only a single argument at a time is returned by the helper. + project_action_arguments_recursive "$action" "$project" "$@" "$argument" done - - IFS=$ifs_save fi } project_action_projects() { - local action=$1 + local action="$1" shift - local project=$1 + local project="$1" shift - local project_path=$( project_path "$project" ) + local project_path="$(project_path "$project")" local project_projects_path="$project_path/$CONFIGS/$PROJECTS" local project_projects_action_path="$project_path/$CONFIGS/$PROJECTS-$action" local arguments local path - if [ -f "$project_projects_action_path" ] - then - path=$project_projects_action_path + if [[ -f "$project_projects_action_path" ]]; then + path="$project_projects_action_path" else - path=$project_projects_path + path="$project_projects_path" fi # Multiple arguments can be read from the file. - while read arguments - do - eval "project_action_arguments "$action" $arguments" + while read -r arguments; do + eval "project_action_arguments $action $arguments" done < "$path" } @@ -298,7 +236,7 @@ project_path() { local project_path="$root/$PROJECTS/$project" - echo "$project_path" + printf '%s\n' "$project_path" } project_sources_path() { @@ -331,7 +269,7 @@ project_sources_path() { if ! [ -z "$sources_path" ] then - echo "$sources_path" + printf '%s\n' "$sources_path" return fi @@ -340,7 +278,7 @@ project_sources_path() { if directory_filled_check "$path" then - echo "$path" + printf '%s\n' "$path" return fi @@ -364,7 +302,7 @@ project_sources_path() { if ! [ -z "$sources_path" ] then - echo "$sources_path" + printf '%s\n' "$sources_path" return fi } @@ -381,13 +319,13 @@ project_sources_directory_filled_check() { project_sources_directory_filled_error() { local project=$1 shift - local arguments=$@ + local arguments="$*" local sources_path=$( project_sources_path "$project" "$@" ) if ! [ -z "$sources_path" ] then - printf "Sources directory for project $project (with ${arguments:-no argument}) already exists\n" >&2 + printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" >&2 return 1 else return 0 @@ -397,13 +335,13 @@ project_sources_directory_filled_error() { project_sources_directory_missing_empty_error() { local project=$1 shift - local arguments=$@ + local arguments="$*" local sources_path=$( project_sources_path "$project" "$@" ) if [ -z "$sources_path" ] then - printf "Sources directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2 + printf '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 return 1 else return 0 @@ -425,7 +363,7 @@ project_sources_archive() { path="$path-$argument" fi - local archive="$path.$TAR_XZ" + local archive="$path.$ARCHIVE" if ! [ -f "$archive" ] then @@ -437,19 +375,19 @@ project_sources_archive() { if ! [ -z "$sources_archive" ] then - echo "$sources_archive" + printf '%s\n' "$sources_archive" fi } project_sources_archive_extract() { local project=$1 shift - local arguments=$@ + local arguments="$*" local archive=$( project_sources_archive "$project" "$@" ) local destination=$( dirname "$archive" ) - printf "Extracting source archive for $project (with ${arguments:-no argument})\n" + printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})" file_verification_check "$archive" archive_extract "$archive" "$destination" @@ -458,7 +396,7 @@ project_sources_archive_extract() { project_sources_archive_update() { local project=$1 shift - local arguments=$@ + local arguments="$*" local repository=$project local sources_path=$( project_sources_path "$project" "$repository" "$@" ) @@ -470,7 +408,7 @@ project_sources_archive_update() { rm -rf "$sources_path" fi - printf "Extracting source archive for $project (with ${arguments:-no argument})\n" + printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})" file_verification_check "$archive" archive_extract "$archive" "$destination" @@ -479,12 +417,12 @@ project_sources_archive_update() { project_sources_archive_missing_error() { local project=$1 shift - local arguments=$@ + local arguments="$*" local archive=$( project_sources_archive "$project" "$@" ) if [ -z "$archive" ] || ! [ -f "$archive" ] then - printf "Missing sources archive for $project (with ${arguments:-no argument})\n" >&2 + printf '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})" >&2 return 1 else return 0 @@ -504,6 +442,27 @@ project_sources_archive_missing_check() { fi } +project_sources_prepare() { + local project="$1" + local sources_path="$2" + + # Not implemented yet / May end up not being needed + #project_sources_prepare_blobs + project_sources_prepare_patch "$project" "$sources_path" "$@" +} + +project_sources_prepare_patch() { + local project="$1" + local sources_path="$2" + + local project_path="$(project_path "$project")" + local patches_path="$project_path/$PATCHES" + + for patch in "$patches_path"/[!.]*.@(patch|diff); do + diff_patch_file "$sources_path" "$patch" + done +} + project_blobs_path() { local project=$1 shift @@ -529,12 +488,12 @@ project_blobs_path() { if [ -f "$blobs_path" ] then - echo "$blobs_path" + printf '%s\n' "$blobs_path" return fi done - echo "$blobs_path" + printf '%s\n' "$blobs_path" } project_blobs_ignore_path() { @@ -562,7 +521,7 @@ project_blobs_ignore_path() { if [ -f "$blobs_ignore_path" ] then - echo "$blobs_ignore_path" + printf '%s\n' "$blobs_ignore_path" return fi done @@ -590,55 +549,53 @@ project_arguments_targets() { } project_usage_actions() { - local project=$1 + local project="$1" shift - printf "\nGeneric actions:\n" + printf '\n%s\n' 'Generic actions:' - for action in $PROJECT_ACTIONS_GENERIC - do - if function_check "$action" - then - printf " $action\n" - fi - done + ( + for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do + if function_check "$action"; then + printf '%s\n' " $action" + fi + done + ) - if [ $# -gt 0 ] - then - printf "\nSpecific actions:\n" + if [[ "$#" -gt 0 ]]; then + printf '\n%s\n' 'Specific actions:' - for action in "$@" - do - printf " $action\n" - done + ( + for action in "$@"; do + printf '%s\n' " $action" + done + ) fi } project_usage_arguments() { - local project=$1 + local project="$1" shift - printf "\nArguments:\n" + printf '\n%s\n' 'Arguments:' - project_usage_arguments_recursive "$project" " " "$@" + project_usage_arguments_recursive "$project" ' ' "$@" } project_usage_arguments_recursive() { - local project=$1 + local project="$1" shift - local spacing=$1 + local spacing="$1" shift local action_helper_arguments local argument - action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" ) + action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")" - if ! [ -z "$action_helper_arguments" ] - then - echo "$action_helper_arguments" | while read argument - do - printf "$spacing$argument\n" + if [[ -n "$action_helper_arguments" ]]; then + for argument in $action_helper_arguments; do + printf '%s\n' "$spacing$argument" project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument" done fi @@ -676,6 +633,45 @@ project_download_check_git() { git_project_prepare_check "$project" "$repository" "$@" } +project_download_archive() { + local project="$1" + shift + local archive_uri="$1" + shift + local archive_dsig_uri="$1" + + local archive="${archive_uri##*/}" + local compress_fmt="${archive##*.tar}" + + local directory_prefix="$root/$SOURCES" + local archive_path="$root/$SOURCES/$archive" + local sources_path="$root/$SOURCES/$project" + + if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then + ARCHIVE="tar$compress_fmt" + fi + + # TODO: Split this code block into separate functions + # Archive verification will be included at that point in time + if ! project_sources_directory_filled_check "$project"; then + download_wrapper "$directory_prefix" "$archive_uri" "$archive_dsig_uri" + archive_extract "$archive_path" "$directory_prefix" + + mv "${archive_path%.tar*}" "$sources_path" + fi + + # Patch the source, if necessary + project_sources_prepare "$project" "$sources_path" +} + +project_download_check_archive() { + local project="$1" + local sources_path="$2" + + # TODO: Write the following function + #project_sources_archive_extract_check "$project" "$sources_path" +} + project_extract() { local project=$1 shift @@ -684,7 +680,7 @@ project_extract() { if ! project_sources_directory_filled_check "$project" "$repository" "$@" then - project_sources_archive_missing_error "$project" "$@" + project_sources_archive_missing_error "$project" "$@" || return 1 project_sources_archive_extract "$project" "$@" fi } @@ -727,7 +723,7 @@ project_update_check_git() { requirements "git" - if git_project_check "$repository" + if ! git_project_check "$repository" then # Git repository should always be updated (even if upstream didn't progress). # For instance, this is useful for testing new versions of patches without changing revision. @@ -767,13 +763,13 @@ project_build_check() { continue fi - while read rule + while read -r rule do - source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" ) + source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" ) source_path="$build_path/$source" # Source may contain a wildcard. - path_wildcard_expand "$source_path" | while read source_file_path + path_wildcard_expand "$source_path" | while read -r source_file_path do if ! [ -f "$source_file_path" ] && ! [ -d "$source_file_path" ] then @@ -796,19 +792,19 @@ project_build_path() { build_path="$build_path-$argument" done - echo "$build_path" + printf '%s\n' "$build_path" } project_build_directory_missing_empty_error() { local project=$1 shift - local arguments=$@ + local arguments="$*" local build_path=$( project_build_path "$project" "$@" ) if ! directory_filled_check "$build_path" then - printf "Build directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2 + printf '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 return 1 else return 0 @@ -849,19 +845,19 @@ project_install() { project_build_directory_missing_empty_error "$project" "$@" - while read rule + while read -r rule do - source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" ) + source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" ) source_path="$build_path/$source" - destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" ) + destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" ) destination_path="$install_path/$destination" destination_directory_path=$( dirname "$destination_path" ) mkdir -p "$destination_directory_path" # Source may contain a wildcard. - path_wildcard_expand "$source_path" | while read source_file_path + path_wildcard_expand "$source_path" | while read -r source_file_path do cp -rT "$source_file_path" "$destination_path" done @@ -890,19 +886,19 @@ project_install() { continue fi - while read rule + while read -r rule do - source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" ) + source=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g" ) source_path="$project_path/$INSTALL/$path/$source" - destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" ) + destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" ) destination_path="$install_path/$destination" destination_directory_path=$( dirname "$destination_path" ) mkdir -p "$destination_directory_path" # Source may contain a wildcard. - path_wildcard_expand "$source_path" | while read source_file_path + path_wildcard_expand "$source_path" | while read -r source_file_path do cp -rT "$source_file_path" "$destination_path" done @@ -943,9 +939,9 @@ project_install_check() { project_build_directory_missing_empty_error "$project" "$@" - while read rule + while read -r rule do - destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" ) + destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" ) destination_path="$install_path/$destination" if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ] @@ -977,9 +973,9 @@ project_install_check() { continue fi - while read rule + while read -r rule do - destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" ) + destination=$( printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g" ) destination_path="$install_path/$destination" if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ] @@ -1002,19 +998,19 @@ project_install_path() { install_path="$install_path-$argument" done - echo "$install_path" + printf '%s\n' "$install_path" } project_install_directory_missing_empty_error() { local project=$1 shift - local arguments=$@ + local arguments="$*" local install_path=$( project_install_path "$project" "$@" ) if ! directory_filled_check "$install_path" then - printf "Install directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2 + printf '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty" >&2 return 1 else return 0 @@ -1038,7 +1034,7 @@ project_release_path() { release_path="$release_path/$project" fi - echo "$release_path" + printf '%s\n' "$release_path" } project_release_archive_path() { @@ -1056,9 +1052,9 @@ project_release_archive_path() { path="$path-$argument" done - local archive_path="$release_path/$path.$TAR_XZ" + local archive_path="$release_path/$path.$ARCHIVE" - echo "$archive_path" + printf '%s\n' "$archive_path" } project_release_rootfs_path() { @@ -1076,9 +1072,9 @@ project_release_rootfs_path() { path="$path-$argument" done - local rootfs_path="$release_path/$path.$TAR_XZ" + local rootfs_path="$release_path/$path.$ARCHIVE" - echo "$rootfs_path" + printf '%s\n' "$rootfs_path" } project_release_sources_archive_path() { @@ -1109,22 +1105,22 @@ project_release_sources_archive_path() { if ! [ -z "$release_path" ] then - local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$TAR_XZ" + local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$ARCHIVE" - echo "$archive_path" + printf '%s\n' "$archive_path" fi } project_release_sources_archive_create() { local project=$1 shift - local arguments=$@ + local arguments="$*" local repository=$project local archive_path=$( project_release_sources_archive_path "$project" "$@" ) local sources_path=$( project_sources_path "$project" "$repository" "$@" ) - printf "Releasing sources archive for $project (with ${arguments:-no argument})\n" + printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})" archive_create "$archive_path" "$sources_path" file_verification_create "$archive_path" @@ -1196,10 +1192,10 @@ project_release_install() { project_install_directory_missing_empty_error "$project" "$@" - local files=$( cd "$install_path" && find -type f || true ) + local files=$( find "$install_path" -type f || true ) local file - echo "$files" | while read file + printf '%s\n' "$files" | while read -r file do path="$release_path/$file" directory_path=$( dirname "$path" ) @@ -1223,10 +1219,10 @@ project_release_install_check() { project_install_directory_missing_empty_error "$project" "$@" - local files=$( cd "$install_path" && find -type f || true ) + local files=$( find "$install_path" -type f || true ) local file - echo "$files" | while read file + printf '%s\n' "$files" | while read -r file do path="$release_path/$file" @@ -1257,12 +1253,12 @@ project_release_install_archive_create() { shift local prefix=$1 shift - local arguments=$@ + local arguments="$*" local install_path=$( project_install_path "$project" "$@" ) local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" ) - printf "Releasing $prefix archive for $project (with ${arguments:-no argument})\n" + printf '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})" archive_create "$archive_path" "$install_path" file_verification_create "$archive_path" @@ -1305,12 +1301,12 @@ project_release_install_rootfs_create() { shift local prefix=$1 shift - local arguments=$@ + local arguments="$*" local install_path=$( project_install_path "$project" "$@" ) local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" ) - printf "Releasing $prefix rootfs for $project (with ${arguments:-no argument})\n" + printf '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})" rootfs_create "$rootfs_path" "$install_path" file_verification_create "$rootfs_path" @@ -1421,7 +1417,7 @@ project_file_path() { return 1 fi - echo "$file_path" + printf '%s\n' "$file_path" } project_file_test() { |