For example a source file 'mydir/myfile.sh' is now valid,
whereas before 'myfile.sh' would have needed to be placed in the same directory
as the PKGBUILD.

Fixes FS#43020

Signed-off-by: Ashley Whetter <[email protected]>
---
I've tested this by generating checksums, making a package, and
making a source package, all with downloadable and local files.
Local files were tested in both the PKGBUILD directory and a subdirectory.

This doesn't work for files that have been placed under a fake protocol to force
makepkg not to include the file in the source package
(for example 'file://a_sub_dir/my_huge_source_file.tar.gz').
 scripts/libmakepkg/source/file.sh.in  |  4 +++-
 scripts/libmakepkg/source/local.sh.in |  2 +-
 scripts/libmakepkg/util/source.sh.in  | 17 +++++++++++++++++
 scripts/makepkg.sh.in                 |  8 ++++++--
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/scripts/libmakepkg/source/file.sh.in 
b/scripts/libmakepkg/source/file.sh.in
index 20493a6..6f17884 100644
--- a/scripts/libmakepkg/source/file.sh.in
+++ b/scripts/libmakepkg/source/file.sh.in
@@ -87,7 +87,9 @@ extract_file() {
 
        local filepath=$(get_filepath "$file")
        rm -f "$srcdir/${file}"
-       ln -s "$filepath" "$srcdir/"
+       local intermediatedirs=$(get_intermediate_dirs "$file")
+       mkdir -p "$srcdir/$intermediatedirs"
+       ln -s "$filepath" "$srcdir/$intermediatedirs"
 
        if in_array "$file" "${noextract[@]}"; then
                # skip source files in the noextract=() array
diff --git a/scripts/libmakepkg/source/local.sh.in 
b/scripts/libmakepkg/source/local.sh.in
index 6a4b882..ef4829a 100644
--- a/scripts/libmakepkg/source/local.sh.in
+++ b/scripts/libmakepkg/source/local.sh.in
@@ -33,7 +33,7 @@ download_local() {
        local filepath=$(get_filepath "$netfile")
 
        if [[ -n "$filepath" ]]; then
-               msg2 "$(gettext "Found %s")" "${filepath##*/}"
+               msg2 "$(gettext "Found %s")" "$netfile"
        else
                local filename=$(get_filename "$netfile")
                error "$(gettext "%s was not found in the build directory and 
is not a URL.")" "$filename"
diff --git a/scripts/libmakepkg/util/source.sh.in 
b/scripts/libmakepkg/util/source.sh.in
index 9d4ba4a..f16d3c6 100644
--- a/scripts/libmakepkg/util/source.sh.in
+++ b/scripts/libmakepkg/util/source.sh.in
@@ -74,6 +74,10 @@ get_filename() {
                                filename=${filename%%.git*}
                        fi
                        ;;
+               local)
+                       # If it is a local file then leave the full path as is
+                       filename=$netfile
+                       ;;
                *)
                        # if it is just an URL, we only keep the last component
                        filename="${netfile##*/}"
@@ -142,3 +146,16 @@ get_downloadclient() {
 
        printf "%s\n" "$agent"
 }
+
+# Get the directories that exist before a source file
+get_intermediate_dirs() {
+       local netfile=$1
+       local intermediatedirs
+
+       if [[ "$(get_protocol "$netfile")" = 'local' ]] && [[ "$netfile" = */* 
]]
+       then
+               intermediatedirs=${netfile%/*}
+       fi
+
+       printf "%s\n" "$intermediatedirs"
+}
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index f80e37a..392b1b3 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1231,8 +1231,12 @@ create_srcpackage() {
                if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY 
== 2 )); then
                        local absfile
                        absfile=$(get_filepath "$file") || missing_source_file 
"$file"
-                       msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
-                       ln -s "$absfile" "$srclinks/$pkgbase"
+                       msg2 "$(gettext "Adding %s...")" "$(get_filename 
"$file")"
+
+                       local intermediatedirs="$(get_intermediate_dirs 
"$file")"
+                       mkdir -p "$srclinks/$pkgbase/$intermediatedirs"
+
+                       ln -s "$absfile" "$srclinks/$pkgbase/$intermediatedirs"
                fi
        done
 
-- 
2.8.0

Reply via email to