Skip to content

Commit 73e811a

Browse files
committed
Fix style of implementation of toolchain profiles
1 parent c86ad66 commit 73e811a

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

tools/options.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ def get_default_options_parser(add_clean=True, add_options=True,
8484

8585

8686
def extract_profile(parser, options, toolchain):
87-
profile = { 'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
87+
"""Extract a Toolchain profile from parsed options
88+
89+
Positional arguments:
90+
parser - parser used to parse the command line arguments
91+
options - The parsed command line arguments
92+
toolchain - the toolchain that the profile should be extracted for
93+
"""
94+
profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
8895
filenames = options.profile or [join(dirname(__file__), "profiles",
8996
"default.json")]
9097
for filename in filenames:

tools/test/toolchains/api.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
"""Tests for the toolchain sub-system"""
12
import sys
23
import os
34
from string import printable
45
from copy import deepcopy
56
from hypothesis import given
67
from hypothesis.strategies import text, lists, fixed_dictionaries
78

8-
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
9+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
10+
".."))
911
sys.path.insert(0, ROOT)
1012

1113
from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES
1214
from tools.targets import TARGET_MAP
1315

1416
def test_instantiation():
15-
for name, Class in TOOLCHAIN_CLASSES.items():
16-
CLS = Class(TARGET_MAP["K64F"])
17-
assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]
17+
"""Test that all exported toolchain may be instantiated"""
18+
for name, tc_class in TOOLCHAIN_CLASSES.items():
19+
cls = tc_class(TARGET_MAP["K64F"])
20+
assert name == cls.name or\
21+
name == LEGACY_TOOLCHAIN_NAMES[cls.name]
1822

1923
ALPHABET = [char for char in printable if char not in [u'.', u'/']]
2024

@@ -24,62 +28,71 @@ def test_instantiation():
2428
'cxx': lists(text()),
2529
'asm': lists(text()),
2630
'ld': lists(text())}),
27-
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
28-
)
31+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
2932
def test_toolchain_profile_c(profile, source_file):
33+
"""Test that the appropriate profile parameters are passed to the
34+
C compiler"""
3035
filename = deepcopy(source_file)
3136
filename[-1] += ".c"
3237
to_compile = os.path.join(*filename)
33-
for name, Class in TOOLCHAIN_CLASSES.items():
34-
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
35-
CLS.inc_md5 = ""
36-
CLS.build_dir = ""
37-
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
38+
for _, tc_class in TOOLCHAIN_CLASSES.items():
39+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
40+
toolchain.inc_md5 = ""
41+
toolchain.build_dir = ""
42+
compile_command = toolchain.compile_command(to_compile,
43+
to_compile + ".o", [])
3844
for parameter in profile['c'] + profile['common']:
3945
assert any(parameter in cmd for cmd in compile_command), \
40-
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
46+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
47+
parameter)
4148

4249
@given(fixed_dictionaries({
4350
'common': lists(text()),
4451
'c': lists(text()),
4552
'cxx': lists(text()),
4653
'asm': lists(text()),
4754
'ld': lists(text())}),
48-
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
49-
)
55+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
5056
def test_toolchain_profile_cpp(profile, source_file):
57+
"""Test that the appropriate profile parameters are passed to the
58+
C++ compiler"""
5159
filename = deepcopy(source_file)
5260
filename[-1] += ".cpp"
5361
to_compile = os.path.join(*filename)
54-
for name, Class in TOOLCHAIN_CLASSES.items():
55-
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
56-
CLS.inc_md5 = ""
57-
CLS.build_dir = ""
58-
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
62+
for _, tc_class in TOOLCHAIN_CLASSES.items():
63+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
64+
toolchain.inc_md5 = ""
65+
toolchain.build_dir = ""
66+
compile_command = toolchain.compile_command(to_compile,
67+
to_compile + ".o", [])
5968
for parameter in profile['cxx'] + profile['common']:
6069
assert any(parameter in cmd for cmd in compile_command), \
61-
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
70+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
71+
parameter)
6272

6373
@given(fixed_dictionaries({
6474
'common': lists(text()),
6575
'c': lists(text()),
6676
'cxx': lists(text()),
6777
'asm': lists(text()),
6878
'ld': lists(text())}),
69-
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
70-
)
79+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
7180
def test_toolchain_profile_asm(profile, source_file):
81+
"""Test that the appropriate profile parameters are passed to the
82+
Assembler"""
7283
filename = deepcopy(source_file)
7384
filename[-1] += ".s"
7485
to_compile = os.path.join(*filename)
75-
for name, Class in TOOLCHAIN_CLASSES.items():
76-
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
77-
CLS.inc_md5 = ""
78-
CLS.build_dir = ""
79-
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
86+
for _, tc_class in TOOLCHAIN_CLASSES.items():
87+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
88+
toolchain.inc_md5 = ""
89+
toolchain.build_dir = ""
90+
compile_command = toolchain.compile_command(to_compile,
91+
to_compile + ".o", [])
8092
if not compile_command:
8193
assert compile_command, to_compile
8294
for parameter in profile['asm']:
8395
assert any(parameter in cmd for cmd in compile_command), \
84-
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
96+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
97+
parameter)
8598

0 commit comments

Comments
 (0)