Skip to content

Commit

Permalink
Merge pull request #519 from brianesquilona/dev_features_mbedcli
Browse files Browse the repository at this point in the history
Added verbosity on mbed compile support
  • Loading branch information
brianesquilona authored Nov 2, 2018
2 parents 68ea287 + d16b1f3 commit f2366cc
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 49 deletions.
10 changes: 8 additions & 2 deletions docs/DEVELOPERS-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion tools/build_release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 4 additions & 37 deletions tools/mbedcli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions tools/mbedcli_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand All @@ -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:
Expand All @@ -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],
Expand All @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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] != []:
Expand Down
58 changes: 58 additions & 0 deletions tools/mbedcli_tools/mbedcli_run.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f2366cc

Please sign in to comment.