mirror of https://github.com/ARMmbed/mbed-os.git
Use notifier api in export
parent
c686c6cb8b
commit
d422a5aadc
|
@ -205,19 +205,7 @@ def generate_project_files(resources, export_path, target, name, toolchain, ide,
|
||||||
return files, exporter
|
return files, exporter
|
||||||
|
|
||||||
|
|
||||||
def zip_export(file_name, prefix, resources, project_files, inc_repos):
|
def _inner_zip_export(resources, inc_repos):
|
||||||
"""Create a zip file from an exported project.
|
|
||||||
|
|
||||||
Positional Parameters:
|
|
||||||
file_name - the file name of the resulting zip file
|
|
||||||
prefix - a directory name that will prefix the entire zip file's contents
|
|
||||||
resources - a resources object with files that must be included in the zip
|
|
||||||
project_files - a list of extra files to be added to the root of the prefix
|
|
||||||
directory
|
|
||||||
"""
|
|
||||||
with zipfile.ZipFile(file_name, "w") as zip_file:
|
|
||||||
for prj_file in project_files:
|
|
||||||
zip_file.write(prj_file, join(prefix, basename(prj_file)))
|
|
||||||
for loc, res in resources.items():
|
for loc, res in resources.items():
|
||||||
to_zip = (
|
to_zip = (
|
||||||
res.headers + res.s_sources + res.c_sources +\
|
res.headers + res.s_sources + res.c_sources +\
|
||||||
|
@ -232,12 +220,37 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
|
||||||
to_zip.append(source)
|
to_zip.append(source)
|
||||||
res.file_basepath[source] = res.base_path
|
res.file_basepath[source] = res.base_path
|
||||||
to_zip += res.repo_files
|
to_zip += res.repo_files
|
||||||
|
yield loc, to_zip
|
||||||
|
|
||||||
|
def zip_export(file_name, prefix, resources, project_files, inc_repos, notify):
|
||||||
|
"""Create a zip file from an exported project.
|
||||||
|
|
||||||
|
Positional Parameters:
|
||||||
|
file_name - the file name of the resulting zip file
|
||||||
|
prefix - a directory name that will prefix the entire zip file's contents
|
||||||
|
resources - a resources object with files that must be included in the zip
|
||||||
|
project_files - a list of extra files to be added to the root of the prefix
|
||||||
|
directory
|
||||||
|
"""
|
||||||
|
to_zip_list = list(_inner_zip_export(resources, inc_repos))
|
||||||
|
total_files = sum(len(to_zip) for _, to_zip in to_zip_list)
|
||||||
|
total_files += len(project_files)
|
||||||
|
zipped = 0
|
||||||
|
with zipfile.ZipFile(file_name, "w") as zip_file:
|
||||||
|
for prj_file in project_files:
|
||||||
|
zip_file.write(prj_file, join(prefix, basename(prj_file)))
|
||||||
|
for loc, to_zip in to_zip_list:
|
||||||
|
res = resources[loc]
|
||||||
for source in to_zip:
|
for source in to_zip:
|
||||||
if source:
|
if source:
|
||||||
zip_file.write(
|
zip_file.write(
|
||||||
source,
|
source,
|
||||||
join(prefix, loc,
|
join(prefix, loc,
|
||||||
relpath(source, res.file_basepath[source])))
|
relpath(source, res.file_basepath[source])))
|
||||||
|
notify.progress("Zipping", source,
|
||||||
|
100 * (zipped / total_files))
|
||||||
|
zipped += 1
|
||||||
|
for lib, res in resources.items():
|
||||||
for source in res.lib_builds:
|
for source in res.lib_builds:
|
||||||
target_dir, _ = splitext(source)
|
target_dir, _ = splitext(source)
|
||||||
dest = join(prefix, loc,
|
dest = join(prefix, loc,
|
||||||
|
@ -248,10 +261,9 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
|
||||||
|
|
||||||
|
|
||||||
def export_project(src_paths, export_path, target, ide, libraries_paths=None,
|
def export_project(src_paths, export_path, target, ide, libraries_paths=None,
|
||||||
linker_script=None, notify=None, verbose=False, name=None,
|
linker_script=None, notify=None, name=None, inc_dirs=None,
|
||||||
inc_dirs=None, jobs=1, silent=False, extra_verbose=False,
|
jobs=1, config=None, macros=None, zip_proj=None,
|
||||||
config=None, macros=None, zip_proj=None, inc_repos=False,
|
inc_repos=False, build_profile=None, app_config=None):
|
||||||
build_profile=None, app_config=None):
|
|
||||||
"""Generates a project file and creates a zip archive if specified
|
"""Generates a project file and creates a zip archive if specified
|
||||||
|
|
||||||
Positional Arguments:
|
Positional Arguments:
|
||||||
|
@ -265,13 +277,9 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
|
||||||
linker_script - path to the linker script for the specified target
|
linker_script - path to the linker script for the specified target
|
||||||
notify - function is passed all events, and expected to handle notification
|
notify - function is passed all events, and expected to handle notification
|
||||||
of the user, emit the events to a log, etc.
|
of the user, emit the events to a log, etc.
|
||||||
verbose - assigns the notify function to toolchains print_notify_verbose
|
|
||||||
name - project name
|
name - project name
|
||||||
inc_dirs - additional include directories
|
inc_dirs - additional include directories
|
||||||
jobs - number of threads
|
jobs - number of threads
|
||||||
silent - silent build - no output
|
|
||||||
extra_verbose - assigns the notify function to toolchains
|
|
||||||
print_notify_verbose
|
|
||||||
config - toolchain's config object
|
config - toolchain's config object
|
||||||
macros - User-defined macros
|
macros - User-defined macros
|
||||||
zip_proj - string name of the zip archive you wish to creat (exclude arg
|
zip_proj - string name of the zip archive you wish to creat (exclude arg
|
||||||
|
@ -302,8 +310,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
|
||||||
# Pass all params to the unified prepare_resources()
|
# Pass all params to the unified prepare_resources()
|
||||||
toolchain = prepare_toolchain(
|
toolchain = prepare_toolchain(
|
||||||
paths, "", target, toolchain_name, macros=macros, jobs=jobs,
|
paths, "", target, toolchain_name, macros=macros, jobs=jobs,
|
||||||
notify=notify, silent=silent, verbose=verbose,
|
notify=notify, config=config, build_profile=build_profile,
|
||||||
extra_verbose=extra_verbose, config=config, build_profile=build_profile,
|
|
||||||
app_config=app_config)
|
app_config=app_config)
|
||||||
# The first path will give the name to the library
|
# The first path will give the name to the library
|
||||||
toolchain.RESPONSE_FILES = False
|
toolchain.RESPONSE_FILES = False
|
||||||
|
@ -349,10 +356,10 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
|
||||||
resource.add(res)
|
resource.add(res)
|
||||||
if isinstance(zip_proj, basestring):
|
if isinstance(zip_proj, basestring):
|
||||||
zip_export(join(export_path, zip_proj), name, resource_dict,
|
zip_export(join(export_path, zip_proj), name, resource_dict,
|
||||||
files + list(exporter.static_files), inc_repos)
|
files + list(exporter.static_files), inc_repos, notify)
|
||||||
else:
|
else:
|
||||||
zip_export(zip_proj, name, resource_dict,
|
zip_export(zip_proj, name, resource_dict,
|
||||||
files + list(exporter.static_files), inc_repos)
|
files + list(exporter.static_files), inc_repos, notify)
|
||||||
else:
|
else:
|
||||||
for static_file in exporter.static_files:
|
for static_file in exporter.static_files:
|
||||||
if not exists(join(export_path, basename(static_file))):
|
if not exists(join(export_path, basename(static_file))):
|
||||||
|
|
|
@ -26,6 +26,7 @@ from tools.utils import argparse_force_uppercase_type
|
||||||
from tools.utils import print_large_string
|
from tools.utils import print_large_string
|
||||||
from tools.utils import NotSupportedException
|
from tools.utils import NotSupportedException
|
||||||
from tools.options import extract_profile, list_profiles, extract_mcus
|
from tools.options import extract_profile, list_profiles, extract_mcus
|
||||||
|
from tools.notifier.term import TerminalNotifier
|
||||||
|
|
||||||
def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None):
|
def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None):
|
||||||
"""Generate a name, if not provided, and find dependencies
|
"""Generate a name, if not provided, and find dependencies
|
||||||
|
@ -71,7 +72,7 @@ def setup_project(ide, target, program=None, source_dir=None, build=None, export
|
||||||
|
|
||||||
|
|
||||||
def export(target, ide, build=None, src=None, macros=None, project_id=None,
|
def export(target, ide, build=None, src=None, macros=None, project_id=None,
|
||||||
zip_proj=False, build_profile=None, export_path=None, silent=False,
|
zip_proj=False, build_profile=None, export_path=None, notify=None,
|
||||||
app_config=None):
|
app_config=None):
|
||||||
"""Do an export of a project.
|
"""Do an export of a project.
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
|
||||||
|
|
||||||
return export_project(src, project_dir, target, ide, name=name,
|
return export_project(src, project_dir, target, ide, name=name,
|
||||||
macros=macros, libraries_paths=lib, zip_proj=zip_name,
|
macros=macros, libraries_paths=lib, zip_proj=zip_name,
|
||||||
build_profile=build_profile, silent=silent,
|
build_profile=build_profile, notify=notify,
|
||||||
app_config=app_config)
|
app_config=app_config)
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,6 +248,8 @@ def main():
|
||||||
|
|
||||||
zip_proj = not bool(options.source_dir)
|
zip_proj = not bool(options.source_dir)
|
||||||
|
|
||||||
|
notify = TerminalNotifier()
|
||||||
|
|
||||||
if (options.program is None) and (not options.source_dir):
|
if (options.program is None) and (not options.source_dir):
|
||||||
args_error(parser, "one of -p, -n, or --source is required")
|
args_error(parser, "one of -p, -n, or --source is required")
|
||||||
exporter, toolchain_name = get_exporter_toolchain(options.ide)
|
exporter, toolchain_name = get_exporter_toolchain(options.ide)
|
||||||
|
@ -270,7 +273,7 @@ def main():
|
||||||
src=options.source_dir, macros=options.macros,
|
src=options.source_dir, macros=options.macros,
|
||||||
project_id=options.program, zip_proj=zip_proj,
|
project_id=options.program, zip_proj=zip_proj,
|
||||||
build_profile=profile, app_config=options.app_config,
|
build_profile=profile, app_config=options.app_config,
|
||||||
export_path=options.build_dir)
|
export_path=options.build_dir, notify = notify)
|
||||||
except NotSupportedException as exc:
|
except NotSupportedException as exc:
|
||||||
print("[ERROR] %s" % str(exc))
|
print("[ERROR] %s" % str(exc))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue