Skip to content

Commit bd5b34f

Browse files
committed
Correct exporter clean behavior
1 parent 6693b08 commit bd5b34f

File tree

10 files changed

+108
-48
lines changed

10 files changed

+108
-48
lines changed

tools/export/cces/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ def generate(self):
408408

409409
print("CCES files generated.")
410410

411+
412+
@staticmethod
413+
def clean(_):
414+
os.remove('cces.json')
415+
os.remove('README.md')
416+
411417
@staticmethod
412418
def build(project_name, log_name='build_log.txt', cleanup=True):
413419
"""
@@ -436,6 +442,7 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
436442
# cleanup workspace
437443
if os.path.exists(workspace):
438444
shutil.rmtree(workspace, True)
445+
CCES.clean(project_name)
439446

440447
# check return code for failure
441448
if ret_code != 0:

tools/export/cmake/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def generate(self):
112112
except TemplateNotFound:
113113
pass
114114

115+
@staticmethod
116+
def clean(_):
117+
remove("CMakeLists.txt")
118+
# legacy .build directory cleaned if exists
119+
if exists('.build'):
120+
shutil.rmtree('.build')
121+
if exists('BUILD'):
122+
shutil.rmtree('BUILD')
123+
115124
@staticmethod
116125
def build(project_name, log_name="build_log.txt", cleanup=True):
117126
""" Build Make project """
@@ -162,13 +171,8 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
162171

163172
# Cleanup the exported and built files
164173
if cleanup:
165-
remove("CMakeLists.txt")
166174
remove(log_name)
167-
# legacy .build directory cleaned if exists
168-
if exists('.build'):
169-
shutil.rmtree('.build')
170-
if exists('BUILD'):
171-
shutil.rmtree('BUILD')
175+
CMake.clean(project_name)
172176

173177
if ret_code != 0:
174178
# Seems like something went wrong.

tools/export/exporters.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Exporter(object):
5050
NAME = None
5151
TARGETS = set()
5252
TOOLCHAIN = None
53+
CLEAN_FILES = ("GettingStarted.html",)
5354

5455

5556
def __init__(self, target, export_dir, project_name, toolchain,
@@ -217,12 +218,28 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
217218
218219
Returns -1 on failure and 0 on success
219220
"""
220-
raise NotImplemented("Implement in derived Exporter class.")
221+
raise NotImplementedError("Implement in derived Exporter class.")
222+
223+
@staticmethod
224+
def clean(project_name):
225+
"""Clean a previously exported project
226+
This method is assumed to be executed at the same level as exporter
227+
project files and project source code.
228+
See uvision/__init__.py, iar/__init__.py, and makefile/__init__.py for
229+
example implemenation.
230+
231+
Positional Arguments:
232+
project_name - the name of the project to build; often required by
233+
exporter's build command.
234+
235+
Returns nothing. May raise exceptions
236+
"""
237+
raise NotImplementedError("Implement in derived Exporter class.")
221238

222239
@abstractmethod
223240
def generate(self):
224241
"""Generate an IDE/tool specific project file"""
225-
raise NotImplemented("Implement a generate function in Exporter child class")
242+
raise NotImplementedError("Implement a generate function in Exporter child class")
226243

227244
@classmethod
228245
def is_target_supported(cls, target_name):

tools/export/gnuarmeclipse/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ def generate(self):
299299
print
300300
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
301301

302+
@staticmethod
303+
def clean(_):
304+
os.remove('.project')
305+
os.remove('.cproject')
306+
if exists('Debug'):
307+
shutil.rmtree('Debug')
308+
if exists('Release'):
309+
shutil.rmtree('Release')
310+
if exists('makefile.targets'):
311+
os.remove('makefile.targets')
312+
302313
# override
303314
@staticmethod
304315
def build(project_name, log_name="build_log.txt", cleanup=True):
@@ -366,14 +377,6 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
366377
if cleanup:
367378
if exists(log_name):
368379
os.remove(log_name)
369-
os.remove('.project')
370-
os.remove('.cproject')
371-
if exists('Debug'):
372-
shutil.rmtree('Debug')
373-
if exists('Release'):
374-
shutil.rmtree('Release')
375-
if exists('makefile.targets'):
376-
os.remove('makefile.targets')
377380

378381
# Always remove the temporary folder.
379382
if exists(tmp_folder):

tools/export/iar/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ def generate(self):
138138
self.gen_file('iar/ewd.tmpl', ctx, self.project_name + ".ewd")
139139
self.gen_file('iar/ewp.tmpl', ctx, self.project_name + ".ewp")
140140

141+
@staticmethod
142+
def clean(project_name):
143+
os.remove(project_name + ".ewp")
144+
os.remove(project_name + ".ewd")
145+
os.remove(project_name + ".eww")
146+
# legacy output file location
147+
if exists('.build'):
148+
shutil.rmtree('.build')
149+
if exists('BUILD'):
150+
shutil.rmtree('BUILD')
151+
141152
@staticmethod
142153
def build(project_name, log_name="build_log.txt", cleanup=True):
143154
""" Build IAR project """
@@ -179,14 +190,7 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
179190

180191
# Cleanup the exported and built files
181192
if cleanup:
182-
os.remove(project_name + ".ewp")
183-
os.remove(project_name + ".ewd")
184-
os.remove(project_name + ".eww")
185-
# legacy output file location
186-
if exists('.build'):
187-
shutil.rmtree('.build')
188-
if exists('BUILD'):
189-
shutil.rmtree('BUILD')
193+
IAR.clean(project_name)
190194

191195
if ret_code !=0:
192196
# Seems like something went wrong.

tools/export/makefile/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ def format_flags(self):
148148

149149
return flags
150150

151+
@staticmethod
152+
def clean(_):
153+
remove("Makefile")
154+
# legacy .build directory cleaned if exists
155+
if exists('.build'):
156+
shutil.rmtree('.build')
157+
if exists('BUILD'):
158+
shutil.rmtree('BUILD')
159+
151160
@staticmethod
152161
def build(project_name, log_name="build_log.txt", cleanup=True):
153162
""" Build Make project """
@@ -178,13 +187,8 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
178187

179188
# Cleanup the exported and built files
180189
if cleanup:
181-
remove("Makefile")
182190
remove(log_name)
183-
# legacy .build directory cleaned if exists
184-
if exists('.build'):
185-
shutil.rmtree('.build')
186-
if exists('BUILD'):
187-
shutil.rmtree('BUILD')
191+
Makefile.clean(project_name)
188192

189193
if ret_code != 0:
190194
# Seems like something went wrong.

tools/export/mcuxpresso/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ def generate(self):
230230
print
231231
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
232232

233+
@staticmethod
234+
def clean(_):
235+
remove('.project')
236+
remove('.cproject')
237+
if exists('Debug'):
238+
shutil.rmtree('Debug')
239+
if exists('Release'):
240+
shutil.rmtree('Release')
241+
if exists('makefile.targets'):
242+
remove('makefile.targets')
243+
233244
# override
234245
@staticmethod
235246
def build(project_name, log_name="build_log.txt", cleanup=True):
@@ -299,14 +310,7 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
299310
if cleanup:
300311
if exists(log_name):
301312
remove(log_name)
302-
remove('.project')
303-
remove('.cproject')
304-
if exists('Debug'):
305-
shutil.rmtree('Debug')
306-
if exists('Release'):
307-
shutil.rmtree('Release')
308-
if exists('makefile.targets'):
309-
remove('makefile.targets')
313+
MCUXpresso.clean(project_name)
310314

311315
# Always remove the temporary folder.
312316
if exists(tmp_folder):

tools/export/nb/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import copy
3+
import shutil
34

45
from os.path import relpath, join, exists, dirname, basename
56
from os import makedirs
@@ -275,6 +276,11 @@ def generate(self):
275276
print
276277
print 'Done. Import the \'{0}\' project in Netbeans.'.format(self.project_name)
277278

279+
@staticmethod
280+
def clean(_):
281+
shutil.rmtree("nbproject")
282+
remove("Makefile")
283+
278284
# -------------------------------------------------------------------------
279285

280286
@staticmethod

tools/export/uvision/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ def generate(self):
238238
self.gen_file('uvision/uvision.tmpl', ctx, self.project_name+".uvprojx")
239239
self.gen_file('uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx")
240240

241+
@staticmethod
242+
def clean(project_name):
243+
os.remove(project_name + ".uvprojx")
244+
os.remove(project_name + ".uvoptx")
245+
# legacy .build directory cleaned if exists
246+
if exists('.build'):
247+
shutil.rmtree('.build')
248+
if exists('BUILD'):
249+
shutil.rmtree('BUILD')
250+
241251
@staticmethod
242252
def build(project_name, log_name='build_log.txt', cleanup=True):
243253
""" Build Uvision project """
@@ -257,13 +267,7 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
257267
# Cleanup the exported and built files
258268
if cleanup:
259269
os.remove(log_name)
260-
os.remove(project_name+".uvprojx")
261-
os.remove(project_name+".uvoptx")
262-
# legacy .build directory cleaned if exists
263-
if exists('.build'):
264-
shutil.rmtree('.build')
265-
if exists('BUILD'):
266-
shutil.rmtree('BUILD')
270+
Uvision.clean(project_name)
267271

268272
# Returns 0 upon success, 1 upon a warning, and neither upon an error
269273
if ret_code != 0 and ret_code != 1:

tools/project.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"""
44
from __future__ import absolute_import, print_function
55
import sys
6-
from os.path import join, abspath, dirname, exists, basename
6+
from os.path import (join, abspath, dirname, exists, basename, normpath,
7+
realpath, basename)
8+
from os import remove
79
ROOT = abspath(join(dirname(__file__), ".."))
810
sys.path.insert(0, ROOT)
911

1012
from shutil import move, rmtree
1113
from argparse import ArgumentParser
12-
from os.path import normpath, realpath
1314

1415
from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES, MBED_TARGETS_PATH
1516
from tools.settings import BUILD_DIR
@@ -247,7 +248,13 @@ def main():
247248
args_error(parser, "%s not supported by %s"%(mcu,options.ide))
248249
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
249250
if options.clean:
250-
rmtree(BUILD_DIR)
251+
for cls in EXPORTERS.values():
252+
try:
253+
cls.clean(basename(abspath(options.source_dir[0])))
254+
except (NotImplementedError, IOError, OSError):
255+
pass
256+
for f in EXPORTERS.values()[0].CLEAN_FILES:
257+
remove(f)
251258
try:
252259
export(mcu, options.ide, build=options.build,
253260
src=options.source_dir, macros=options.macros,

0 commit comments

Comments
 (0)