[PATCH] Nested app support for complete-bundle.sh - Mailing list pgadmin-hackers

From Florian G. Pflug
Subject [PATCH] Nested app support for complete-bundle.sh
Date
Msg-id 4620F8E5.6000107@phlo.org
Whole thread Raw
Responses Re: [PATCH] Nested app support for complete-bundle.sh  (Dave Page <dpage@postgresql.org>)
List pgadmin-hackers
Hi

That symlinking-Framworks idea proved to be easier than I
initially thought - here is a patch ;-)

This patch also moves pkg to the end of the list of subdirs
in the main Makefile.am. If pkg is listed before debugger,
than complete-bundle.sh is run _before_ the debugger binary
is copied into the bundle, which obviously causes all kinds
of trouble ;-)

greetings, Florian Pflug
Index: Makefile.am
===================================================================
--- Makefile.am    (revision 6194)
+++ Makefile.am    (working copy)
@@ -9,7 +9,7 @@

 AUTOMAKE_OPTIONS = foreign

-SUBDIRS = branding i18n pgadmin pkg xtra debugger
+SUBDIRS = branding i18n pgadmin xtra debugger pkg

 EXTRA_DIST = \
     $(top_srcdir)/BUGS \
Index: pkg/mac/complete-bundle.sh
===================================================================
--- pkg/mac/complete-bundle.sh    (revision 6194)
+++ pkg/mac/complete-bundle.sh    (working copy)
@@ -8,47 +8,70 @@

 test -d "$bundle/Contents/Frameworks" || mkdir -p "$bundle/Contents/Frameworks" || exit 1

-echo "Completing bundle: $bundle"
+function CompleteSingleApp() {
+    local bundle=$1 tag=$(basename "$1") todo todo_old fw_relpath lib lib_bn nested_app na_relpath

-cd "$bundle"
+    echo "Completing app: $bundle"
+    pushd "$bundle" > /dev/null

-todo=$(file `find ./ -perm +0111 ! -type d` | grep "Mach-O executable" | awk -F ':| ' '{ORS=" "; print $1}' | uniq)
+    #We skip nested apps here - those are treated specially
+    todo=$(file `find ./ -perm +0111 ! -type d ! -path "*.app/*" ! -name "*.app"` | grep "Mach-O executable" | awk -F
':|' '{ORS=" "; print $1}' | uniq) 

-echo "Found executables: $todo"
+    echo "App: $tag: Found executables: $todo"
+    while test "$todo" != ""; do
+        todo_old=$todo ;
+        todo="" ;
+        for todo_obj in $todo_old; do
+            echo "App: $tag: Post-processing: $todo_obj"

-while test "$todo" != ""; do
-    todo_old=$todo ;
-    todo="" ;
-    for todo_obj in $todo_old; do
-        echo "Post-processing: $todo_obj"
+            #Figure out the relative path from todo_obj to Contents/Frameworks
+            fw_relpath=$(echo "$todo_obj" |\
+                sed -n 's|^\(\.//*\)\(\([^/][^/]*/\)*\)[^/][^/]*$|\2|gp' | \
+                sed -n 's|[^/][^/]*/|../|gp' \
+            )"Contents/Frameworks"

-        #Figure out the relative path from todo_obj to Contents/Frameworks
-        fw_relpath=$(echo "$todo_obj" |\
-            sed -n 's|^\(\.//*\)\(\([^/][^/]*/\)*\)[^/][^/]*$|\2|gp' | \
-            sed -n 's|[^/][^/]*/|../|gp' \
-        )"Contents/Frameworks"
-
-        #Find all libraries $todo_obj depends on, but skip system libraries
-        for lib in $(
-            otool -L $todo_obj | \
-            sed -n 's|^.*[[:space:]]\([^[:space:]]*\.dylib\).*$|\1|p' | \
-            egrep -v '^(/usr/lib)|(/System)|@executable_path@' \
-        ); do
-            lib_bn="$(basename "$lib")" ;
-            if ! test -f "Contents/Frameworks/$lib_bn"; then
-                echo "Adding library: $lib_bn (because of: $todo_obj)"
-                cp "$lib" "Contents/Frameworks/$lib_bn"
-                chmod 755 "Contents/Frameworks/$lib_bn"
-                install_name_tool \
-                    -id "$lib_bn" \
-                    "Contents/Frameworks/$lib_bn" || exit 1
-                todo="$todo .//Contents/Frameworks/$lib_bn"
-            fi
-            install_name_tool -change \
-                "$lib" \
-                "@executable_path/$fw_relpath/$lib_bn" \
-                "$todo_obj" || exit 1
+            #Find all libraries $todo_obj depends on, but skip system libraries
+            for lib in $(
+                otool -L $todo_obj | \
+                sed -n 's|^.*[[:space:]]\([^[:space:]]*\.dylib\).*$|\1|p' | \
+                egrep -v '^(/usr/lib)|(/System)|@executable_path@' \
+            ); do
+                lib_bn="$(basename "$lib")" ;
+                if ! test -f "Contents/Frameworks/$lib_bn"; then
+                    echo "App: $tag: Adding library: $lib_bn (because of: $todo_obj)"
+                    cp "$lib" "Contents/Frameworks/$lib_bn"
+                    chmod 755 "Contents/Frameworks/$lib_bn"
+                    install_name_tool \
+                        -id "$lib_bn" \
+                        "Contents/Frameworks/$lib_bn" || exit 1
+                    todo="$todo ./Contents/Frameworks/$lib_bn"
+                fi
+                install_name_tool -change \
+                    "$lib" \
+                    "@executable_path/$fw_relpath/$lib_bn" \
+                    "$todo_obj" || exit 1
+            done
         done
     done
-done
-echo "Bundle completed"
+
+    #We handle only one level here, because this is recursive anyway
+    for nested_app in $(find ./ -type d -name "*.app" ! -path "*.app/*"); do
+        echo "App: $tag: Post-processing nested app: $nested_app"
+
+        if ! test -d "$nested_app/Contents/Frameworks"; then
+            echo "App: "$(basename "$nested_app")": Symlinking Frameworks-folder to parent $bundle"
+            na_relpath=$(echo "$nested_app" |\
+                sed -n 's|^\(\.//*\)\(\([^/][^/]*/\)*\)[^/][^/]*$|\2|gp' | \
+                sed -n 's|[^/][^/]*/|../|gp' \
+            )"Contents/Frameworks"
+            ln -s "../../$na_relpath" "$nested_app/Contents/Frameworks"
+        fi
+
+        CompleteSingleApp "$nested_app"
+    done
+
+    echo "App completed: $bundle"
+    popd > /dev/null
+}
+
+CompleteSingleApp "$bundle"

pgadmin-hackers by date:

Previous
From: "Florian G. Pflug"
Date:
Subject: Debugger, Nested Bundles & @executable_path
Next
From: svn@pgadmin.org
Date:
Subject: SVN Commit by hiroshi: r6195 - in trunk/pgadmin3: . pkg/mac