Skip to content

Commit daf29dc

Browse files
authored
Merge pull request #6153 from theotherjimmy/correct-export-clean
Correct exporter clean behavior
2 parents 7f81280 + ed7793d commit daf29dc

File tree

21 files changed

+176
-55
lines changed

21 files changed

+176
-55
lines changed

tools/export/atmelstudio/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717
import uuid
1818
from os.path import splitext, basename, dirname
19+
from os import remove
1920

2021
from tools.export.exporters import Exporter, deprecated_exporter
2122

@@ -83,3 +84,8 @@ def generate(self):
8384
target = self.target.lower()
8485
self.gen_file('atmelstudio/atsln.tmpl', ctx, '%s.atsln' % self.project_name)
8586
self.gen_file('atmelstudio/cppproj.tmpl', ctx, '%s.cppproj' % self.project_name)
87+
88+
@staticmethod
89+
def clean(project_name):
90+
remove('%s.atsln' % project_name)
91+
remove('%s.cppproj' % project_name)

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/cdt/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
22

33
from os.path import join, exists
4-
from os import makedirs
4+
from os import makedirs, remove
5+
import shutil
56

67
from tools.export.makefile import Makefile, GccArm, Armc5, IAR
78

@@ -39,6 +40,12 @@ def generate(self):
3940
self.gen_file('cdt/.cproject.tmpl', ctx, '.cproject')
4041
self.gen_file('cdt/.project.tmpl', ctx, '.project')
4142

43+
@staticmethod
44+
def clean(project_name):
45+
shutil.rmtree("eclipse-extras")
46+
remove(".cproject")
47+
remove(".project")
48+
4249

4350
class EclipseGcc(Eclipse, GccArm):
4451
LOAD_EXE = True

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/cmsis/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,8 @@ def generate(self):
153153
'date': ''
154154
}
155155
self.gen_file('cmsis/cpdsc.tmpl', ctx, 'project.cpdsc')
156+
157+
158+
@staticmethod
159+
def clean(_):
160+
os.remove('project.cpdsc')

tools/export/coide/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
limitations under the License.
1616
"""
1717
from os.path import splitext, basename
18+
from os import remove
1819

1920
from tools.export.exporters import Exporter, deprecated_exporter
2021

@@ -109,3 +110,7 @@ def generate(self):
109110

110111
# Project file
111112
self.gen_file('coide/%s.coproj.tmpl' % target, ctx, '%s.coproj' % self.project_name)
113+
114+
@staticmethod
115+
def clean(project_name):
116+
remove('%s.coproj' % project_name)

tools/export/e2studio/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from os import remove
1718
from tools.export.gnuarmeclipse import GNUARMEclipse
1819

1920
class E2Studio(GNUARMEclipse):
@@ -39,3 +40,8 @@ def generate(self):
3940
self.gen_file('gnuarmeclipse/.project.tmpl', jinja_ctx, '.project', trim_blocks=True, lstrip_blocks=True)
4041
self.gen_file_nonoverwrite('gnuarmeclipse/mbedignore.tmpl', jinja_ctx, '.mbedignore')
4142
self.gen_file('gnuarmeclipse/makefile.targets.tmpl', jinja_ctx, 'makefile.targets', trim_blocks=True, lstrip_blocks=True)
43+
44+
@staticmethod
45+
def clean(project_name):
46+
remove('%s OpenOCD 5x.launch' % project_name)
47+
remove('%s OpenOCD.launch' % project_name)

tools/export/embitz/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
limitations under the License.
1616
"""
1717
from os.path import splitext, basename
18+
from os import remove
1819
from tools.targets import TARGET_MAP
1920
from tools.export.exporters import Exporter, apply_supported_whitelist
2021

@@ -87,3 +88,7 @@ def generate(self):
8788
}
8889

8990
self.gen_file('embitz/eix.tmpl', ctx, '%s.eix' % self.project_name)
91+
92+
@staticmethod
93+
def clean(project_name):
94+
remove("%s.eix" % project_name)

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):

0 commit comments

Comments
 (0)