-
Notifications
You must be signed in to change notification settings - Fork 4
/
zephyr-launch.py
executable file
·70 lines (58 loc) · 2.3 KB
/
zephyr-launch.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
#!/usr/bin/env python
# zephyr-launch.py
#
# Copyright (C) 2016 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import argparse
import os
import sys
import subprocess
import shlex
class ZephyrLaunchError(Exception):
pass
def clone_zephyr(url, dest):
cmd = "git clone {}".format(url)
cmd = shlex.shlex(cmd, posix=True)
cmd.whitespace_split = True
cmd = list(cmd)
try:
print "Attempting to clone {}".format(url)
subprocess.check_call(cmd, cwd=dest, stdout=sys.stdout, stderr=sys.stderr)
except subprocess.CalledProcessError:
errormsg = 'Unable to clone "{}".'.format(url)
raise ZephyrLaunchError(errormsg)
parser = argparse.ArgumentParser()
parser.add_argument("--git", nargs='+', help="git repo with zephyr kernel source")
parser.add_argument("--workdir", default='/workdir',
help="Directory containing the zephyr kernel source. "
"Or the location to prepare the git repo"
"if --git was specfied.")
args = parser.parse_args()
if args.git is not None:
args.git = (','.join(args.git)).replace(":|", " ")
try:
if not os.path.exists(args.workdir):
os.mkdir(args.workdir)
zephyrfound = os.path.exists(os.path.join(args.workdir,"zephyr"))
if not zephyrfound and args.git is None:
errormsg = ('You need to check out a zephyr kernel to build zephyr apps, e.g. git clone https://gerrit.zephyrproject.org/r/zephyr')
print(errormsg)
elif args.git is not None:
clone_zephyr(args.git, args.workdir)
cmd = 'bash -c'.split()
args = 'cd {}; exec bash -i'.format(args.workdir)
os.execvp(cmd[0], cmd + [args])
except ZephyrLaunchError as e:
print e