Skip to content

Commit

Permalink
ioc: don't prune pre-selected directories.
Browse files Browse the repository at this point in the history
When pruning modules, some of them might contain special cases where it
is harder to automatically detect in the pruning algorithm. While users
could workaround this by specifying such special paths under APP_DIRS,
this can be handled here by adding extra tooling to be used by modules.

Introduce a way for modules to specify extra paths that must be kept,
besides those detected by lnls-prune-artifacts. Do this through a
.lnls-keep-paths file that specifies all relative paths (directories or
files) whose contents must be kept. Paths may be globs, so that they are
resolved based on their bash expansion, avoiding hard-coded options when
ambiguity can be automatically resolved.

These exceptions are considered for all ancestors of a candidate to
removal, so that they are not restricted to EPICS modules themselves.
This eases implementation because we won't need to detect which parent
is a module and should contain .lnls-keep-paths, and instead simply
traverse the whole ancestor list looking if any of them defines one.
  • Loading branch information
henriquesimoes committed Dec 13, 2024
1 parent c8e0638 commit aa63d0a
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions base/lnls-prune-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,42 @@ get_used_epics_modules() {
filter_out_paths "$all_modules" "$unused_modules"
}

# Traverse ancestor directories of each provided path, and concatenate all
# their .lnls-keep-paths defined entries as absolute paths.
get_defined_paths_to_keep() {
for path; do
if [ "${path:0:1}" != "/" ]; then
>&2 echo "error: get_defined_paths_to_keep() expects absolute paths, but got '$path'"
exit 1
fi

while true; do
keep_path_file="$path/.lnls-keep-paths"

if [ -f "$keep_path_file" ]; then
keep_paths=$(cat "$keep_path_file")

for keep_path in $keep_paths; do
# output it as an absolute path
realpath "$path"/$keep_path
done
fi

[ "$path" == "/" ] && break

path=$(dirname $path)
done
done | sort -u
}

prune_module_dirs() {
module=$1

module_dirs=$(find $module -type d)
keep_paths=$(cat << EOF
$(find_shared_libraries $module)
$(find $module -type f -regex ".*\.\(cmd\|db\|template\|req\|substitutions\)" -printf "%h\n" | sort -u)
$(get_defined_paths_to_keep $module)
EOF
)

Expand Down Expand Up @@ -154,11 +183,16 @@ remove_unused_shared_libraries() {
remove_libs=$(echo "$remove_libs" | grep -vx $lib)
done

keep_paths=$(get_defined_paths_to_keep $remove_libs)

for lib in $remove_libs; do
size=$(du -hs $lib | cut -f 1)
# if library is not found inside any $keep_dirs, remove it
if find $keep_paths -path "$lib" -exec false {} +; then
size=$(du -hs $lib | cut -f 1)

echo "Removing shared library '$lib' ($size)"
rm -f ${lib%.so*}.so*
echo "Removing shared library '$lib' ($size)"
rm -f ${lib%.so*}.so*
fi
done
}

Expand Down

0 comments on commit aa63d0a

Please sign in to comment.