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 Jun 5, 2024
1 parent 49f4ce3 commit 573785b
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 @@ -15,6 +15,14 @@ get_linked_libraries() {
done | sort | uniq
}

find_shared_libs() {
search_paths=$@

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

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

get_used_epics_modules() {
targets=$@

Expand Down Expand Up @@ -53,9 +61,7 @@ remove_static_libs() {
remove_unused_shared_libs() {
targets=$@

remove_libs=$(find /opt /usr/local -type f -executable -name *.so* -print)
remove_libs=$(echo "$remove_libs" | grep -E "*.so(.[0-9]+)*$" | sort | uniq)

remove_libs=$(find_shared_libs /opt /usr/local)
used_libs=$(get_linked_libraries $targets)

for lib in $used_libs; do
Expand All @@ -70,7 +76,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 | uniq)
"

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 @@ -81,10 +107,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 $target_paths
clean_up_epics_modules $target_paths
remove_static_libs /opt
remove_unused_shared_libs $target_paths

0 comments on commit 573785b

Please sign in to comment.