-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_module_dependencies.sh
More file actions
executable file
·131 lines (106 loc) · 4.2 KB
/
check_module_dependencies.sh
File metadata and controls
executable file
·131 lines (106 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# Module dependency checker for SENTINEL
# Analyzes module dependencies and checks for missing declarations
echo "=== SENTINEL Module Dependency Analysis ==="
echo
export SENTINEL_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
MODULES_DIR="${SENTINEL_ROOT}/bash_modules.d"
ISSUES_FOUND=0
# Colors for output
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
NC="\033[0m"
# Map of known function providers
declare -A FUNCTION_PROVIDERS=(
["sentinel_log_info"]="logging"
["sentinel_log_warning"]="logging"
["sentinel_log_error"]="logging"
["_log_info"]="logging"
["_log_warning"]="logging"
["_log_error"]="logging"
["CONFIG"]="config_cache"
["source_cached"]="config_cache"
["_config_cache_enabled"]="config_cache"
)
# Check each module
for module_file in "$MODULES_DIR"/*.module "$MODULES_DIR"/*.sh; do
[[ ! -f "$module_file" ]] && continue
module_name=$(basename "$module_file" | sed 's/\.\(module\|sh\)$//')
# Skip non-module files
[[ "$module_name" == "migrate_config" || "$module_name" == "install-autocomplete" ]] && continue
echo -e "${BLUE}Checking module: $module_name${NC}"
# Get declared dependencies
declared_deps=""
if grep -q "SENTINEL_MODULE_DEPENDENCIES=" "$module_file"; then
declared_deps=$(grep "SENTINEL_MODULE_DEPENDENCIES=" "$module_file" | head -n1 | sed 's/.*="\(.*\)".*/\1/')
fi
# Check for usage of functions from other modules
missing_deps=""
# Check for logging functions
if grep -qE "(sentinel_log_info|sentinel_log_warning|sentinel_log_error|_log_info|_log_warning|_log_error)" "$module_file"; then
# Check if module defines its own logging functions
if ! grep -q "^\(function \)\?sentinel_log_info\(\(\)\)\?\s*{" "$module_file" && \
! grep -q "^\(function \)\?_sentinel_log_info\(\(\)\)\?\s*{" "$module_file"; then
if [[ ! "$declared_deps" =~ "logging" ]]; then
missing_deps+="logging "
fi
fi
fi
# Check for config_cache functions
if grep -qE "(source_cached|CONFIG\[|_config_cache_enabled)" "$module_file"; then
if [[ ! "$declared_deps" =~ "config_cache" ]]; then
missing_deps+="config_cache "
fi
fi
# Report findings
if [[ -n "$declared_deps" ]]; then
echo " Declared dependencies: $declared_deps"
else
echo " No dependencies declared"
fi
if [[ -n "$missing_deps" ]]; then
echo -e " ${RED}Missing dependencies: $missing_deps${NC}"
((ISSUES_FOUND++))
else
echo -e " ${GREEN}Dependencies OK${NC}"
fi
echo
done
# Check module load order
echo -e "${BLUE}Checking module load order...${NC}"
if [[ -f "${SENTINEL_ROOT}/.bash_modules" ]]; then
echo "Module load order from .bash_modules:"
# Check that dependencies are loaded before modules that need them
loaded_modules=()
while IFS= read -r module; do
# Skip comments and empty lines
[[ -z "$module" || "$module" =~ ^# ]] && continue
module_file="$MODULES_DIR/$module.module"
[[ ! -f "$module_file" ]] && module_file="$MODULES_DIR/$module.sh"
if [[ -f "$module_file" ]]; then
# Get dependencies
deps=""
if grep -q "SENTINEL_MODULE_DEPENDENCIES=" "$module_file"; then
deps=$(grep "SENTINEL_MODULE_DEPENDENCIES=" "$module_file" | head -n1 | sed 's/.*="\(.*\)".*/\1/')
fi
# Check if dependencies are loaded
for dep in $deps; do
if [[ ! " ${loaded_modules[@]} " =~ " ${dep} " ]]; then
echo -e " ${YELLOW}Warning: $module requires $dep, but it's loaded after${NC}"
fi
done
fi
loaded_modules+=("$module")
done < "${SENTINEL_ROOT}/.bash_modules"
else
echo -e "${YELLOW}No .bash_modules file found${NC}"
fi
echo
echo "=== Summary ==="
if [[ $ISSUES_FOUND -eq 0 ]]; then
echo -e "${GREEN}All module dependencies appear to be properly declared!${NC}"
else
echo -e "${RED}Found $ISSUES_FOUND modules with missing dependency declarations${NC}"
fi