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. `bin` is also removed, as only $REPONAME and $RUNDIR should
contain target executables.
  • Loading branch information
henriquesimoes committed Oct 15, 2024
1 parent 1a684b3 commit affe302
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions base/lnls-prune-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ get_linked_libraries() {
done | sort -u
}

find_shared_libs() {
search_paths=$@

libs=$(find $search_paths -type f -executable -name *.so*)

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

get_used_epics_modules() {
targets=$@

Expand Down Expand Up @@ -62,9 +70,7 @@ remove_unused_shared_libs() {
targets=$@

used_libs=$(get_linked_libraries $targets)

remove_libs=$(find /opt /usr/local -type f -executable -name *.so*)
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 -v $lib)
Expand All @@ -78,7 +84,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)
"

for candidate in $(find $module -type d); 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
}

clean_up_epics_modules() {
targets=$@

used_modules=$(get_used_epics_modules $targets)
Expand All @@ -89,10 +115,12 @@ remove_unused_epics_modules() {

echo "Removing module '$module' ($size)..."
rm -rf $module
elif [ -d $module/lib ]; then
prune_module_dirs $module
fi
done
}

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

0 comments on commit affe302

Please sign in to comment.