forked from blackbeam/rust-mysql-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (112 loc) · 3.12 KB
/
Makefile
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
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))
MYSQL_DATA_DIR = $(mkfile_dir)tests/rust-mysql-simple-test
MYSQL_SSL_CA = $(mkfile_dir)tests/ca-cert.pem
MYSQL_SSL_CERT = $(mkfile_dir)tests/server-cert.pem
MYSQL_SSL_KEY = $(mkfile_dir)tests/server-key.pem
MYSQL_PORT = 3307
BASEDIR := $(shell mysqld --verbose --help 2>/dev/null | grep -e '^basedir' | awk '{ print $$2 }')
OS := $(shell uname)
FEATURES := "ssl"
BENCH_FEATURES := "nightly" "nightly ssl"
define run-mysql
if [ -e $(MYSQL_DATA_DIR)/mysqld.pid ];\
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
fi
if [ -e $(MYSQL_DATA_DIR) ];\
then \
rm -rf $(MYSQL_DATA_DIR) || true; \
fi
mkdir -p $(MYSQL_DATA_DIR)/data
if ((mysql --version | grep -P '5\.(6|7)' >>/dev/null) || (mysql --version | grep Maria >>/dev/null));\
then \
mysql_install_db --no-defaults \
--basedir=$(BASEDIR) \
--datadir=$(MYSQL_DATA_DIR)/data; \
else \
mysqld --initialize-insecure \
--basedir=$(BASEDIR) \
--datadir=$(MYSQL_DATA_DIR)/data; \
fi
mysqld --no-defaults \
--basedir=$(BASEDIR) \
--bind-address=127.0.0.1 \
--datadir=$(MYSQL_DATA_DIR)/data \
--max-allowed-packet=32M \
--pid-file=$(MYSQL_DATA_DIR)/mysqld.pid \
--port=$(MYSQL_PORT) \
--innodb_file_per_table=1 \
--innodb_log_file_size=256M \
--local-infile=ON \
--ssl \
--ssl-ca=$(MYSQL_SSL_CA) \
--ssl-cert=$(MYSQL_SSL_CERT) \
--ssl-key=$(MYSQL_SSL_KEY) \
--socket=$(MYSQL_DATA_DIR)/mysqld.sock &
while ! nc -z 127.0.0.1 $(MYSQL_PORT); \
do \
sleep 0.5; \
done
if [ -e ~/.mysql_secret ]; \
then \
mysqladmin -h127.0.0.1 \
--port=$(MYSQL_PORT) \
-u root \
-p"`cat ~/.mysql_secret | grep -v Password`" password 'password'; \
else \
mysqladmin -h127.0.0.1 --port=$(MYSQL_PORT) -u root password 'password'; \
fi
endef
all: lib doc
target/deps: lib
target/tests/mysql: test
lib:
cargo build --release
doc:
cargo doc
test:
$(run-mysql)
if ! (COMPRESS=0 SSL=0 cargo test); \
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
exit 1; \
fi
if ! (COMPRESS=1 SSL=0 cargo test); \
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
exit 1; \
fi
if ! (COMPRESS=0 SSL=1 cargo test); \
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
exit 1; \
fi
if ! (COMPRESS=1 SSL=1 cargo test); \
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
exit 1; \
fi
@kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`
@rm -rf $(MYSQL_DATA_DIR) || true
bench:
$(run-mysql)
for var in $(BENCH_FEATURES); \
do \
echo TESTING FEATURS: $$var; \
if ! (cargo bench --no-default-features --features "$$var"); \
then \
kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`; \
rm -rf $(MYSQL_DATA_DIR) || true; \
exit 1; \
fi \
done
@kill -9 `cat $(MYSQL_DATA_DIR)/mysqld.pid`
@rm -rf $(MYSQL_DATA_DIR) || true
clean:
cargo clean