Skip to content

Commit

Permalink
ioc: prune module directories from non-static builds.
Browse files Browse the repository at this point in the history
Modules may contain several artifacts, including configuration files,
graphical interface files and other repository artifacts that do not
need to be in the IOC image.

Remove them all except the ones containing EPICS database (`.db` and
`.template`) or autosave requirement (`.req`) files, besides shared
libraries. Binaries directory (`bin`) is also removed, as only $REPONAME
and $RUNDIR should contain target executables, which are filtered out
from the list.
  • Loading branch information
henriquesimoes committed Nov 6, 2024
1 parent 089b0bc commit b2764a3
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions base/lnls-prune-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ find_elf_executables() {
done < <(find $targets -type f -executable)
}

find_shared_libs() {
libs=$(find_elf_executables $@)

echo "$libs" | grep -E "*.so(.[0-9]+)*$" | sort -u
}

find_linked_libraries() {
executables=$(find_elf_executables $@)

Expand Down Expand Up @@ -86,9 +92,7 @@ remove_static_libs() {

remove_unused_shared_libs() {
used_libs=$(find_linked_libraries $@)

remove_libs=$(find_elf_executables /opt /usr/local)
remove_libs=$(echo "$remove_libs" | grep -E "*.so(.[0-9]+)*$" | sort -u)
remove_libs=$(find_shared_libs /opt /usr/local)

for lib in $used_libs; do
remove_libs=$(echo "$remove_libs" | grep -vx $lib)
Expand All @@ -102,7 +106,27 @@ remove_unused_shared_libs() {
done
}

remove_unused_epics_modules() {
prune_module_dirs() {
module=$1

keep_paths="
$(find_shared_libs $module)
$(find $module -type f -regex ".*\.\(db\|template\|req\)" -printf "%h\n" | sort -u)
"

while read -r candidate; do
[ -d $candidate ] || continue

if [[ ! $keep_paths =~ "$candidate".* ]]; then
size=$(du -hs $candidate | cut -f 1)

printf "Removing directory '$candidate' ($size)...\n"
rm -rf $candidate
fi
done < <(find $module -type d)
}

clean_up_epics_modules() {
targets=$@

all_modules=$(get_all_epics_modules)
Expand All @@ -122,8 +146,15 @@ remove_unused_epics_modules() {
echo "Removing module '$module' ($size)..."
rm -rf $module
done

prune_dirs=$(filter_out_paths "$used_modules" "$targets")

for dir in $prune_dirs; do
echo "Pruning module '$dir'..."
prune_module_dirs $dir
done
}

remove_unused_epics_modules $@
clean_up_epics_modules $@
remove_static_libs /opt
remove_unused_shared_libs $@

0 comments on commit b2764a3

Please sign in to comment.