Skip to content

Commit 6838aa9

Browse files
committed
Clean code style of python code for generic make
1 parent 920bb47 commit 6838aa9

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

tools/export/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
'uvision4': uvision4.Uvision4,
3333
'uvision5': uvision5.Uvision5,
3434
'lpcxpresso': codered.CodeRed,
35-
'gcc_arm': makefile.GccArm_Exporter,
36-
'make_gcc_arm': makefile.GccArm_Exporter,
37-
'make_armc5': makefile.Armc5_Exporter,
38-
'make_iar': makefile.IAR_Exporter,
35+
'gcc_arm': makefile.GccArm,
36+
'make_gcc_arm': makefile.GccArm,
37+
'make_armc5': makefile.Armc5,
38+
'make_iar': makefile.IAR,
3939
'ds5_5': ds5_5.DS5_5,
4040
'iar': iar.IAREmbeddedWorkbench,
4141
'emblocks' : emblocks.IntermediateFile,

tools/export/makefile/__init__.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,48 @@
1717
from os.path import splitext, basename, relpath, join, abspath, dirname,\
1818
exists
1919
from os import curdir, getcwd
20+
from jinja2.exceptions import TemplateNotFound
2021
from tools.export.exporters import Exporter
2122
from tools.utils import NotSupportedException
2223
from tools.targets import TARGET_MAP
23-
from jinja2.exceptions import TemplateNotFound
2424

2525

2626
class Makefile(Exporter):
27+
"""Generic Makefile template that mimics the behavior of the python build
28+
system
29+
"""
2730

2831
DOT_IN_RELATIVE_PATH = True
2932

3033
MBED_CONFIG_HEADER_SUPPORTED = True
3134

3235
def generate(self):
33-
# "make" wants Unix paths
36+
"""Generate the makefile
37+
38+
Note: subclasses should not need to override this method
39+
"""
3440
self.resources.win_to_unix()
3541

36-
to_be_compiled = []
37-
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
38-
r = getattr(self.resources, r_type)
39-
if r:
40-
for source in r:
41-
base, ext = splitext(source)
42-
to_be_compiled.append(base + '.o')
42+
to_be_compiled = [splitext(src)[0] + ".o" for src in
43+
self.resources['s_sources'] +
44+
self.resources['c_sources'] +
45+
self.resources['cpp_sources']]
4346

44-
libraries = []
45-
for lib in self.resources.libraries:
46-
l, _ = splitext(basename(lib))
47-
libraries.append(l[3:])
47+
libraries = [splitext(lib)[0][3:] for lib in self.resources.libraries]
4848

4949
ctx = {
5050
'name': self.project_name,
5151
'to_be_compiled': to_be_compiled,
5252
'object_files': self.resources.objects,
53-
'include_paths': self.resources.inc_dirs,
53+
'include_paths': list(set(self.resources.inc_dirs)),
5454
'library_paths': self.resources.lib_dirs,
5555
'linker_script': self.resources.linker_script,
5656
'libraries': libraries,
5757
'symbols': self.toolchain.get_symbols(),
5858
'hex_files': self.resources.hex_files,
5959
'vpath': (["../../.."]
60-
if basename(dirname(dirname(self.export_dir))) == "projectfiles"
60+
if (basename(dirname(dirname(self.export_dir)))
61+
== "projectfiles")
6162
else [".."]),
6263
'cc_cmd': " ".join(self.toolchain.cc),
6364
'cppc_cmd': " ".join(self.toolchain.cppc),
@@ -68,15 +69,16 @@ def generate(self):
6869
'link_script_option': self.LINK_SCRIPT_OPTION,
6970
}
7071

71-
for key in ['include_paths', 'library_paths', 'linker_script', 'hex_files']:
72+
for key in ['include_paths', 'library_paths', 'linker_script',
73+
'hex_files']:
7274
if isinstance(ctx[key], list):
7375
ctx[key] = [ctx['vpath'][0] + "/" + t for t in ctx[key]]
7476
else:
7577
ctx[key] = ctx['vpath'][0] + "/" + ctx[key]
7678
if "../." not in ctx["include_paths"]:
7779
ctx["include_paths"] += ['../.']
78-
ctx["include_paths"] = list(set(ctx["include_paths"]))
79-
for key in ['include_paths', 'library_paths', 'hex_files', 'to_be_compiled', 'symbols']:
80+
for key in ['include_paths', 'library_paths', 'hex_files',
81+
'to_be_compiled', 'symbols']:
8082
ctx[key] = sorted(ctx[key])
8183
ctx.update(self.flags)
8284

@@ -96,23 +98,26 @@ def generate(self):
9698
raise NotSupportedException("This make tool is in development")
9799

98100

99-
class GccArm_Exporter(Makefile):
101+
class GccArm(Makefile):
102+
"""GCC ARM specific makefile target"""
100103
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
101104
if "GCC_ARM" in obj.supported_toolchains]
102105
NAME = 'Make-GCC-ARM'
103106
TOOLCHAIN = "GCC_ARM"
104107
LINK_SCRIPT_OPTION = "-T"
105108

106109

107-
class Armc5_Exporter(Makefile):
110+
class Armc5(Makefile):
111+
"""ARM Compiler 5 specific makefile target"""
108112
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
109113
if "ARM" in obj.supported_toolchains]
110114
NAME = 'Make-ARMc5'
111115
TOOLCHAIN = "ARM"
112116
LINK_SCRIPT_OPTION = "--scatter"
113117

114118

115-
class IAR_Exporter(Makefile):
119+
class IAR(Makefile):
120+
"""IAR specific makefile target"""
116121
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
117122
if "IAR" in obj.supported_toolchains]
118123
NAME = 'Make-IAR'

0 commit comments

Comments
 (0)