forked from eclipse/iottestware
/
install.py
286 lines (224 loc) · 9.38 KB
/
install.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
###############################################################################
# Copyright (c) 2018 Fraunhofer FOKUS #
# All rights reserved. This program and the accompanying materials #
# are made available under the terms of the Eclipse Public License v1.0 #
# which accompanies this distribution, and is available at #
# http://www.eclipse.org/legal/epl-v10.html #
# #
# Contributors: #
# Sascha Hackel #
# Alexander Kaiser #
###############################################################################
""""""""""""""""""
""" IMPORTS """
""""""""""""""""""
import os
from os.path import expanduser
import subprocess
import argparse
import glob
""""""""""""""""""""""""
""" CONFIGURATION """
""""""""""""""""""""""""
# home directory
HOME = expanduser("~")
parser = argparse.ArgumentParser(description='Installing and running the IoT-Testware. Please specify a mode.')
parser.add_argument("-p", "--protocol", required=True, choices=['mqtt', 'coap', 'opcua'],
help="sets a protocol that will be cloned together with its dependencies")
parser.add_argument("-b", "--build", required=False, action="store_true",
help="build the project and create a Makefile")
parser.add_argument("--path", default=HOME+"/Titan", required=False,
help="specify optionally your root directory, where all dependencies will be stored")
parser.add_argument("-e", "--executable_name", required=False, nargs=1,
help="set the name of the executable that will be generated")
parser.add_argument("-v", "--verbose", required=False, action="store_true",
help="progress status output is verbose")
args = parser.parse_args()
# base path for the Eclipse Titan protocol modules and test ports
PATH_BASE=args.path
# defined protocols
IOT_TESTWARE = {
"coap":"CoAP",
"mqtt":"MQTT",
"opcua":"OPC_UA"
}
# version number of needed module
GIT_PROTOCOL_VERSION = {
"coap":"f51e6415de7582d01bf725efdc5161d3533babd1",
"mqtt":"c22560bb461c21cb1835f19721e990eb57691bad",
"opcua":"f13b46d1c9c8448fee8e034c086d6fd3caedbd3b"
}
# current protocol
PROTOCOL = IOT_TESTWARE[args.protocol]
# default executable name
NAME_EXE = "iottestware."+args.protocol
if args.executable_name!=None:
NAME_EXE = args.executable_name[0]
# current working directory
project_dir = os.getcwd()
# Git flags
GIT_QUIET="--quiet"
if args.verbose:
GIT_FLAG="--verbose"
else:
GIT_FLAG=GIT_QUIET
""" INSTALLATION ! Do NOT change from here ! """
# These are prescribed in the *.tpd file
# TestPorts
PATH_SOCKET_API=PATH_BASE+"/TestPorts/Common_Components/Socket_API_CNL113686/"
PATH_IPL4=PATH_BASE+"/TestPorts/IPL4asp/"
# ProtocolModules
PATH_COMMON=PATH_BASE+"/ProtocolModules/COMMON/"
PATH_PROTOCOL=PATH_BASE+"/ProtocolModules/"+PROTOCOL+"/"
# Libraries
PATH_TCC=PATH_BASE+"/Libraries/TCCUsefulFunctions_CNL113472/"
PATH_IOTTESTWARE=PATH_BASE+"/IoT-Testware"
PATH_TW=PATH_IOTTESTWARE+"/iottestware."+args.protocol+"/"
# Git repositories
GIT_IOTTESTWARE = 'https://github.com/eclipse/iottestware.'+args.protocol+'.git'
GIT_SOCKET_API = 'https://github.com/eclipse/titan.TestPorts.Common_Components.Socket-API.git'
GIT_SOCKET_API_VERSION = '9e4ac13486f084e6eca74b976daf21b0028c44c1'
GIT_IPL4 = 'https://github.com/eclipse/titan.TestPorts.IPL4asp.git'
GIT_IPL4_VERSION = '8045145aa32cd4452f1acc30ade0a6ea79033bcc'
GIT_COMMON = 'https://github.com/eclipse/titan.ProtocolModules.COMMON.git'
GIT_COMMON_VERSION = '9a52b8dc609e18c193fbe4619aeb52d6c94e7922'
GIT_PROTOCOL = 'git://git.eclipse.org/gitroot/titan/titan.ProtocolModules.'+PROTOCOL+'.git'
GIT_TCC = 'https://github.com/eclipse/titan.Libraries.TCCUsefulFunctions.git'
GIT_TCC_VERSION = '27f76bb794af89f5ed9088317fc2e82247667f74'
def install(protocol):
""""""""""""""""""""
""" IOT-TESTWARE """
""""""""""""""""""""
if os.path.isdir(PATH_TW):
print(PATH_TW + " already exists")
os.chdir(PATH_TW)
# ensure latest Titan version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
subprocess.Popen(['git', 'checkout', GIT_QUIET, 'master']).communicate()[0]
subprocess.Popen(['git', 'pull', GIT_FLAG]).communicate()[0]
# back to cwd
os.chdir(project_dir)
else:
# print sth ...
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_IOTTESTWARE, PATH_TW])
print(" IoT-Testware ... done!")
""""""""""""""""""
""" TEST PORTS """
""""""""""""""""""
if os.path.isdir(PATH_SOCKET_API):
print(PATH_SOCKET_API + " already exists")
os.chdir(PATH_SOCKET_API)
# ensure latest version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
else:
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_SOCKET_API, PATH_SOCKET_API]).communicate()[0]
# go to PATH_SOCKET_API
os.chdir(PATH_SOCKET_API)
# checkout the required version SocketAPI
subprocess.Popen(['git', 'checkout', GIT_QUIET, GIT_SOCKET_API_VERSION]).communicate()[0]
# back to cwd
os.chdir(project_dir)
if os.path.isdir(PATH_IPL4):
print(PATH_IPL4 + " already exists")
os.chdir(PATH_IPL4)
# ensure latest version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
else:
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_IPL4, PATH_IPL4]).communicate()[0]
# go to PATH_IPL4
os.chdir(PATH_IPL4)
# checkout the required version IPL4asp
subprocess.Popen(['git', 'checkout', GIT_QUIET, GIT_IPL4_VERSION]).communicate()[0]
# back to cwd
os.chdir(project_dir)
print(" Test ports ... done!")
""""""""""""""""""""""""
""" PROTOCOL MODULES """
""""""""""""""""""""""""
if os.path.isdir(PATH_COMMON):
print(PATH_COMMON + " already exists")
os.chdir(PATH_COMMON)
# ensure latest version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
else:
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_COMMON, PATH_COMMON]).communicate()[0]
# go to PATH_COMMON
os.chdir(PATH_COMMON)
# checkout the required version of COMMON
subprocess.Popen(['git', 'checkout', GIT_QUIET, GIT_COMMON_VERSION]).communicate()[0]
# back to cwd
os.chdir(project_dir)
if os.path.isdir(PATH_PROTOCOL):
print(PATH_PROTOCOL + " already exists")
os.chdir(PATH_PROTOCOL)
# ensure latest version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
else:
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_PROTOCOL, PATH_PROTOCOL]).communicate()[0]
# go to PATH_PROTOCOL
os.chdir(PATH_PROTOCOL)
# checkout required version of Test Suite
subprocess.Popen(['git', 'checkout', GIT_QUIET, GIT_PROTOCOL_VERSION[args.protocol]]).communicate()[0]
# back to cwd
os.chdir(project_dir)
print(" Protocol modules ... done!")
""""""""""""""""""
""" LIBRARIES """
""""""""""""""""""
if os.path.isdir(PATH_TCC):
print(PATH_TCC + " already exists")
os.chdir(PATH_TCC)
# ensure latest version
subprocess.Popen(['git', 'remote', 'update']).communicate()[0]
else:
subprocess.Popen(['git', 'clone', GIT_FLAG, GIT_TCC, PATH_TCC]).communicate()[0]
# go to PATH_TCC
os.chdir(PATH_TCC)
# checkout required version of TCC
subprocess.Popen(['git', 'checkout', GIT_QUIET, GIT_TCC_VERSION]).communicate()[0]
# back to cwd
os.chdir(project_dir)
print(" Libraries ... done!")
print("Getting Dependencies done!")
""""""""""""""""""""""""""
""" PREPARE WORKSPACE """
""""""""""""""""""""""""""
print("Preparing workspace ...")
# clean the bin directory
bin_folder = PATH_TW+"bin"
if os.path.isdir(bin_folder):
bin_files = glob.glob(bin_folder+"/*")
for file in bin_files:
os.remove(file)
else:
os.mkdir(bin_folder)
print(" Bin directory clean!")
def build(protocol):
bin_folder = PATH_TW+"bin"
tpd_file = PATH_TW+"iottestware."+protocol+".tpd"
# create bin folder if does not exist
if not os.path.isdir(bin_folder):
os.mkdir(bin_folder)
# Create a Makefile with Titan's ttcn3_makefilegen
# -f: force overwriting of the output Makefile
# -g: generate Makefile for use with GNU make
# -m: always use makedepend for dependencies
# -e ets_name: name of the target executable
# -t tpd: read project descriptor file
os.system("ttcn3_makefilegen -f -g -m -t "+tpd_file+" -e "+NAME_EXE+" "+PATH_TW+"src/*.ttcn")
print("Makefile generated!")
# move to bin folder
os.chdir(bin_folder)
# compile and build
os.system("make compile")
os.system("make")
print("Compilation done!")
print("Building the project done!")
def Main():
print("Getting dependencies ...")
install(args.protocol)
if args.build:
print("Building the project ...")
build(args.protocol)
if __name__ == '__main__':
Main()