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 8, 2024
1 parent 63ee161 commit 1680f69
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions base/lnls-prune-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,27 @@ get_used_epics_modules() {
filter_out_paths "$all_modules" "$unused_modules"
}

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 @@ -97,6 +117,13 @@ 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_static_libs() {
Expand Down Expand Up @@ -129,6 +156,6 @@ remove_unused_shared_libs() {
done
}

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

0 comments on commit 1680f69

Please sign in to comment.