forked from garnacho/dxr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-env.sh
executable file
·126 lines (108 loc) · 2.87 KB
/
setup-env.sh
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
#!/usr/bin/env bash
if [ -z "${BASH_VERSION}" ]; then
echo -e "\n\n\n\nYour environment is not correctly set up.\n"
echo "You need to source $DXRSRC/setup-env.sh into a running bash:"
echo ". $DXRSRC/setup-env.sh"
return 0 &>/dev/null
exit 1
fi
if [ -z "$2" ]; then
name="${BASH_SOURCE[0]}"
if [ -z "$name" ]; then
name=$0
fi
echo "Usage: . $name <dxr.config> <treename>"
return 0 &>/dev/null
exit 1
fi
DXRCONFIG="$1"
TREENAME="$2"
function get_var()
{
echo $(PYTHONPATH=$DXRSRC:$PYTHONPATH python - <<HEREDOC
import dxr
cfg=dxr.load_config("$DXRCONFIG")
found=False
for treecfg in cfg.trees:
if treecfg.tree == "$1":
found=True
break
if found == False:
raise BaseException("Tree[$1] not found in config[$DXRCONFIG]")
try:
print("%s" % treecfg.$2)
except:
raise BaseException("Variable[$2] not found in Tree[$1]")
HEREDOC
)
}
SRCDIR=$(get_var "$TREENAME" "sourcedir")
OBJDIR=$(get_var "$TREENAME" "objdir")
if [ -z "$SRCDIR" ]; then
return 0 &>/dev/null
exit 1
fi
if [ -z "$OBJDIR" ]; then
echo -e "\e[1;33mThe object dir equals source dir (not recommended).\e[0m\n"
export OBJDIR="$SRCDIR"
fi
if [ -z "$DXRSRC" ]; then
echo "Setting DXRSRC variable"
scriptsrc=${BASH_SOURCE[0]}
export DXRSRC=$(dirname $(readlink -f $scriptsrc))
fi
MAKE=${MAKE:-make}
echo "Finding available DXR plugins..."
tools=($(PYTHONPATH=$DXRSRC:$PYTHONPATH python - <<HEREDOC
import dxr
cfg=dxr.load_config("$DXRCONFIG")
for treecfg in cfg.trees:
if treecfg.tree == "$TREENAME":
files = [x.__file__ for x in dxr.get_active_plugins(treecfg, "$DXRSRC")]
break
print ' '.join([x[:x.find('/indexer.py')] for x in files])
HEREDOC
) )
echo -n "Found:"
for plugin in $(seq 0 $((${#tools[@]} - 1))); do
echo -n " $(basename ${tools[plugin]})"
done
echo ""
echo -n "Cleaning up environment variables from previous runs... "
for plugin in $(seq 0 $((${#tools[@]} - 1))); do
if [ -e "${tools[plugin]}/unset-env.sh" ]; then
. "${tools[plugin]}/unset-env.sh"
fi
done
echo ""
echo -n "Building sqlite tokenizer... "
$MAKE -C ${DXRSRC}/sqlite
if [[ $? != 0 ]]; then
echo "Bailing!"
return 1
fi
echo "done!"
for plugin in $(seq 0 $((${#tools[@]} - 1))); do
echo -n "Prebuilding $(basename ${tools[plugin]})... "
if [ -e ${tools[plugin]}/Makefile ]; then
$MAKE -s -C ${tools[plugin]} prebuild
if [[ $? != 0 ]]; then
echo "Bailing!"
return 1
fi
fi
echo "done!"
done
echo -n "Preparing environment... "
for plugin in $(seq 0 $((${#tools[@]} - 1))); do
if [ -e "${tools[plugin]}/set-env.sh" ]; then
. "${tools[plugin]}/set-env.sh"
fi
done
echo "done!"
echo "DXR setup complete. You can now compile your source code in this shell."
# Check for . $0 instead of ./$0
return 0 &>/dev/null
echo -e "\n\n\n\n\e[1;31mYour environment is not correctly set up.\e[0m\n"
echo "You need to run the following command instead:"
echo ". $DXRSRC/setup-env.sh"