forked from aperloff/vivado-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.xilinx_docker
159 lines (147 loc) · 5.52 KB
/
.xilinx_docker
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
#!/bin/bash
xilinx_docker() {
local debug="false"
local entrypoint=""
local image=""
local local=""
local os="sl7"
local registry="docker.io"
local remote="/home/vivado/local_mount/"
local version="2019.2"
local program_version="vivado${version}"
local usage="$FUNCNAME [-h] [-l <loacal path to mount>] [-r <remote path to mount>] -e <entrypoint>
-- opens a docker container which contains Xilinx Vivado/Vitis HLx Design Edition
there are multiple entrypoints (programs) to choose from
entrypoints:
1) vivado
2) vivado_hls
3) vitis (if available)
4) vitis_hls (if available)
5) bash
known registries:
1) docker.io (a.k.a DockerHub)
2) gitlab-registry.cern.ch (a.k.a CERN GitLab)
where:
-h show this help text
-e sets the entrypoint (default: ${entrypoint})
-i specify the Docker image to be used (default: ${image})
-l local path to mount in container (default: ${local})
-o the os of the image, sl7 or ubuntu (default: ${os})
-r remote path to mount in the container (default: ${remote})
-R the Docker registry of the image (default: ${registry})
-v the Vivado version to use (default: ${version})
-V use Vitis rather than Vivado
example: xilinx_docker -e bash -l `pwd` -r /root/workdir"
local OPTIND OPTARG
while getopts 'hde:i:l:o:r:R:v:V' option; do
case "$option" in
d) debug="true"
;;
e) entrypoint=$OPTARG
;;
h) echo "$usage"
return 0
;;
i) image=$OPTARG
;;
l) local=$OPTARG
;;
o) os=$OPTARG
;;
r) remote=$OPTARG
;;
R) registry=$OPTARG
;;
v) version=$OPTARG
program_version="vivado${version}"
;;
V) vitis="true"
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
return -1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
return -2
;;
esac
done
shift $((OPTIND - 1))
# Entrypoint santity check
if [[ "$entrypoint" == "" ]]; then
echo "ERROR: You must specify an entrypoint!"
echo "$usage" >&2
return -3
fi
# Make some modifications if using Vitis rather than Vivado
if [[ "$vitis" == "true" ]]; then
remote="${remote/\/home\/vivado/\/home\/vitis}"
program_version="${program_version/vivado/vitis}"
fi
# Format the local mount point
if [[ "$local" != "" ]]; then
local local_mount="-v${local}:${remote}"
else
echo "Note: No local mount set."
fi
# Format the image used
if [[ -z ${image} ]]; then
if [[ "${registry}" == *"docker.io"* ]]; then
image=${registry}/aperloff/vivado-docker:${os}_${program_version}_x11
elif [[ "${registry}" == *"gitlab-registry.cern.ch"* ]]; then
image=${registry}/aperloff/vivado-docker/${os}_${program_version}_x11:latest
fi
fi
# Capture the output of the xhost command and look for the lines:
# "access control enabled, only authorized clients can connect"
# "INET:localhost
# If the first is different, then the xhost access should be reset by doing:
# xhost -
# Then check again. If either the second line is missing, or the first was there, but the second one was missing, then do:
# xhost +127.0.0.1
# Then check again. If it's not right this time, then exit and throw an error
xhost_enabled="access control enabled, only authorized clients can connect"
xhost_localhost="INET:localhost"
xhost_check="$(xhost)"
if [[ $xhost_check == *"${xhost_localhost}"* ]]; then
echo "Note::access control already enabled, including an opening for localhost"
else
xhost -
xhost_check="$(xhost)"
if [[ $xhost_check != *"${xhost_enabled}"* ]]; then
xhost +127.0.0.1
xhost_check="$(xhost)"
if [[ $xhost_check != *"${xhost_localhost}"* ]]; then
echo "ERROR:Unable to set the xhost settings properly"
return -3
fi
fi
fi
if [[ "$debug" == "true" ]]; then
set -x
fi
case "${entrypoint}" in
vivado)
docker run --rm -it --net=host -e DISPLAY=host.docker.internal:0 ${local_mount} --entrypoint /opt/Xilinx/Vivado/${version}/bin/vivado ${image}
;;
vivado_hls)
docker run --rm -it --net=host -e DISPLAY=host.docker.internal:0 ${local_mount} --entrypoint /opt/Xilinx/Vivado/${version}/bin/vivado_hls ${image}
;;
vitis)
docker run --rm -it --net=host -e DISPLAY=host.docker.internal:0 ${local_mount} --entrypoint /opt/Xilinx/Vitis/${version}/bin/vitis ${image}
;;
vitis_hls)
docker run --rm -it --net=host -e DISPLAY=host.docker.internal:0 ${local_mount} --entrypoint /opt/Xilinx/Vitis/${version}/bin/vitis_hls ${image}
;;
bash)
docker run --rm -it --net=host -e DISPLAY=host.docker.internal:0 ${local_mount} --entrypoint /bin/bash ${image}
;;
*)
echo "ERROR::Unknown executable. Would you like to run Vivado (vivado), Vivado HLS (hls), or bash (bash)?"
set +x
return -4
;;
esac
set +x
}