Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/extensions/detect-unused-extensions.sh
Views: 3956
## Configuration1export LOG_ALL_HOOK_TRACES=no # Should we log all hook function traces to stdout? (no, or level: wrn info)23## Hooks45# A honeypot wishful hooking. To make sure the whole thing works.6# This is exactly the kind of hooking this extension is meant to detect.7# This will never run, and should be detected below, but is handled specially and ignored.8# Note: this will never run, since we (hopefully) don't have a hook_point called 'wishful_hooking_example'.9function wishful_hooking_example__this_will_never_run() {10echo "WISHFUL HOOKING -- this will never run. I promise."11}1213# Run super late, hopefully at the last possible moment.14function extension_metadata_ready__999_detect_wishful_hooking() {15display_alert "Checking extensions and hooks for uncalled hook points"16declare -i found_honeypot_function=01718# Loop over the defined functions' keys. Find the info about the call. If not found, warn the user.19# shellcheck disable=SC2154 # hook-exported variable20for one_defined_function in ${!defined_hook_point_functions[*]}; do21local source_info defined_info line_info22defined_info="${defined_hook_point_functions["${one_defined_function}"]}"23source_info="${hook_point_function_trace_sources["${one_defined_function}"]}"24line_info="${hook_point_function_trace_lines["${one_defined_function}"]}"25stack="$(get_extension_hook_stracktrace "${source_info}" "${line_info}")"26if [[ "$source_info" != "" ]]; then27# log to debug log. it's reassuring.28echo "\$\$\$ Hook function stacktrace for '${one_defined_function}': '${stack}' (${defined_info})" >>"${EXTENSION_MANAGER_LOG_FILE}"29if [[ "${LOG_ALL_HOOK_TRACES}" != "no" ]]; then30display_alert "Hook function stacktrace for '${one_defined_function}'" "${stack}" "${LOG_ALL_HOOK_TRACES}"31fi32continue # found a caller, move on.33fi3435# special handling for the honeypot function. it is supposed to be always detected as uncalled.36if [[ "${one_defined_function}" == "wishful_hooking_example__this_will_never_run" ]]; then37# we expect this wishful hooking, it is done on purpose below, to make sure this code works.38found_honeypot_function=139else40# unexpected wishful hooking. Log and wrn the user.41echo "\$\$\$ Wishful hooking detected" "Function '${one_defined_function}' is defined (${defined_info}) but never called by the build." >>"${EXTENSION_MANAGER_LOG_FILE}"42display_alert "Wishful hooking detected" "Function '${one_defined_function}' is defined (${defined_info}) but never called by the build." "wrn"43fi44done4546if [[ $found_honeypot_function -lt 1 ]]; then47display_alert "Wishful hook DETECTION FAILED" "detect-wishful-hooking is not working. Good chance the environment vars are corrupted. Avoid child shells. Sorry." "wrn" | tee -a "${EXTENSION_MANAGER_LOG_FILE}"48fi49}505152