-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_tutorial.sh
More file actions
executable file
·97 lines (86 loc) · 2.96 KB
/
build_tutorial.sh
File metadata and controls
executable file
·97 lines (86 loc) · 2.96 KB
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
#!/bin/bash
red=$'\e[1;31m'
end=$'\e[0m'
# Write the first line of SUMMARY.md. This clears anything that was there previously
# printf "# Summary\n\n" > src/SUMMARY.md
printf "Generating visualizations for the following examples: \n"
# Uncomment the examples are being tested
declare -a targetExamples=(
# "copy"
# "func_take_ownership"
# "func_take_return_ownership"
# "function"
# "hatra1"
# "hatra1_test"
# "hatra2"
# "immutable_borrow"
# "immutable_borrow_method_call"
# "immutable_variable"
# "move_assignment"
# "move_different_scope"
# "move_func_return"
# "multiple_immutable_borrow"
# "mutable_borrow"
# "mutable_borrow_method_call"
# "mutable_variables"
# "nll_lexical_scope_different"
# "printing"
# "string_from_move_print"
# "string_from_print"
# "struct_lifetime"
# "struct_rect"
# "struct_rect2"
# "struct_string"
# "extra_credit"
"thread_vec"
"thread_vec2"
)
LOCALEX="src/assets/code_examples"
EX="../rustviz/src/examples"
# Loop through the specified examples
for target in ${targetExamples[@]}; do
printf "building %s...\n" $target
if ! [[ -d "$EX/$target" ]]
then
mkdir $EX/$target
fi
cp "$LOCALEX/$target/source.rs" "$EX/$target/source.rs"
# Check if required files are there
if [[ -f "$EX/$target/source.rs" ]]
then
# Check if file headers exist
if ! [[ -f "$EX/$target/main.rs" ]]
then
printf "\ngenerating header for %s..." $target
cd "../rustviz/src/RustvizParse"
cargo run "../examples/$target/source.rs" >/dev/null 2>&1
cd "../../../rustviz-tutorial"
cp "$EX/$target/main.rs" "$LOCALEX/$target/main.rs"
printf "\nPlease define events and rerun current script\n"
continue
fi
cp "$LOCALEX/$target/main.rs" "$EX/$target/main.rs"
cd "../rustviz/src/" # switch to appropriate folder
# Run svg generation for example
cargo run $target >/dev/null 2>&1
# If the svg generation exited with an error or the required SVGs weren't created, report failure and continue
if [[ $? -ne 0 || !(-f "examples/$target/vis_code.svg") || !(-f "examples/$target/vis_timeline.svg") ]]; then
printf "${red}FAILED${end} on SVG generation.\n"
cd ../../rustviz-tutorial
continue
fi
cd ../../rustviz-tutorial
# Copy files to mdbook directory
mkdir -p "./src/assets/code_examples/$target"
cp "$EX/$target/vis_code.svg" "./src/assets/code_examples/$target/vis_code.svg"
cp "$EX/$target/vis_timeline.svg" "./src/assets/code_examples/$target/vis_timeline.svg"
else
# Not Necessary (file double check)
printf "${red}FAILED${end}. The required files are not in the examples dir.\n"
fi
done
# Build mdbook
mdbook build
# Run HTTP server on docs directory
cd book
python3 -m http.server 8000