diff --git a/src/oebuild/app/build.py b/src/oebuild/app/build.py new file mode 100644 index 0000000000000000000000000000000000000000..29ccdcae94167cec152f392a99a1e25a7e1d6b3f --- /dev/null +++ b/src/oebuild/app/build.py @@ -0,0 +1,131 @@ +''' +Copyright (c) 2023 openEuler Embedded +oebuild is licensed under Mulan PSL v2. +You can use this software according to the terms and conditions of the Mulan PSL v2. +You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PSL v2 for more details. +''' + +import os + +import oebuild.util as oebuild_util +from oebuild.m_log import logger +from oebuild.app.main import OebuildApp + + +class QuickBuild(): + ''' + The build command will quickly generate the compile.yaml + ''' + + def __init__(self, ): + self.app = OebuildApp() + + def check_yaml(self, yaml_path): + path = os.path.join(os.getcwd(), yaml_path) + + if os.path.exists(path): + return True + + logger.error("the %s directory is not exists", path) + return False + + def run(self, yaml_path): + ''' + Execute oebuild commands in order. + ''' + if not self.check_yaml(yaml_path): + return + + self.load_command_date(yaml_path) + + if self.do_init() != 0: + return + + if self.do_update() != 0: + return + + if self.do_generate() != 0: + return + + def load_command_date(self, yaml_path): + ''' + Load command data by yaml. + ''' + path = os.path.join(os.getcwd(), yaml_path) + try: + data = oebuild_util.read_yaml(yaml_dir=path)["yocto"] + self.init_cmd = None if 'init' not in data else data["init"] + self.update_cmd = None if 'update' not in data else data["update"] + self.generate_cmd = None if 'generate' not in data else data["generate"] + + except Exception as e_p: + raise e_p + + def do_init(self, ): + ''' + Execute oebuild command : oebuild init [directory] [-u yocto_remote_url] [-b branch] + ''' + directory = None if 'directory' not in self.init_cmd else self.init_cmd["directory"] + url = None if 'url' not in self.init_cmd else self.init_cmd["url"] + branch = None if 'branch' not in self.init_cmd else self.init_cmd["branch"] + + argv = [ + 'init', + ] + if directory: + argv.append(directory) + + if url: + argv.append('-u') + argv.append(url) + + if branch: + argv.append('-b') + argv.append(branch) + + self.app.run_command(argv=argv) + + def do_update(self, ): + ''' + Execute oebuild command : oebuild update [yocto docker layer] [-tag] + ''' + layer = None if 'layer' not in self.update_cmd else self.update_cmd["layer"] + tag = None if 'tag' not in self.update_cmd else self.update_cmd["tag"] + + argv = [ + 'update', + ] + + if layer and layer in ['yocto', 'docker', 'layer']: + argv.append(layer) + + if tag: + argv.append('-tag') + argv.append(tag) + + self.app.run_command(argv=argv) + + def do_generate(self, ): + ''' + Execute oebuild command : oebuild generate + ''' + platform = None if 'platform' not in self.generate_cmd else self.generate_cmd["platform"] + features = None if 'features' not in self.generate_cmd else self.generate_cmd["features"] + + argv = [ + 'generate', + ] + if platform: + argv.append('-p') + argv.append(platform) + + if features: + argv.append('-f') + argv.append(features) + + self.app.run_command(argv=argv) diff --git a/src/oebuild/app/conf/build.yaml.sample b/src/oebuild/app/conf/build.yaml.sample new file mode 100644 index 0000000000000000000000000000000000000000..25d9afe101f42d1a25d8d2bc8b84dbdcc0478e57 --- /dev/null +++ b/src/oebuild/app/conf/build.yaml.sample @@ -0,0 +1,13 @@ +yocto: + init: + directory: abc + url: None + branch: master + + update: + layer: None + tag: None + + generate: + platform: None + features: None diff --git a/src/oebuild/app/main.py b/src/oebuild/app/main.py index ac10b47da124357e7c9645f42df33cccdabd9bfd..58fbed03133e9cf9534ccea8f98812014c6f59c1 100644 --- a/src/oebuild/app/main.py +++ b/src/oebuild/app/main.py @@ -14,9 +14,10 @@ import sys import pathlib from collections import OrderedDict import getpass - import colorama +from build import QuickBuild + import oebuild.util as oebuild_util from oebuild.auto_completion import AutoCompletion from oebuild.version import __version__ @@ -197,8 +198,12 @@ def main(argv=None): colorama.init() AutoCompletion().run() - app = OebuildApp() - app.run(argv or sys.argv[1:]) + if (len(sys.argv) > 1) and 'yaml' in sys.argv[1]: + build = QuickBuild(sys.argv[1]) + build.run() + else: + app = OebuildApp() + app.run(argv or sys.argv[1:]) if __name__ == "__main__":