diff --git a/docs/DEVELOPERS-GUIDE.md b/docs/DEVELOPERS-GUIDE.md index 7d56f5845..f0837f184 100644 --- a/docs/DEVELOPERS-GUIDE.md +++ b/docs/DEVELOPERS-GUIDE.md @@ -31,7 +31,11 @@ $ venv/Scripts/deactivate Mbedcli project lists compile ``` $ venv/Scripts/activate -$ pip install -r requirements3.txt +$ pip install -r requirements.txt +$ mbed deploy +$ mbed update +$ mbed config root . +$ mbed config ARM_PATH FULL_PATH_TO_ARMCC_FOLDER $ tools/mbedcli_compile.py project1 project2 project3 --clean $ venv/Scripts/deactivate ``` @@ -54,7 +58,8 @@ mbedcli should be included in the python package or requirements.txt. Currently Arguments ``` positional arguments: - projects Selectively compile only the firmware specified otherwise all projects + projects Selectively compile only the firmware specified + otherwise all projects optional arguments: -h, --help show this help message and exit @@ -66,6 +71,7 @@ optional arguments: --toolchain TOOLCHAIN Toolchain directory if present --clean Rebuild or delete build folder before compile + -v Pass verbosity level to mbed compile -vv for more ``` Valid projects are listed on help. diff --git a/tools/build_release.bat b/tools/build_release.bat index 644c202fa..0e2a52fe8 100644 --- a/tools/build_release.bat +++ b/tools/build_release.bat @@ -74,7 +74,7 @@ if not [%requirements_file%]==[] pip install -r %requirements_file% @REM mbed deploy @REM mbed update mbed config root . - mbed config ARM_PATH=!ARM_PATH! + mbed config ARM_PATH !ARM_PATH! python tools/mbedcli_compile.py --clean --release @if !errorlevel! neq 0 exit /B !errorlevel! python tools/copy_release_files.py --project-tool mbedcli diff --git a/tools/mbedcli_compile.py b/tools/mbedcli_compile.py index 9ca688eba..8d2e1d2f7 100644 --- a/tools/mbedcli_compile.py +++ b/tools/mbedcli_compile.py @@ -19,44 +19,16 @@ import argparse import os import shutil -import sys import yaml - -from subprocess import check_output, CalledProcessError +import mbedcli_tools from pre_build_script import generate_version_file -from generate_mbedcli_files import generate_mbedcli_files -from post_compute_crc import post_compute_crc from package_release_files import package_release_files PROJECTS_YAML = "projects.yaml" VERSION_YAML = "version.yaml" -def mbedcli_compile(daplink_dir, build_folder, project, toolchain, clean): - generate_mbedcli_files(os.path.join(daplink_dir, "projects.yaml"), project) - project_dir=os.path.join(daplink_dir, build_folder, project.upper()) - if clean is True and os.path.exists(project_dir): - print("Deleting %s" % project_dir) - shutil.rmtree(project_dir, ignore_errors=True) - try: - check_output("mbed compile -m %s -t %s --profile custom_profile.json" % (project, toolchain), shell=True) - cli_name_out = os.path.basename(daplink_dir) - build_dir = os.path.join(project_dir, toolchain+"-CUSTOM_PROFILE") - for file in os.listdir(build_dir): - if file.startswith(cli_name_out): - rename_file = os.path.join(build_dir, file.replace(cli_name_out, project, 1)) - if os.path.exists(rename_file): - os.remove(rename_file) - os.rename(os.path.join(build_dir, file), rename_file) - cli_hex_output = os.path.join(build_dir, project + ".hex") - crc_file_output = os.path.join(build_dir, project + "_crc") - post_compute_crc(cli_hex_output, crc_file_output) - except CalledProcessError: - print("Error - mbed compile error") - exit(1) - def main(): """python -u tools/mbedcli_compile.py kl26z_microbit_if kl26z_bl --clean""" - #parse project yaml file for project list project_list = [] with open(PROJECTS_YAML, 'r') as top_yaml: @@ -69,7 +41,6 @@ def main(): break except yaml.YAMLError as ex: print("Found yaml parse error", ex) - #parse the arguments projects = "List of supported projects\n\n" + ", ".join(project_list) # parser = argparse.ArgumentParser(description='mbedcli compile support for DAPLink', epilog=projects, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -80,11 +51,10 @@ def main(): parser.add_argument('--release-folder', type=str, default='firmware', help='Directory to create and place files in') parser.add_argument('--toolchain', type=str, default='ARM', help='Toolchain directory if present') parser.add_argument('--clean', dest='clean', action='store_true', help='Rebuild or delete build folder before compile') + parser.add_argument('-v', dest='verbosity', action='count', help='Pass verbosity level to mbed compile -vv for more') parser.set_defaults(clean=False) parser.set_defaults(release=False) args = parser.parse_args() - - self_path = os.path.abspath(__file__) tools_dir = os.path.dirname(self_path) daplink_dir = os.path.dirname(tools_dir) @@ -94,17 +64,14 @@ def main(): version_git_dir = os.path.join(daplink_dir, "source", "daplink") generate_version_file(version_git_dir) if not args.projects == []: - for project in args.projects: print("Compiling %s" % project) - mbedcli_compile(daplink_dir, args.build_folder, project, args.toolchain, args.clean) + mbedcli_tools.mbedcli_run(daplink_dir, args.build_folder, project, args.toolchain, args.clean, args.verbosity) else: print("compiling all firmware") - for project in project_list: print("Compiling %s" % project) - mbedcli_compile(daplink_dir, args.build_folder, project, args.toolchain, args.clean) - + mbedcli_tools.mbedcli_run(daplink_dir, args.build_folder, project, args.toolchain, args.clean, args.verbosity) if args.release is True: release_version = 0 with open(os.path.join("records","tools", VERSION_YAML), 'r') as ver_yaml: diff --git a/tools/mbedcli_tools/__init__.py b/tools/mbedcli_tools/__init__.py new file mode 100644 index 000000000..c17574d01 --- /dev/null +++ b/tools/mbedcli_tools/__init__.py @@ -0,0 +1,19 @@ +# +# DAPLink Interface Firmware +# Copyright (c) 2009-2018, ARM Limited, All Rights Reserved +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from mbedcli_run import mbedcli_run diff --git a/tools/generate_custom_cli_files.py b/tools/mbedcli_tools/generate_custom_cli_files.py similarity index 99% rename from tools/generate_custom_cli_files.py rename to tools/mbedcli_tools/generate_custom_cli_files.py index f3c623ff4..20bc8b871 100644 --- a/tools/generate_custom_cli_files.py +++ b/tools/mbedcli_tools/generate_custom_cli_files.py @@ -18,9 +18,7 @@ import json - def generate_custom_profile(build_dicts, compiler='ARM', tool_search='make_armcc', filename = 'custom_profile.json'): - profile_dict = { compiler: { "common": [], @@ -30,7 +28,6 @@ def generate_custom_profile(build_dicts, compiler='ARM', tool_search='make_armcc "ld": [] } } - if 'tool_specific' in build_dicts: for entry in build_dicts['tool_specific']: if entry == tool_search: @@ -46,9 +43,7 @@ def generate_custom_profile(build_dicts, compiler='ARM', tool_search='make_armcc with open(filename, 'w') as custom_profile: json.dump(profile_dict, custom_profile, indent=4, separators=(',', ': ')) - def generate_custom_targets(target_name, build_dicts, out_ext='hex', filename = 'custom_targets.json'): - target_dict = { target_name : { "core": build_dicts['common']['core'][0], @@ -58,7 +53,6 @@ def generate_custom_targets(target_name, build_dicts, out_ext='hex', filename = "macros" : [] } } - if 'common' in build_dicts: for entry in build_dicts['common']: if entry == 'macros': diff --git a/tools/generate_mbedcli_files.py b/tools/mbedcli_tools/generate_mbedcli_files.py similarity index 99% rename from tools/generate_mbedcli_files.py rename to tools/mbedcli_tools/generate_mbedcli_files.py index dbea8bce4..11e9b7c53 100644 --- a/tools/generate_mbedcli_files.py +++ b/tools/mbedcli_tools/generate_mbedcli_files.py @@ -20,7 +20,6 @@ import yaml import sys import logging - from generate_custom_cli_files import generate_custom_targets from generate_custom_cli_files import generate_custom_profile from generate_mbedignore import generate_mbedignore diff --git a/tools/generate_mbedignore.py b/tools/mbedcli_tools/generate_mbedignore.py similarity index 99% rename from tools/generate_mbedignore.py rename to tools/mbedcli_tools/generate_mbedignore.py index 186ae279c..0ed99856a 100644 --- a/tools/generate_mbedignore.py +++ b/tools/mbedcli_tools/generate_mbedignore.py @@ -18,7 +18,6 @@ import os - def add_list_path(input_path_list, ouput_path_dict): for path_list in input_path_list: repath = os.path.normpath(path_list) @@ -49,7 +48,6 @@ def generate_mbedignore(build_dicts, topsource = 'source', filename = '.mbedigno for file in os.listdir("./"): if file != topsource: ignore_list.append(file) - for root, dirs, files in os.walk(topsource): if root in src_folder_file_dict: if src_folder_file_dict[root] != []: diff --git a/tools/mbedcli_tools/mbedcli_run.py b/tools/mbedcli_tools/mbedcli_run.py new file mode 100644 index 000000000..7a67de8b9 --- /dev/null +++ b/tools/mbedcli_tools/mbedcli_run.py @@ -0,0 +1,58 @@ +# +# DAPLink Interface Firmware +# Copyright (c) 2009-2018, ARM Limited, All Rights Reserved +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import shutil +import subprocess +from generate_mbedcli_files import generate_mbedcli_files +from post_compute_crc import post_compute_crc + +def call_and_copy_output(args): + try: + process = subprocess.Popen(args, stdout=None, stderr=subprocess.STDOUT) + process.wait() + if process.returncode != 0: + print("Error - mbed compile!") + exit(process.returncode) + except (OSError, ValueError) as e: + print("Error - Cannot do mbed compile") + print(e.output) + exit(1) + +def mbedcli_run(daplink_dir, build_folder, project, toolchain, clean, verbosity): + generate_mbedcli_files(os.path.join(daplink_dir, "projects.yaml"), project) + project_dir=os.path.join(daplink_dir, build_folder, project.upper()) + if clean is True and os.path.exists(project_dir): + print("Deleting %s" % project_dir) + shutil.rmtree(project_dir, ignore_errors=True) + args = ["mbed", "compile", "-m", project, "-t", toolchain, "--profile", "custom_profile.json"] + if verbosity is not None: + args.append("-" + "v" * verbosity) + call_and_copy_output(args) + cli_name_out = os.path.basename(daplink_dir) + build_dir = os.path.join(project_dir, toolchain+"-CUSTOM_PROFILE") + for file in os.listdir(build_dir): + if file.startswith(cli_name_out): + rename_file = os.path.join(build_dir, file.replace(cli_name_out, project, 1)) + if os.path.exists(rename_file): + os.remove(rename_file) + os.rename(os.path.join(build_dir, file), rename_file) + cli_hex_output = os.path.join(build_dir, project + ".hex") + crc_file_output = os.path.join(build_dir, project + "_crc") + print("Creating crc padded binaries %s" % os.path.basename(crc_file_output)) + post_compute_crc(cli_hex_output, crc_file_output)