forked from libpnet/libpnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
153 lines (133 loc) · 3.95 KB
/
build.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# Copyright (c) 2014 Robert Clipsham <robert@octarineparrot.com>
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# Build script, since cargo doesn't currently work on FreeBSD
[[ "$VERBOSE" == "1" ]] && set -x
RUSTC=$(which rustc)
RUSTDOC=$(which rustdoc)
CARGO=$(which cargo)
SUDO=$(which sudo)
SYSTEM=$(uname -s)
TESTER="$CARGO test"
CC=$(which clang || which gcc)
CARGO_FLAGS=
# FIXME Need to get interface differently on Windows
# FIXME Needs to with with iproute2 too
PNET_TEST_IFACE=$(ifconfig | egrep 'UP| active' | \
perl -pe '/^[A-z0-9]+:([^\n]|\n\t)*status: active/' | \
grep active -B1 | head -n1 | cut -f1 -d:)
# FIXME Need to link libraries properly on Windows
build() {
if [[ -x "$CARGO" ]]; then
$CARGO build $CARGO_FLAGS --release
else
$RUSTC src/lib.rs
fi
}
build_doc() {
if [[ -x "$CARGO" ]]; then
$CARGO doc $CARGO_FLAGS
else
$RUSTDOC src/lib.rs -o target/doc --crate-name pnet
fi
}
build_test() {
if [[ -x "$CARGO" ]]; then
$CARGO test --no-run $CARGO_FLAGS
$CARGO bench --no-run $CARGO_FLAGS
else
$RUSTC src/lib.rs --test --out-dir ./target/ -C extra-filename=-no-cargo
fi
}
run_macro_tests() {
cd pnet_macros &&
$CARGO test $CARGO_FLAGS &&
cd ..
}
run_test() {
run_macro_tests &&
export RUST_TEST_THREADS=1 &&
case "$SYSTEM" in
Linux)
$SUDO -E LD_LIBRARY_PATH=$LD_LIBRARY_PATH sh -c "cargo build $CARGO_FLAGS --release && \
cargo test $CARGO_FLAGS && \
cargo bench --no-run $CARGO_FLAGS && \
cargo doc $CARGO_FLAGS"
;;
FreeBSD|Darwin)
export PNET_TEST_IFACE
$SUDO -E DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH bash -c "cargo build $CARGO_FLAGS && \
cargo test $CARGO_FLAGS && \
cargo bench --no-run $CARGO_FLAGS && \
cargo doc $CARGO_FLAGS"
;;
MINGW*|MSYS*)
PNET_TEST_IFACE=$PNET_TEST_IFACE RUST_TEST_THREADS=1 $TESTER
;;
FreeBSD|*)
echo "Unsupported testing platform"
;;
esac
}
clean() {
if [[ -x "$CARGO" ]]; then
$CARGO clean $CARGO_FLAGS
else
rm -fr target
fi
}
benchmarks() {
[[ "$SYSTEM" != "Darwin" ]] && echo warning: C benchmarks only work on OS X
$CC -W -Wall -O2 benches/c_receiver.c -o target/benches/c_receiver
$CC -W -Wall -O2 benches/c_sender.c -o target/benches/c_sender
$RUSTC -O benches/rs_receiver.rs --out-dir target/benches -L target/release
$RUSTC -O benches/rs_sender.rs --out-dir target/benches -L target/release
}
travis_script() {
case "$SYSTEM" in
Linux)
$SUDO sed -i 's/secure_path="/secure_path="\/home\/travis\/rust\/bin:/' /etc/sudoers
;;
Darwin)
echo Defaults secure_path = \"$PATH\" | $SUDO tee -a /etc/sudoers
;;
*)
echo "Unsupported travis platform"
;;
esac
run_test
}
mkdir -p target/doc
mkdir -p target/benches
if [[ "$VERBOSE" == "1" ]]; then
CARGO_FLAGS="--verbose"
TESTER="$TESTER $CARGO_FLAGS"
fi
if [[ ! -x "$CARGO" ]]; then
TESTER='./target/pnet-*'
fi
case "$1" in
test)
run_test
;;
doc)
build_doc
;;
clean)
clean
;;
benchmarks)
benchmarks
;;
travis_script)
travis_script
;;
*)
build
;;
esac