|
| 1 | +# Copyright (c) 2021 Project CHIP Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import logging |
| 16 | +import os |
| 17 | +from enum import Enum, auto |
| 18 | + |
| 19 | +from .builder import Builder, BuilderOutput |
| 20 | + |
| 21 | + |
| 22 | +class RealtekBoard(Enum): |
| 23 | + RTL8777G = auto() |
| 24 | + |
| 25 | + @property |
| 26 | + def BoardName(self): |
| 27 | + return 'rtl8777g' |
| 28 | + |
| 29 | + |
| 30 | +class RealtekApp(Enum): |
| 31 | + LIGHT = auto() |
| 32 | + LIGHT_SWITCH = auto() |
| 33 | + LOCK = auto() |
| 34 | + WINDOW = auto() |
| 35 | + |
| 36 | + @property |
| 37 | + def ExampleName(self): |
| 38 | + if self == RealtekApp.LIGHT: |
| 39 | + return 'lighting-app' |
| 40 | + elif self == RealtekApp.LIGHT_SWITCH: |
| 41 | + return 'light-switch-app' |
| 42 | + elif self == RealtekApp.LOCK: |
| 43 | + return 'lock-app' |
| 44 | + elif self == RealtekApp.WINDOW: |
| 45 | + return 'window-app' |
| 46 | + else: |
| 47 | + raise Exception('Unknown app type: %r' % self) |
| 48 | + |
| 49 | + @property |
| 50 | + def TargetName(self): |
| 51 | + if self == RealtekApp.LIGHT: |
| 52 | + return 'matter-cli-ftd' |
| 53 | + elif self == RealtekApp.LIGHT_SWITCH: |
| 54 | + return 'matter-cli-mtd' |
| 55 | + elif self == RealtekApp.LOCK: |
| 56 | + return 'matter-cli-ftd' |
| 57 | + elif self == RealtekApp.WINDOW: |
| 58 | + return 'matter-cli-mtd' |
| 59 | + else: |
| 60 | + raise Exception('Unknown app type: %r' % self) |
| 61 | + |
| 62 | + @property |
| 63 | + def AppNamePrefix(self): |
| 64 | + if self == RealtekApp.LIGHT: |
| 65 | + return 'chip-rtl8777g-lighting-app' |
| 66 | + elif self == RealtekApp.LIGHT_SWITCH: |
| 67 | + return 'chip-rtl8777g-light-switch-app' |
| 68 | + elif self == RealtekApp.LOCK: |
| 69 | + return 'chip-rtl8777g-lock-app' |
| 70 | + elif self == RealtekApp.WINDOW: |
| 71 | + return 'chip-rtl8777g-window-app' |
| 72 | + else: |
| 73 | + raise Exception('Unknown app type: %r' % self) |
| 74 | + |
| 75 | + |
| 76 | +class RealtekBuilder(Builder): |
| 77 | + |
| 78 | + def __init__(self, |
| 79 | + root, |
| 80 | + runner, |
| 81 | + board: RealtekBoard = RealtekBoard.RTL8777G, |
| 82 | + app: RealtekApp = RealtekApp.LIGHT): |
| 83 | + super(RealtekBuilder, self).__init__(root, runner) |
| 84 | + self.board = board |
| 85 | + self.app = app |
| 86 | + |
| 87 | + def generate(self): |
| 88 | + logging.info('generate %s', self.output_dir) |
| 89 | + |
| 90 | + def _build(self): |
| 91 | + cmd = 'third_party/openthread/ot-realtek/Realtek/build.sh {out_folder} {board} {app} {target} '.format( |
| 92 | + out_folder=self.output_dir.strip(), |
| 93 | + board=self.board.BoardName, |
| 94 | + app=self.app.ExampleName, |
| 95 | + target=self.app.TargetName |
| 96 | + ) |
| 97 | + |
| 98 | + # <build root> <build_system> <output_directory> <application> |
| 99 | + cmd += ' '.join([self.root, 'ninja', self.output_dir, |
| 100 | + self.app.ExampleName]) |
| 101 | + |
| 102 | + self._Execute(['bash', '-c', cmd], |
| 103 | + title='Generating ' + self.identifier) |
| 104 | + |
| 105 | + def build_outputs(self): |
| 106 | + logging.info('build_outputs %s', self.output_dir) |
0 commit comments