From 33ddc979ce4e2247744be0979890238b6b90864c Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 16 Jul 2019 22:21:22 -0500 Subject: libs/project: Complete project_sources_prepare() The method in which project sources are prepared from either extracted non-git source archives or sources under $PROJECTS/$project/$SOURCES are comparable to preparing git sources. This makes knowledge of the source preparation process mostly transferable across the build system regardless whether git is involved or not. --- libs/project | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/libs/project b/libs/project index 8f4ef233..908f8942 100755 --- a/libs/project +++ b/libs/project @@ -521,23 +521,75 @@ project_sources_archive_missing_check() { project_sources_prepare() { local project="$1" - local sources_path="$2" + shift + + project_sources_prepare_blobs "$project" "$@" + project_sources_prepare_patch "$project" "$@" +} + +project_sources_prepare_blobs() { + local project=$1 + shift + + local sources_path=$(project_sources_path "$project" "$project" "$@") + + ( + cd "$sources_path" || exit 1 - # Not implemented yet / May end up not being needed - #project_sources_prepare_blobs - project_sources_prepare_patch "$project" "$sources_path" "$@" + project_blobs "$project" "$@" | while IFS='' read -r blob; do + rm -f -- "$blob" + done + ) } project_sources_prepare_patch() { local project="$1" - local sources_path="$2" + shift - local project_path="$(project_path "$project")" - local patches_path="$project_path/$PATCHES" + local argument + local path + + for argument in "$@"; do + if [[ -z $path ]]; then + path=$argument + else + path=$path/$argument + fi + done + + if [[ -n $project ]]; then + project_sources_patch_recursive "$project" "$path" + fi +} + +project_sources_prepare_check() { + local project=$1 + shift + + local sources_path=$(project_sources_path "$project" "$project" "$@") + + directory_filled_check "$sources_path" +} + +project_sources_patch_recursive() { + local project=$1 + local path=$2 + + local project_path=$(project_path "$project") + local sources_path=$(project_sources_path "$project" "$project" "$@") + local patches_path=$project_path/$PATCHES/$path + + if ! [[ -d $project_path/$PATCHES ]]; then + return 0 + fi for patch in "$patches_path"/[!.]*.@(patch|diff); do - diff_patch "$sources_path" "$patch" + diff_patch "$sources_path" "$patch" || return 1 done + + if [[ $path != . ]]; then + project_sources_patch_recursive "$project" "$(dirname "$path")" + fi } project_blobs() { @@ -751,8 +803,7 @@ project_download_archive() { mv "${archive_path%.tar*}" "$sources_path" fi - # Patch the source, if necessary - project_sources_prepare "$project" "$sources_path" + project_sources_prepare "$project" } project_download_check_archive() { -- cgit v1.2.3-70-g09d2 From 089265a306c58b52a0f90dde99b7cc6af3f25e11 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 16 Jul 2019 22:38:34 -0500 Subject: Avoid redundant patching when recursively patching If a path is not supplied to project_sources_patch_recursive() or git_project_patch_recursive() then it will attempt to apply the set of patches located at $PROJECTS/$project/$PATCHES (the top-level patches directory) twice. Checking to see if $path is of non-zero length avoids this issue. --- libs/git | 2 +- libs/project | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/git b/libs/git index 429d4783..2cde3dd3 100755 --- a/libs/git +++ b/libs/git @@ -312,7 +312,7 @@ git_project_patch_recursive() { git_patch "$repository_path" "$branch" "$patch" || return 1 done - if [[ $path != . ]]; then + if [[ -n $path && $path != . ]]; then git_project_patch_recursive "$project" "$repository" "$branch" "$(dirname "$path")" fi } diff --git a/libs/project b/libs/project index 908f8942..34b139a5 100755 --- a/libs/project +++ b/libs/project @@ -587,7 +587,7 @@ project_sources_patch_recursive() { diff_patch "$sources_path" "$patch" || return 1 done - if [[ $path != . ]]; then + if [[ -n $path && $path != . ]]; then project_sources_patch_recursive "$project" "$(dirname "$path")" fi } -- cgit v1.2.3-70-g09d2 From 7f8a0e4bc1e94db325cd0348c92c6005b6fd84cf Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 16 Jul 2019 22:43:31 -0500 Subject: Add functions to safely apply patches to non-git sources project_sources_patch() is the equivalent to git_patch() when working with non-git sources. It should not be used with sources under a version control system. --- libs/common | 7 +++++++ libs/project | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/common b/libs/common index 06b411e1..b1091e4f 100755 --- a/libs/common +++ b/libs/common @@ -117,6 +117,13 @@ diff_patch() { patch -fd "$sources_path" -r - < "$patch_path" } +diff_patch_check() { + local sources_path=$1 + local patch_path=$2 + + patch -sfd "$sources_path" --dry-run < "$patch_path" > /dev/null 2>&1 +} + path_wildcard_expand() { local path=$@ diff --git a/libs/project b/libs/project index 34b139a5..b130af17 100755 --- a/libs/project +++ b/libs/project @@ -584,7 +584,7 @@ project_sources_patch_recursive() { fi for patch in "$patches_path"/[!.]*.@(patch|diff); do - diff_patch "$sources_path" "$patch" || return 1 + project_sources_patch "$sources_path" "$patch" || return 1 done if [[ -n $path && $path != . ]]; then @@ -608,6 +608,17 @@ project_blobs() { fi } +project_sources_patch() { + local sources_path=$1 + local patch_path=$2 + + if diff_patch_check "$sources_path" "$patch_path"; then + diff_patch "$sources_path" "$patch_path" + else + return 1 + fi +} + project_blobs_path() { local project=$1 shift -- cgit v1.2.3-70-g09d2