forked from seL4/sel4-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
83 lines (73 loc) · 2.51 KB
/
common.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
#!/usr/bin/env python
#
# Copyright 2018, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#
import os
import sys
import sh
import logging
# Define how to configure each platform in terms of arguments passed to cmake
PLAT_CONFIG = {
'pc99': ['-DTUT_BOARD=pc', '-DTUT_ARCH=x86_64'],
'zynq7000': ['-DAARCH32=TRUE', '-DTUT_BOARD=zynq7000'],
}
ALL_CONFIGS = PLAT_CONFIG.keys()
# Declare each tutorial and the configs they support
TUTORIALS = {
'hello-1': ALL_CONFIGS,
'hello-2': ALL_CONFIGS,
'hello-2-nolibs': ALL_CONFIGS,
'hello-3': ALL_CONFIGS,
'hello-3-nolibs': ALL_CONFIGS,
'hello-4': ALL_CONFIGS,
'hello-timer': ALL_CONFIGS,
'hello-camkes-0': ALL_CONFIGS,
'hello-camkes-1': ALL_CONFIGS,
'hello-camkes-2': ALL_CONFIGS,
'hello-camkes-timer': ['zynq7000'],
}
ALL_TUTORIALS = TUTORIALS.keys()
def get_tutorial_dir():
'''Return directory containing sel4 tutorials repo'''
return os.path.dirname(os.path.realpath(__file__))
def get_project_root():
'''Returns the path to the root directory of this project'''
# assume default location of this project in projects/sel4-tutorials
return os.path.join(get_tutorial_dir(), '..', '..')
def init_build_directory(config, tut, solution, directory, output=None):
tut_arg = "-DTUTORIAL=" + tut
args = ['-DCMAKE_TOOLCHAIN_FILE=../kernel/gcc.cmake', '-G', 'Ninja'] + PLAT_CONFIG[config] + [tut_arg];
if solution:
args = args + ["-DBUILD_SOLUTIONS=TRUE"]
result = sh.cmake(args + ['..'], _cwd = directory, _out=output)
if result.exit_code != 0:
return result
sh.cmake(['..'], _cwd = directory, _out=output)
if result.exit_code != 0:
return result
sh.cmake(['..'], _cwd = directory, _out=output)
if result.exit_code != 0:
return result
return sh.cmake(['..'], _cwd = directory, _out=output)
def set_log_level(verbose, quiet):
if verbose:
logging.basicConfig(level=logging.DEBUG)
elif quiet:
logging.basicConfig(level=logging.ERROR)
else:
logging.basicConfig(level=logging.INFO)
def setup_logger(name):
logger = logging.getLogger(name)
ch = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger