Skip to content

Commit

Permalink
[Mbed] Mbed platform examples Python builder (#11197)
Browse files Browse the repository at this point in the history
* Add Mbed python builder
Add Mbed targets to python builder

* Improve mbed_example.sh script - Python builder compatibility
Improve examples cmake file and gitignore

* Improve build and outputs definition in Python builder

* Update all_targets_except_host.txt

* Update testdata
Fix mbed builder for testing

* Fix mbed unit test build script

* Fix mbed builder for Darwin platform

* Add mbed-release targets to exampleTarget input - task.json

* Changes restyle

* Add all Mbed supported targets and sorted - tasks.json

* Improve mbed builder - more dry-run commands
Add develop and debug profiles to glob-blacklist

* Changes restyle
  • Loading branch information
ATmobica authored and pull[bot] committed Sep 5, 2023
1 parent 7ca13dd commit 3840623
Show file tree
Hide file tree
Showing 20 changed files with 410 additions and 40 deletions.
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@
"linux-x64-chip-tool-ipv6only",
"linux-x64-thermostat",
"linux-x64-thermostat-ipv6only",
"mbed-CY8CPROTO_062_4343W-all-clusters-debug",
"mbed-CY8CPROTO_062_4343W-all-clusters-develop",
"mbed-CY8CPROTO_062_4343W-all-clusters-release",
"mbed-CY8CPROTO_062_4343W-light-debug",
"mbed-CY8CPROTO_062_4343W-light-develop",
"mbed-CY8CPROTO_062_4343W-light-release",
"mbed-CY8CPROTO_062_4343W-lock-debug",
"mbed-CY8CPROTO_062_4343W-lock-develop",
"mbed-CY8CPROTO_062_4343W-lock-release",
"mbed-CY8CPROTO_062_4343W-pigweed-debug",
"mbed-CY8CPROTO_062_4343W-pigweed-develop",
"mbed-CY8CPROTO_062_4343W-pigweed-release",
"mbed-CY8CPROTO_062_4343W-shell-debug",
"mbed-CY8CPROTO_062_4343W-shell-develop",
"mbed-CY8CPROTO_062_4343W-shell-release",
"nrf-nrf52840-light",
"nrf-nrf52840-lock",
"nrf-nrf52840-pump",
Expand Down
1 change: 0 additions & 1 deletion examples/all-clusters-app/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config/
build-*/
4 changes: 2 additions & 2 deletions examples/all-clusters-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ configure_file(
@ONLY
)

set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-all-clusters-app-example)

Expand All @@ -25,7 +25,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

add_executable(${APP_TARGET})

Expand Down
1 change: 0 additions & 1 deletion examples/lighting-app/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config/
build-*/
4 changes: 2 additions & 2 deletions examples/lighting-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ configure_file(
@ONLY
)

set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-lighting-app-example)

Expand All @@ -23,7 +23,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

add_executable(${APP_TARGET})

Expand Down
1 change: 0 additions & 1 deletion examples/lock-app/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config/
build-*/
4 changes: 2 additions & 2 deletions examples/lock-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ configure_file(
@ONLY
)

set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-lock-app-example)

Expand All @@ -23,7 +23,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

add_executable(${APP_TARGET})

Expand Down
1 change: 0 additions & 1 deletion examples/pigweed-app/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config/
build-*/
4 changes: 2 additions & 2 deletions examples/pigweed-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configure_file(
@ONLY
)

set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-pigweed-app-example)

Expand All @@ -22,7 +22,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

add_executable(${APP_TARGET})

Expand Down
1 change: 0 additions & 1 deletion examples/shell/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
config/
build-*/
4 changes: 2 additions & 2 deletions examples/shell/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configure_file(
@ONLY
)

set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_PATH ${MBED_OS_PATH} CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET chip-mbed-shell-example)

Expand All @@ -22,7 +22,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})

add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

add_executable(${APP_TARGET})

Expand Down
25 changes: 25 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from builders.telink import TelinkApp, TelinkBoard, TelinkBuilder
from builders.tizen import TizenApp, TizenBoard, TizenBuilder
from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder
from builders.mbed import MbedApp, MbedBoard, MbedProfile, MbedBuilder


class Target:
Expand Down Expand Up @@ -191,6 +192,29 @@ def AndroidTargets():
yield target.Extend('androidstudio-x64-chip-tool', board=AndroidBoard.AndroidStudio_X64, app=AndroidApp.CHIP_TOOL)


def MbedTargets():
target = Target('mbed', MbedBuilder)

targets = [
target.Extend('CY8CPROTO_062_4343W',
board=MbedBoard.CY8CPROTO_062_4343W),
]

app_targets = []
for target in targets:
app_targets.append(target.Extend('lock', app=MbedApp.LOCK))
app_targets.append(target.Extend('light', app=MbedApp.LIGHT))
app_targets.append(target.Extend(
'all-clusters', app=MbedApp.ALL_CLUSTERS))
app_targets.append(target.Extend('pigweed', app=MbedApp.PIGWEED))
app_targets.append(target.Extend('shell', app=MbedApp.SHELL))

for target in app_targets:
yield target.Extend('release', profile=MbedProfile.RELEASE)
yield target.Extend('develop', profile=MbedProfile.DEVELOP).GlobBlacklist('Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')
yield target.Extend('debug', profile=MbedProfile.DEBUG).GlobBlacklist('Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')


ALL = []

target_generators = [
Expand All @@ -199,6 +223,7 @@ def AndroidTargets():
Efr32Targets(),
NrfTargets(),
AndroidTargets(),
MbedTargets()
]

for generator in target_generators:
Expand Down
150 changes: 150 additions & 0 deletions scripts/build/builders/mbed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Copyright (c) 2021 Project CHIP Authors
#
# 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 logging
import os
import platform
import glob
import shlex
import pathlib

from enum import Enum, auto
from .builder import Builder


class MbedApp(Enum):
LOCK = auto()
LIGHT = auto()
ALL_CLUSTERS = auto()
PIGWEED = auto()
SHELL = auto()

@property
def ExampleName(self):
if self == MbedApp.LOCK:
return 'lock-app'
elif self == MbedApp.LIGHT:
return 'lighting-app'
elif self == MbedApp.ALL_CLUSTERS:
return 'all-clusters-app'
elif self == MbedApp.PIGWEED:
return 'pigweed-app'
elif self == MbedApp.SHELL:
return 'shell'
else:
raise Exception('Unknown app type: %r' % self)

@property
def AppNamePrefix(self):
if self == MbedApp.LOCK:
return 'chip-mbed-lock-app-example'
elif self == MbedApp.LIGHT:
return 'chip-mbed-lighting-app-example'
elif self == MbedApp.ALL_CLUSTERS:
return 'chip-mbed-all-clusters-app-example'
elif self == MbedApp.PIGWEED:
return 'chip-mbed-pigweed-app-example'
elif self == MbedApp.SHELL:
return 'shell'
else:
raise Exception('Unknown app type: %r' % self)


class MbedBoard(Enum):
CY8CPROTO_062_4343W = auto()

@property
def BoardName(self):
if self == MbedBoard.CY8CPROTO_062_4343W:
return 'CY8CPROTO_062_4343W'
else:
raise Exception('Unknown board type: %r' % self)


class MbedProfile(Enum):
RELEASE = auto()
DEVELOP = auto()
DEBUG = auto()

@property
def ProfileName(self):
if self == MbedProfile.RELEASE:
return 'release'
elif self == MbedProfile.DEVELOP:
return 'develop'
elif self == MbedProfile.DEBUG:
return 'debug'
else:
raise Exception('Unknown board type: %r' % self)


class MbedBuilder(Builder):
def __init__(self,
root,
runner,
app: MbedApp = MbedApp.LOCK,
board: MbedBoard = MbedBoard.CY8CPROTO_062_4343W,
profile: MbedProfile = MbedProfile.RELEASE):
super(MbedBuilder, self).__init__(root, runner)
self.app = app
self.board = board
self.profile = profile
self.toolchain = "GCC_ARM"
self.mbed_os_path = os.path.join(
self.root, 'third_party', 'mbed-os', 'repo')
self.mbed_os_posix_socket_path = os.path.join(
self.root, 'third_party', 'mbed-os-posix-socket', 'repo')

@property
def ExamplePath(self):
return os.path.join(self.root, 'examples', self.app.ExampleName, 'mbed')

def generate(self):
if not os.path.exists(self.output_dir):
self._Execute(['mbed-tools', 'configure',
'-t', self.toolchain,
'-m', self.board.BoardName,
'-p', self.ExamplePath,
'-o', self.output_dir,
'--mbed-os-path', self.mbed_os_path,
], title='Generating config ' + self.identifier)

self._Execute(['cmake', '-S', shlex.quote(self.ExamplePath), '-B', shlex.quote(self.output_dir), '-GNinja',
'-DCMAKE_BUILD_TYPE={}'.format(
self.profile.ProfileName.lower()),
'-DMBED_OS_PATH={}'.format(
shlex.quote(self.mbed_os_path)),
'-DMBED_OS_POSIX_SOCKET_PATH={}'.format(
shlex.quote(self.mbed_os_posix_socket_path)),
], title='Generating ' + self.identifier)

def _build(self):
# Remove old artifacts to force linking
cmd = 'rm -rf {}/chip-*'.format(self.output_dir)
self._Execute(['bash', '-c', cmd],
title='Remove old artifacts ' + self.identifier)

self._Execute(['cmake', '--build', shlex.quote(self.output_dir)],
title='Building ' + self.identifier)

def build_outputs(self):
return {
self.app.AppNamePrefix + '.elf':
os.path.join(self.output_dir, self.app.AppNamePrefix + '.elf'),
self.app.AppNamePrefix + '.hex':
os.path.join(self.output_dir, self.app.AppNamePrefix + '.hex'),
self.app.AppNamePrefix + '.map':
os.path.join(self.output_dir,
self.app.AppNamePrefix + '.elf.map'),
}
15 changes: 15 additions & 0 deletions scripts/build/testdata/all_targets_except_host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ esp32-m5stack-all-clusters-ipv6only
esp32-m5stack-all-clusters-rpc
esp32-m5stack-all-clusters-rpc-ipv6only
infineon-p6-lock
mbed-CY8CPROTO_062_4343W-all-clusters-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-all-clusters-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-all-clusters-release
mbed-CY8CPROTO_062_4343W-light-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-light-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-light-release
mbed-CY8CPROTO_062_4343W-lock-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-lock-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-lock-release
mbed-CY8CPROTO_062_4343W-pigweed-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-pigweed-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-pigweed-release
mbed-CY8CPROTO_062_4343W-shell-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-shell-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-shell-release
nrf-nrf52840-light
nrf-nrf52840-light-rpc
nrf-nrf52840-lock
Expand Down
Loading

0 comments on commit 3840623

Please sign in to comment.