-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·175 lines (150 loc) · 4.44 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
#TODO
# Make a enviroment restore
# If modified package is not used do not query git
orig_pwd=`pwd`
while [ x != "x$1" ] ; do
if [ "$1" == "--without-sawg" ]; then
without_sawg="--without-sawg"
elif [ "$1" == "--note" ]; then
note=$2
shift
elif [ "$1" == "-V" ]; then
variant=$2
shift
elif [ "$1" == "-hw-rev" ]; then
hwrev=$2
shift
elif [ "$1" == "amc" ]; then
board="sayma_amc"
elif [ "$1" == "rtm" ]; then
board="sayma_rtm"
elif [ "$1" == "kasli" ]; then
board="kasli"
elif [ "$1" == "kasli_generic" ]; then
board="kasli_generic"
if [ -f $2 ]; then
json_file=$2
else
echo "Provide file for kasli generic"
exit 1
fi
shift
elif [ "$1" == "metlino" ]; then
board="metlino"
elif [ "$1" == "--no-compile-gateware" ]; then
no_gateware="--no-compile-gateware"
fi
shift
done
if [ -z ${board+x} ]; then
echo "Which board? (amc rtm metlino kasli kasli_generic)"
exit 1
fi
if [ "$board" == "kasli_generic" ]; then
board_dir="kasli"
else
board_dir=$board
fi
mkdir -p $board_dir
if [ "$board" == "kasli_generic" ]; then
variant=`cat $json_file | python3 -c "import sys, json; print(json.load(sys.stdin)['variant'])"`
hwrev=`cat $json_file | python3 -c "import sys, json; print(json.load(sys.stdin)['hw_rev'])"`
fi
if [ -z ${variant+x} ]; then
if [ "$board" == "sayma_amc" ]; then
variant="satellite"
elif [ "$board" == "sayma_rtm" ]; then
variant="satellite"
elif [ "$board" == "kasli" ]; then
variant="tester"
elif [ "$board" == "metlino" ]; then
variant="master"
fi
fi
if [ -z ${hwrev+x} ]; then
if [ "$board" == "sayma_amc" ]; then
hwrev="v2.0"
elif [ "$board" == "sayma_rtm" ]; then
hwrev="v2.0"
elif [ "$board" == "kasli" ]; then
hwrev="v1.1"
elif [ "$board" == "metlino" ]; then
hwrev="v1.0"
fi
fi
#Get complete environment state
artiq_dir=`python -c "import artiq; import os; print(os.path.dirname(artiq.__file__))"`
cd $artiq_dir
artiq_hash=`git rev-parse --short HEAD`
artiq_diff=`git diff`
misoc_dir=`python -c "import misoc; import os; print(os.path.dirname(misoc.__file__))"`
cd $misoc_dir
misoc_hash=`git rev-parse --short HEAD`
misoc_diff=`git diff`
migen_dir=`python -c "import migen; import os; print(os.path.dirname(migen.__file__))"`
cd $migen_dir
migen_hash=`git rev-parse --short HEAD`
migen_diff=`git diff`
nixscripts_dir="/home/pawel/artiq-dev/nix-scripts"
cd $nixscripts_dir
nixscripts_hash=`git rev-parse --short HEAD`
nixscripts_diff=`git diff`
vivado_ver=`vivado -version`
nix_pkgs_ver=`nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'`
cd $orig_pwd
name=`date +"%Y-%m-%d_%H_%M_%S"`
if [ -z ${note+x} ]; then
name+="_${board}_${variant}_${hwrev}"
else
name+="_${board}_${variant}_${hwrev}_${note}"
fi
# echo $name
mkdir $board_dir/$name
cd $board_dir/$name
echo -e "Build:\n$board $variant $hwrev $without_sawg $no_gateware" >> environment.txt
if ! [ -z ${note+x} ]; then
echo -e "Note: $note" >> environment.txt
fi
echo -e "Artiq:\n$artiq_hash\n" >> environment.txt
echo "$artiq_diff" > artiq.patch
echo -e "Misoc:\n$misoc_hash\n" >> environment.txt
echo "$misoc_diff" > misoc.patch
echo -e "Migen:\n$migen_hash\n" >> environment.txt
echo "$migen_diff" > migen.patch
echo -e "Nix scripts:\n$nixscripts_hash\n" >> environment.txt
echo "$nixscripts_diff" > nix_scripts.patch
echo -e "Vivado:\n$vivado_ver\n" >> environment.txt
echo -e "Nix:\n$nix_pkgs_ver\n" >> environment.txt
echo -e "Command:\n" >> environment.txt
echo `cat /home/pawel/artiq-dev/start_nix_shell.sh` >> environment.txt
if ! [ -z ${no_gateware+x} ]; then
mkdir -p $variant
cd $variant
link="../../../${board}_${variant}_${hwrev}_latest"
latest=`readlink $link`
ln -s $latest/$variant/gateware gateware
cd ..
fi
call=" -m artiq.gateware.targets.$board --output-dir=. $no_gateware $without_sawg"
if [ "$board" == "kasli_generic" ]; then
call+=" $orig_pwd/$json_file"
cp $orig_pwd/$json_file .
fi
if ! [[ "$board" == "sayma_rtm" || "$board" == "metlino" || "$board" == "kasli_generic" ]]; then
call+=" -V $variant"
fi
if ! [ "$board" == "metlino" ]; then
call+=" --hw-rev $hwrev"
fi
# echo $call
python $call |& tee build_log.txt
linkname="${board}_${variant}_${hwrev}_latest"
# echo $linkname
if [ -f "$variant/gateware/top.bit" ] || [ -f "gateware/top.bit" ]; then
rm -f "../../$linkname"
ln -sf `pwd` "../../$linkname"
else
echo "Build failed, not updating $linkname link."
fi
cd $orig_pwd