Skip to content

Commit f06973c

Browse files
committed
fix(automation-tools): fixed library search from ldd and filtered out /tmp /home /run local path for searching.
1 parent 4d93864 commit f06973c

File tree

2 files changed

+94
-26
lines changed

2 files changed

+94
-26
lines changed

automation-tools/assembler.sh

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,35 +1065,59 @@ process_library_file() {
10651065
# Clear output file
10661066
> "$output_file"
10671067

1068+
# Load filtered patterns from filtered_libs.txt
1069+
local filtered_libs_file="$(dirname "$0")/../filtered_libs.txt"
1070+
local filtered_patterns=()
1071+
if [[ -f "$filtered_libs_file" ]]; then
1072+
while IFS= read -r fline; do
1073+
[[ -z "$fline" || "$fline" =~ ^[[:space:]]*# ]] && continue
1074+
filtered_patterns+=("$fline")
1075+
done < "$filtered_libs_file"
1076+
fi
1077+
10681078
while IFS= read -r line; do
10691079
# Skip empty lines and comments
10701080
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
1071-
1072-
# Check if line looks like ldd output
1073-
if [[ "$line" =~ ^[[:space:]]*([^[:space:]]+)[[:space:]]=\>[[:space:]]*(not\ found|/.*)[[:space:]]*(\(.*\))?$ ]]; then
1074-
# Extract library name from ldd output (standard format: name => path)
1075-
local lib_name="${BASH_REMATCH[1]}"
1076-
echo "$lib_name" >> "$output_file"
1077-
log i "📚 Found library from ldd: $lib_name" "$logfile"
1081+
1082+
local lib_name=""
1083+
# Migliorata: estrai nome completo con versione (es: libzip.so.5)
1084+
if [[ "$line" =~ ^[[:space:]]*([a-zA-Z0-9_\-]+\.so(\.[0-9]+)*)([[:space:]]|=\u003e).* ]]; then
1085+
lib_name="${BASH_REMATCH[1]}"
1086+
extracted_from_ldd=true
10781087
elif [[ "$line" =~ ^[[:space:]]*(/[^[:space:]]+)[[:space:]]+(\(.*\))$ ]]; then
1079-
# Extract library name from ldd output (dynamic linker format: /path (address))
1080-
local lib_path="${BASH_REMATCH[1]}"
1081-
local lib_name=$(basename "$lib_path")
1082-
echo "$lib_name" >> "$output_file"
1083-
log i "🔗 Found dynamic linker from ldd: $lib_name" "$logfile"
1084-
elif [[ "$line" =~ ^[[:space:]]*([^[:space:]]+\.(so|so\.[0-9]+(\.[0-9]+)*)).*$ ]]; then
1085-
# Direct library name
1086-
local lib_name="${BASH_REMATCH[1]}"
1087-
echo "$lib_name" >> "$output_file"
1088-
log i "📚 Found library: $lib_name" "$logfile"
1088+
lib_path="${BASH_REMATCH[1]}"
1089+
lib_name=$(basename "$lib_path")
1090+
elif [[ "$line" =~ ^[[:space:]]*([a-zA-Z0-9_\-]+\.so(\.[0-9]+)*).*$ ]]; then
1091+
lib_name="${BASH_REMATCH[1]}"
10891092
elif [[ "$line" =~ ^[[:space:]]*plugins/ ]]; then
1090-
# Plugin directory - pass through as is
10911093
echo "$line" >> "$output_file"
1092-
log i "🔌 Found plugin directory: $line" "$logfile"
1094+
log i "� Found plugin directory: $line" "$logfile"
1095+
continue
10931096
else
1094-
# Unknown format, log warning but continue
10951097
log w "❓ Unrecognized library format: $line" "$logfile"
1098+
continue
1099+
fi
1100+
1101+
# Check if library is filtered
1102+
local is_filtered=false
1103+
for pattern in "${filtered_patterns[@]}"; do
1104+
if [[ "$lib_name" == $pattern ]]; then
1105+
log w "⏭️ Skipping $lib_name as it's filtered in filtered_libs.txt" "$logfile"
1106+
is_filtered=true
1107+
break
1108+
fi
1109+
done
1110+
if [[ "$is_filtered" == true ]]; then
1111+
continue
1112+
fi
1113+
1114+
echo "$lib_name" >> "$output_file"
1115+
if [[ "$extracted_from_ldd" == true ]]; then
1116+
log i "📚 Extracted library from ldd dump: $lib_name" "$logfile"
1117+
else
1118+
log i "📚 Found library: $lib_name" "$logfile"
10961119
fi
1120+
extracted_from_ldd=false
10971121
done < "$input_file"
10981122

10991123
log d "✅ Processed component library file, output written to: $output_file" "$logfile"

automation-tools/search_libs.sh

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ search_libs() {
1010
# Use absolute paths to avoid confusion
1111
local component_lib_dir="$(realpath -m "${FLATPAK_DEST}/../lib" 2>/dev/null)"
1212
local artifacts_lib_dir="$(realpath -m "${FLATPAK_DEST}/lib")"
13-
14-
SEARCH_PATHS=("$artifacts_lib_dir" "$component_lib_dir" /app /usr/lib /usr/lib64)
13+
14+
# Add squashfs-root (AppImage extracted) if present
15+
local squashfs_root_dir="${component}/squashfs-root"
16+
local squashfs_lib_dir="${squashfs_root_dir}/lib"
17+
if [[ -d "$squashfs_root_dir" ]]; then
18+
SEARCH_PATHS=("$artifacts_lib_dir" "$component_lib_dir" "$squashfs_lib_dir" "$squashfs_root_dir" "$squashfs_root_dir/usr/lib" /app /usr/lib /usr/lib64)
19+
else
20+
SEARCH_PATHS=("$artifacts_lib_dir" "$component_lib_dir" /app /usr/lib /usr/lib64)
21+
fi
22+
# Exclude /run from search
1523
mkdir -p "${FLATPAK_DEST}/lib/"
1624

1725
lib_list="$1"
@@ -24,21 +32,58 @@ search_libs() {
2432
# Load libraries from the provided list
2533
log d "🔍 Searching for libraries from: \"$lib_list\"..." "$logfile"
2634
mapfile -t all_libs < <(grep -v '^\s*#' "$lib_list" | sort -u)
35+
36+
# Load filtered patterns from filtered_libs.txt
37+
local filtered_libs_file="$(dirname "$0")/../filtered_libs.txt"
38+
local filtered_patterns=()
39+
if [[ -f "$filtered_libs_file" ]]; then
40+
while IFS= read -r line; do
41+
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
42+
filtered_patterns+=("$line")
43+
done < "$filtered_libs_file"
44+
fi
2745
log i "📦 Loaded ${#all_libs[@]} libraries from list" "$logfile"
2846

2947
need_to_debug=false
3048
not_found_libs=()
3149

3250
for lib in "${all_libs[@]}"; do
51+
# Salta la ricerca se la libreria è filtrata
52+
local is_filtered=false
53+
for pattern in "${filtered_patterns[@]}"; do
54+
if [[ "$lib" == $pattern ]]; then
55+
echo "⏭️ Skipping $lib as it's filtered in filtered_libs.txt"
56+
is_filtered=true
57+
break
58+
fi
59+
done
60+
if [[ "$is_filtered" == true ]]; then
61+
continue
62+
fi
3363
# Check if library is already present in artifacts (from AppImage extraction)
3464
if [[ -f "${FLATPAK_DEST}/lib/$lib" ]]; then
3565
echo "📦 Using native library from component: $lib (skipping external copy)"
3666
continue
3767
fi
38-
39-
path=$(find "${SEARCH_PATHS[@]}" -type f -name "$lib" 2>/dev/null | head -n 1)
68+
echo "[DEBUG] Searching for $lib in paths:"
69+
for search_path in "${SEARCH_PATHS[@]}"; do
70+
echo " - $search_path"
71+
done
72+
path=$(find "${SEARCH_PATHS[@]}" -type f -name "$lib" \
73+
! -path "/run/*" \
74+
! -path "/home/*" \
75+
! -path "/tmp/*" 2>/dev/null | tee /tmp/search_libs_debug.log | head -n 1)
76+
if [ -n "$path" ]; then
77+
echo "[DEBUG] Found $lib at: $path"
78+
fi
4079
if [ -z "$path" ]; then
41-
path=$(find "${SEARCH_PATHS[@]}" -type f -iname "*$lib*" 2>/dev/null | head -n 1)
80+
path=$(find "${SEARCH_PATHS[@]}" -type f -iname "*$lib*" \
81+
! -path "/run/*" \
82+
! -path "/home/*" \
83+
! -path "/tmp/*" 2>/dev/null | tee -a /tmp/search_libs_debug.log | head -n 1)
84+
if [ -n "$path" ]; then
85+
echo "[DEBUG] Found $lib (variant) at: $path"
86+
fi
4287
if [ -z "$path" ]; then
4388
# Special handling: if libopenh264.so.7 is requested, create symlink from .2.5.1 if available
4489
if [ "$lib" == "libopenh264.so.7" ] && [ -f "${FLATPAK_DEST}/lib/libopenh264.so.2.5.1" ]; then
@@ -51,7 +96,6 @@ search_libs() {
5196
continue
5297
fi
5398
fi
54-
5599
dest="${FLATPAK_DEST}/lib/$(basename "$path")"
56100
if [ "$path" != "$dest" ]; then
57101
cp -fL "$path" "${FLATPAK_DEST}/lib/"

0 commit comments

Comments
 (0)