-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherrors_resolver_demo
executable file
·112 lines (91 loc) · 2.15 KB
/
errors_resolver_demo
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
#!/bin/bash
export CPATH LIBRARY_PATH
export CPPFLAGS
export LDFLAGS
export LDLIBS
export LD_LIBRARY_PATH
set -e
CPPFLAGS=-Wall
[ -z "$CC" ] && CC=gcc
showv() { val=$(eval "echo \$${1}"); test "$val" && echo -n "$1='$val' $2" || true; }
show_vars()
{
showv CC
showv CXX
showv CXXFLAGS
showv CPATH
showv CPPFLAGS
#showv LIBRARY_PATH
showv LDFLAGS
showv LDLIBS
}
fatal() { echo "Fatal error $1"; exit 1; }
(echo | python3) || fatal
(echo | gcc - -E > /dev/null) || fatal
(echo | g++ - -E > /dev/null) || fatal
echo -e "Initial invironment\n"
# Feature substitute_paths allows to substitute long paths to shortcut variables.
export substitute_paths=d1:d2 d1=some/long/path d2=some/long/path2
showv CC $'\n'
#showv substitute_paths
#showv d1
#showv d2 $'\n'
#prepare sub library
make --quiet --always-make -C sub
echo
pass()
{
echo -e "$1\n"
eval "$(make --always-make $target |& tee make.tmp | ./errors_resolver.py | tee out.tmp)"
grep -e warning: -e error: -e undefined -e cannot make.tmp || true
echo -e "\nFix:"
cat out.tmp
echo
}
run_errors_resolver_sample()
{
target=errors_resolver_sample
pass "pass 1: resolve headers paths"
pass "pass 2: resolve headers"
pass "pass 3: resolve libraries"
pass "pass 3: resolve library paths"
echo -e "Final compilation:\n"
make --always-make $target || fatal
if [ -e ./$target ]; then
arch=$(echo $(file -e elf ./$target | cut -d',' -f2 | tr - _))
else
arch=$(uname -m)
fi
echo -e "\nTest run:\n"
if [[ $arch = $(uname -m) ]]; then
./$target
else
echo detected architecture $arch, machine $($CC -dumpmachine)
qemu-${arch,,} -L /usr/"$($CC -dumpmachine)" ./$target
fi
echo -e "\nFinal result:\n"
show_vars
echo "make -B $target "
showv LD_LIBRARY_PATH
echo ./$target
}
run_errors_resolver_sample_cpp()
{
echo -e "\nC++ sample\n"
export CXXFLAGS=-std=c++98
target=errors_resolver_sample_cpp
pass "pass 1: resolve C++ standard"
show_vars
echo -e "\n\nFinal compilation:\n"
make --always-make $target || fatal
echo -e "\nFinal result:\n"
show_vars
echo "make -B $target "
echo "./$target "
}
if [ -n "$*" ]; then
eval "$*"
else
(run_errors_resolver_sample)
(run_errors_resolver_sample_cpp)
fi