Debian Codegraph @

scripts/check-padding

raw
1 #!/usr/bin/env bash
2
3 set -eu
4 set -o pipefail
5
6 cpp="/tmp/alignment.cpp"
7 app="/tmp/alignment"
8
9 function usage() {
10 echo "Usage:"
11 echo ""
12 echo "./scripts/rebuild.sh [header] [class name]"
13 echo ""
14 echo "Please pass a header file and a class name"
15 echo ""
16 echo " ./scripts/check-padding include/mapnik/attribute.hpp mapnik::attribute"
17 echo ""
18 exit 1
19
20 }
21
22 function add() {
23 echo $1 >> ${cpp}
24 }
25
26 CXX=${CXX:-clang++}
27
28 function compile() {
29 ${CXX} -o ${app} ${cpp} -Wpadded -I./ -I./deps/mapbox/variant/include -isystem ./mason_packages/.link/include -std=c++11 -Ideps -Lsrc -Ideps/agg/include -Iinclude
30 }
31
32 if [[ ${1:-unset} == "unset" ]] || [[ ${2:-unset} == "unset" ]] || [[ $@ == '-h' ]] || [[ $@ == '--help' ]]; then
33 usage
34 fi
35
36 echo '' > ${cpp}
37
38 add "#include <iostream>"
39 add "#include <vector>"
40
41 add "#include \"$1\""
42
43 add ""
44
45 add '#define REPORT(type) std::clog << "sizeof(" #type ") " << sizeof(type) << "\n";'
46
47 add "int main() {"
48 add ""
49
50 add "REPORT(std::string)"
51 add "REPORT(unsigned int)"
52 add "REPORT(int)"
53 add "REPORT(bool)"
54 add "REPORT(std::vector<double>)"
55 add "REPORT(std::size_t)"
56
57 add "REPORT($2)"
58
59 add "return 0;"
60 add "}"
61
62 compile
63 ${app}