Clone of official tools

Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
--- a/project_api.py	Mon Feb 13 09:29:13 2017 -0600
+++ b/project_api.py	Wed Feb 15 13:53:18 2017 -0600
@@ -134,11 +134,10 @@
 
 
 
-def export_project(src_paths, export_path, target, ide,
-                   libraries_paths=None, linker_script=None, clean=False,
-                   notify=None, verbose=False, name=None, inc_dirs=None,
-                   jobs=1, silent=False, extra_verbose=False, config=None,
-                   macros=None, zip_proj=None, inc_repos=False,
+def export_project(src_paths, export_path, target, ide, libraries_paths=None,
+                   linker_script=None, notify=None, verbose=False, name=None,
+                   inc_dirs=None, jobs=1, silent=False, extra_verbose=False,
+                   config=None, macros=None, zip_proj=None, inc_repos=False,
                    build_profile=None):
     """Generates a project file and creates a zip archive if specified
 
@@ -151,7 +150,6 @@
     Keyword Arguments:
     libraries_paths - paths to additional libraries
     linker_script - path to the linker script for the specified target
-    clean - removes the export_path if it exists
     notify - function is passed all events, and expected to handle notification
       of the user, emit the events to a log, etc.
     verbose - assigns the notify function to toolchains print_notify_verbose
@@ -183,60 +181,54 @@
         src_paths = {"": paths}
 
     # Export Directory
-    if exists(export_path) and clean:
-        rmtree(export_path)
     if not exists(export_path):
         makedirs(export_path)
 
     _, toolchain_name = get_exporter_toolchain(ide)
 
     # Pass all params to the unified prepare_resources()
-    toolchain = prepare_toolchain(paths, target, toolchain_name,
-                                  macros=macros, clean=clean, jobs=jobs,
-                                  notify=notify, silent=silent, verbose=verbose,
-                                  extra_verbose=extra_verbose, config=config,
-                                  build_profile=build_profile)
-    try:
-        # The first path will give the name to the library
-        if name is None:
-            name = basename(normpath(abspath(src_paths[0])))
+    toolchain = prepare_toolchain(paths, target, toolchain_name, macros=macros,
+                                  jobs=jobs, notify=notify, silent=silent,
+                                  verbose=verbose, extra_verbose=extra_verbose,
+                                  config=config, build_profile=build_profile)
+    # The first path will give the name to the library
+    if name is None:
+        name = basename(normpath(abspath(src_paths[0])))
 
-        # Call unified scan_resources
-        resource_dict = {loc: scan_resources(path, toolchain, inc_dirs=inc_dirs)
-                        for loc, path in src_paths.iteritems()}
-        resources = Resources()
-        toolchain.build_dir = export_path
-        config_header = toolchain.get_config_header()
-        resources.headers.append(config_header)
-        resources.file_basepath[config_header] = dirname(config_header)
+    # Call unified scan_resources
+    resource_dict = {loc: scan_resources(path, toolchain, inc_dirs=inc_dirs)
+                     for loc, path in src_paths.iteritems()}
+    resources = Resources()
+    toolchain.build_dir = export_path
+    config_header = toolchain.get_config_header()
+    resources.headers.append(config_header)
+    resources.file_basepath[config_header] = dirname(config_header)
 
-        if zip_proj:
-            subtract_basepath(resources, export_path)
-            for loc, res in resource_dict.iteritems():
-                temp = copy.deepcopy(res)
-                subtract_basepath(temp, export_path, loc)
-                resources.add(temp)
-        else:
-            for _, res in resource_dict.iteritems():
-                resources.add(res)
-
-        # Change linker script if specified
-        if linker_script is not None:
-            resources.linker_script = linker_script
+    if zip_proj:
+        subtract_basepath(resources, export_path)
+        for loc, res in resource_dict.iteritems():
+            temp = copy.deepcopy(res)
+            subtract_basepath(temp, export_path, loc)
+            resources.add(temp)
+    else:
+        for _, res in resource_dict.iteritems():
+            resources.add(res)
 
-        files, exporter = generate_project_files(resources, export_path,
-                                                target, name, toolchain, ide,
-                                                macros=macros)
-        files.append(config_header)
-        if zip_proj:
-            if isinstance(zip_proj, basestring):
-                zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos)
-            else:
-                zip_export(zip_proj, name, resource_dict, files, inc_repos)
+    # Change linker script if specified
+    if linker_script is not None:
+        resources.linker_script = linker_script
 
-        return exporter
-    except Exception as e:
-        toolchain.tool_error(str(e))
+    files, exporter = generate_project_files(resources, export_path,
+                                             target, name, toolchain, ide,
+                                             macros=macros)
+    files.append(config_header)
+    if zip_proj:
+        if isinstance(zip_proj, basestring):
+            zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos)
+        else:
+            zip_export(zip_proj, name, resource_dict, files, inc_repos)
+
+    return exporter
 
 
 def print_results(successes, failures, skips=None):