Correct exporter clean behavior

pull/6153/head
Jimmy Brisson 2018-02-21 09:26:14 -06:00
parent 6693b08cfc
commit bd5b34f59c
10 changed files with 108 additions and 48 deletions

View File

@ -408,6 +408,12 @@ class CCES(Exporter):
print("CCES files generated.")
@staticmethod
def clean(_):
os.remove('cces.json')
os.remove('README.md')
@staticmethod
def build(project_name, log_name='build_log.txt', cleanup=True):
"""
@ -436,6 +442,7 @@ class CCES(Exporter):
# cleanup workspace
if os.path.exists(workspace):
shutil.rmtree(workspace, True)
CCES.clean(project_name)
# check return code for failure
if ret_code != 0:

View File

@ -112,6 +112,15 @@ class CMake(Exporter):
except TemplateNotFound:
pass
@staticmethod
def clean(_):
remove("CMakeLists.txt")
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
@staticmethod
def build(project_name, log_name="build_log.txt", cleanup=True):
""" Build Make project """
@ -162,13 +171,8 @@ class CMake(Exporter):
# Cleanup the exported and built files
if cleanup:
remove("CMakeLists.txt")
remove(log_name)
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
CMake.clean(project_name)
if ret_code != 0:
# Seems like something went wrong.

View File

@ -50,6 +50,7 @@ class Exporter(object):
NAME = None
TARGETS = set()
TOOLCHAIN = None
CLEAN_FILES = ("GettingStarted.html",)
def __init__(self, target, export_dir, project_name, toolchain,
@ -217,12 +218,28 @@ class Exporter(object):
Returns -1 on failure and 0 on success
"""
raise NotImplemented("Implement in derived Exporter class.")
raise NotImplementedError("Implement in derived Exporter class.")
@staticmethod
def clean(project_name):
"""Clean a previously exported project
This method is assumed to be executed at the same level as exporter
project files and project source code.
See uvision/__init__.py, iar/__init__.py, and makefile/__init__.py for
example implemenation.
Positional Arguments:
project_name - the name of the project to build; often required by
exporter's build command.
Returns nothing. May raise exceptions
"""
raise NotImplementedError("Implement in derived Exporter class.")
@abstractmethod
def generate(self):
"""Generate an IDE/tool specific project file"""
raise NotImplemented("Implement a generate function in Exporter child class")
raise NotImplementedError("Implement a generate function in Exporter child class")
@classmethod
def is_target_supported(cls, target_name):

View File

@ -299,6 +299,17 @@ class GNUARMEclipse(Exporter):
print
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
@staticmethod
def clean(_):
os.remove('.project')
os.remove('.cproject')
if exists('Debug'):
shutil.rmtree('Debug')
if exists('Release'):
shutil.rmtree('Release')
if exists('makefile.targets'):
os.remove('makefile.targets')
# override
@staticmethod
def build(project_name, log_name="build_log.txt", cleanup=True):
@ -366,14 +377,6 @@ class GNUARMEclipse(Exporter):
if cleanup:
if exists(log_name):
os.remove(log_name)
os.remove('.project')
os.remove('.cproject')
if exists('Debug'):
shutil.rmtree('Debug')
if exists('Release'):
shutil.rmtree('Release')
if exists('makefile.targets'):
os.remove('makefile.targets')
# Always remove the temporary folder.
if exists(tmp_folder):

View File

@ -138,6 +138,17 @@ class IAR(Exporter):
self.gen_file('iar/ewd.tmpl', ctx, self.project_name + ".ewd")
self.gen_file('iar/ewp.tmpl', ctx, self.project_name + ".ewp")
@staticmethod
def clean(project_name):
os.remove(project_name + ".ewp")
os.remove(project_name + ".ewd")
os.remove(project_name + ".eww")
# legacy output file location
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
@staticmethod
def build(project_name, log_name="build_log.txt", cleanup=True):
""" Build IAR project """
@ -179,14 +190,7 @@ class IAR(Exporter):
# Cleanup the exported and built files
if cleanup:
os.remove(project_name + ".ewp")
os.remove(project_name + ".ewd")
os.remove(project_name + ".eww")
# legacy output file location
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
IAR.clean(project_name)
if ret_code !=0:
# Seems like something went wrong.

View File

@ -148,6 +148,15 @@ class Makefile(Exporter):
return flags
@staticmethod
def clean(_):
remove("Makefile")
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
@staticmethod
def build(project_name, log_name="build_log.txt", cleanup=True):
""" Build Make project """
@ -178,13 +187,8 @@ class Makefile(Exporter):
# Cleanup the exported and built files
if cleanup:
remove("Makefile")
remove(log_name)
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
Makefile.clean(project_name)
if ret_code != 0:
# Seems like something went wrong.

View File

@ -230,6 +230,17 @@ class MCUXpresso(GNUARMEclipse):
print
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
@staticmethod
def clean(_):
remove('.project')
remove('.cproject')
if exists('Debug'):
shutil.rmtree('Debug')
if exists('Release'):
shutil.rmtree('Release')
if exists('makefile.targets'):
remove('makefile.targets')
# override
@staticmethod
def build(project_name, log_name="build_log.txt", cleanup=True):
@ -299,14 +310,7 @@ class MCUXpresso(GNUARMEclipse):
if cleanup:
if exists(log_name):
remove(log_name)
remove('.project')
remove('.cproject')
if exists('Debug'):
shutil.rmtree('Debug')
if exists('Release'):
shutil.rmtree('Release')
if exists('makefile.targets'):
remove('makefile.targets')
MCUXpresso.clean(project_name)
# Always remove the temporary folder.
if exists(tmp_folder):

View File

@ -1,5 +1,6 @@
import os
import copy
import shutil
from os.path import relpath, join, exists, dirname, basename
from os import makedirs
@ -275,6 +276,11 @@ class GNUARMNetbeans(Exporter):
print
print 'Done. Import the \'{0}\' project in Netbeans.'.format(self.project_name)
@staticmethod
def clean(_):
shutil.rmtree("nbproject")
remove("Makefile")
# -------------------------------------------------------------------------
@staticmethod

View File

@ -238,6 +238,16 @@ class Uvision(Exporter):
self.gen_file('uvision/uvision.tmpl', ctx, self.project_name+".uvprojx")
self.gen_file('uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx")
@staticmethod
def clean(project_name):
os.remove(project_name + ".uvprojx")
os.remove(project_name + ".uvoptx")
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
@staticmethod
def build(project_name, log_name='build_log.txt', cleanup=True):
""" Build Uvision project """
@ -257,13 +267,7 @@ class Uvision(Exporter):
# Cleanup the exported and built files
if cleanup:
os.remove(log_name)
os.remove(project_name+".uvprojx")
os.remove(project_name+".uvoptx")
# legacy .build directory cleaned if exists
if exists('.build'):
shutil.rmtree('.build')
if exists('BUILD'):
shutil.rmtree('BUILD')
Uvision.clean(project_name)
# Returns 0 upon success, 1 upon a warning, and neither upon an error
if ret_code != 0 and ret_code != 1:

View File

@ -3,13 +3,14 @@ supported IDEs or project structures.
"""
from __future__ import absolute_import, print_function
import sys
from os.path import join, abspath, dirname, exists, basename
from os.path import (join, abspath, dirname, exists, basename, normpath,
realpath, basename)
from os import remove
ROOT = abspath(join(dirname(__file__), ".."))
sys.path.insert(0, ROOT)
from shutil import move, rmtree
from argparse import ArgumentParser
from os.path import normpath, realpath
from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES, MBED_TARGETS_PATH
from tools.settings import BUILD_DIR
@ -247,7 +248,13 @@ def main():
args_error(parser, "%s not supported by %s"%(mcu,options.ide))
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
if options.clean:
rmtree(BUILD_DIR)
for cls in EXPORTERS.values():
try:
cls.clean(basename(abspath(options.source_dir[0])))
except (NotImplementedError, IOError, OSError):
pass
for f in EXPORTERS.values()[0].CLEAN_FILES:
remove(f)
try:
export(mcu, options.ide, build=options.build,
src=options.source_dir, macros=options.macros,