From f4653a03be02ac092d4a1142b4df7851d7689037 Mon Sep 17 00:00:00 2001 From: alichinese Date: Mon, 19 Jun 2023 11:24:10 +0800 Subject: [PATCH 1/2] generate: add a new instruction * generating compile files requires a lot of external directives, which are numerous and difficult to remember, and for users, they can directly customize the build configuration file intuitively, and then specify the build configuration file directly at build time Signed-off-by: lixinyu --- src/oebuild/app/conf/compile.yaml.sample | 155 +++++++++++++++++++ src/oebuild/app/plugins/generate/generate.py | 49 +++++- src/oebuild/app/plugins/init/init.py | 16 +- src/oebuild/configure.py | 1 + src/oebuild/util.py | 7 + 5 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 src/oebuild/app/conf/compile.yaml.sample diff --git a/src/oebuild/app/conf/compile.yaml.sample b/src/oebuild/app/conf/compile.yaml.sample new file mode 100644 index 0000000..36f7644 --- /dev/null +++ b/src/oebuild/app/conf/compile.yaml.sample @@ -0,0 +1,155 @@ +# compile.yaml is the build configuration file of the build tool oebuild under +# openEuler Embedded, which will parse the file when executing the oebuild bitbake, +# and by parsing the file, the built image will be set in various ways, and the +# most critical is still the modification of local.conf and bblayers.conf. Not all +# parameters need to be set here, mainly around whether the build environment is in +# the container, that is, some parameters are valid in the container and some are +# valid in the host environment. The build configuration file is a demo file, you can +# remove the file name suffix .sample, and then customize or configure it according to +# your needs, and then execute `oebuild bitbake -f [target]` to build +# according to the specified build configuration file + + +# build_in can specify the environment used to build, +# and currently we have two environments, one is built in a +# container and the other is built on the host. The list of +# parameters for both environments is as follows: +# 1, docker +# 2, host +# but, default param is docker +build_in: docker + + +# docker_image specifies the container image when building in the container +# +docker_image: swr.cn-north-4.myhuaweicloud.com/openeuler-embedded/openeuler-container:latest + + +# platform specifies the board at build time, if it is not +# clear what the value of the board is, it can be determined by +# executing `oebuild generate -l platform`, this command will list +# all supported boards for openEuler Embedded +# +platform: aarch64-std + + +# mechine replaces the mechine parameter in local.conf, +# in general, platform lists a list in the +# `yocto-meta-openeuler/.oebuild/platform` directory, and the +# mechine value is specified in the specific platform +# +mechine: qemu-aarch64 + + +# toolchain_type specifies the identity of the external toolchain, +# if the build environment is in a container, you need to locate +# the cross-compilation chain address through this identity, and +# the list of cross-compilation chain address mappings in the +# container is as follows: +# 1,EXTERNAL_TOOLCHAIN_arm = "/usr1/openeuler/gcc/openeuler_gcc_arm32le" +# 2,EXTERNAL_TOOLCHAIN_aarch64 = "/usr1/openeuler/gcc/openeuler_gcc_arm64le" +# 3,EXTERNAL_TOOLCHAIN_x86-64 = "/usr1/openeuler/gcc/openeuler_gcc_x86_64" +# 4,EXTERNAL_TOOLCHAIN_riscv64 = "/usr1/openeuler/gcc/openeuler_gcc_riscv64" +# +toolchain_type: EXTERNAL_TOOLCHAIN_aarch64 + +# toolchain_dir specify the cross-compilation chain directory +# used at build time, if the build environment is in a container, +# that is, build_in parameter is docker, this parameter does not +# need to be specified, because the cross-compilation chain is +# already built in the container, if the build environment is in +# the host, that is, the build_in parameter is host, this parameter +# needs to be specified. There are currently 4 cross-compilation chains, +# and the list of paths in the container build environment is as follows: +# 1, /usr1/openeuler/gcc/openeuler_gcc_arm64le +# 2, /usr1/openeuler/gcc/openeuler_gcc_arm32le +# 3, /usr1/openeuler/gcc/openeuler_gcc_x86_64 +# 4, /usr1/openeuler/gcc/openeuler_gcc_riscv64 +# +# toolchain_dir: /usr1/openeuler/gcc/openeuler_gcc_arm64le + + +# nativesdk_dir represents the compiled SDK directory, nativesdk hosts +# some external tools and dynamic link libraries needed at build time, +# etc., these things will not be packaged into the image, the same as +# the toolchain_dir parameters, if the build environment is in the +# container, do not need to be specified, the container has been built-in, +# if the build environment is in the host, you need to specify the directory. +# +# nativesdk_dir: /opt/buildtools/nativesdk + + +# not_use_repos specifies whether to update the layer layer when starting +# the build environment, it needs to be updated by default, if you debug or +# modify the layer layer, you can set this parameter to true. +# +# not_use_repos: false + + +# sstate_cache specifies whether the sstate-cache mechanism is used when +# yocto is built, and if so, the SSTATE_MIRRORS value in local.conf will be +# modified, and there are two SSTATE_MIRRORS values, one is a remote link, +# and the other is a local directory, both pointing to the directory of specific +# sstate-cache. There are two types of values for SSTATE_MIRRORS: +# 1,file://.* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH +# 2,file://.* file:///some/local/dir/sstate/PATH +# If you set this parameter to http://xxxx/share, eventually in local.conf, +# the SSTATE_MIRRORS will be set to +# file://.* http://xxxx/share/PATH;downloadfilename=PATH, and if the cost path +# is set, the SSTATE_MIRRORS will be set to file:// .* file://xxx/PATH. +# Another thing to note is that if the build environment is in a container, +# specifying the sstate-cache path will be mounted to the +# /usr1/openeuler/sstate-cache directory in the container when the container +# is created, so the value of the SSTATE_MIRRORS in local.conf will become +# file://.* file:///usr1/openeuler/sstate-cache/PATH +# +# sstate_cache: xxx + + +# sstate_dir specifies the path where yocto stores sstate at build time, +# this variable corresponds to the SSTATE_DIR in local.conf, and this variable +# is only useful if the build environment is the host environment +# +# sstate_dir: xxx + + +# tmp_dir specifies the path to the tmp directory in Yocto, which is used +# to store Yocto's build output, corresponding to the TMP_DIR parameter in +# local.conf. Also, this parameter is only valid if the build environment +# is a host environment +# +# tmp_dir: xxx + +# repos is used to set the code repository required to initialize the build +# environment when openEuler Embedded is built, usually the following parameter +# should list the information of the layers layer required by bitbake during +# initialization, which can be set according to your own needs. The following +# values of this parameter have format requirements, which are illustrated here: +# repos: +# abc: +# url: xxxxxxxxxxx +# path: xxxxxxxxxx +# refspec: xxxxxxxxxxxx +# the key abc represents a repository, url is remote url, path is local path, it means +# when download repository,it will be stored in local, in general, the key abc is same +# to path, refspec is point branch or tag +# +# repos: +# abc: +# url: xxxx +# path: xxxx +# refspec: xxx + +# local_conf is to supplement the setting of various parameters in local.conf, and all +# values filled in under this variable will be appended to local.conf unchanged +# +# local_conf: +# xxx + +# The layers parameter specifies the layer of bitbake at initialization, the value of +# this parameter is a relative value, that is, the path under the src directory, for example, +# set a layer of layers to yocto-meta-openembedded/meta-python, it will eventually be replaced +# with /src/yocto-meta-openembedded/meta-python in layers +# +# layers: +# xxxx \ No newline at end of file diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 471db03..62bcf8c 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -15,9 +15,11 @@ import textwrap import os import sys import pathlib +from shutil import copyfile from oebuild.command import OebuildCommand import oebuild.util as oebuild_util +from oebuild.parse_compile import ParseCompile,CheckCompileError from oebuild.configure import Configure from oebuild.parse_template import BaseParseTemplate, ParseTemplate, BUILD_IN_DOCKER, BUILD_IN_HOST from oebuild.m_log import logger, INFO_COLOR @@ -85,6 +87,12 @@ class Generate(OebuildCommand): ''' ) + parser.add_argument('-c', '--compile_dir', dest='compile_dir', + help=''' + this param is for compile.yaml directory + ''' + ) + parser.add_argument('-d', dest='directory', help=''' this param is build directory, the default is same to platform @@ -137,6 +145,31 @@ class Generate(OebuildCommand): logger.error('your current directory had not finishd init') sys.exit(-1) + yocto_dir = self.configure.source_yocto_dir() + if not self.check_support_oebuild(yocto_dir): + logger.error('Currently, yocto-meta-openeuler does not support oebuild, \ + please modify .oebuild/config and re-execute `oebuild update`') + return + + if args.compile_dir is not None: + try: + platform = self._check_compile(args.compile_dir) + args.platform = platform + build_dir = self._init_build_dir(args=args) + if build_dir is None: + logger.error("build directory can not mkdir") + return + # copy compile.yaml to build directory + copyfile(args.compile_dir, os.path.join(build_dir, "compile.yaml")) + self._print_generate(build_dir=build_dir) + except CheckCompileError as c_e: + logger.error(str(c_e)) + except ValueError as v_e: + logger.error(str(v_e)) + except IOError as e: + logger.error(str(e)) + return + build_in = BUILD_IN_DOCKER if args.build_in == BUILD_IN_HOST: try: @@ -156,12 +189,6 @@ class Generate(OebuildCommand): if args.tmp_dir is not None: self.tmp_dir = args.tmp_dir - yocto_dir = self.configure.source_yocto_dir() - if not self.check_support_oebuild(yocto_dir): - logger.error('Currently, yocto-meta-openeuler does not support oebuild, \ - please modify .oebuild/config and re-execute `oebuild update`') - return - if args.list is not None: self.list_info(args=args) return @@ -239,6 +266,9 @@ following container, enter it numerically, and enter q to exit:''') docker_image=docker_image )) + self._print_generate(build_dir=build_dir) + + def _print_generate(self, build_dir): format_dir = f''' generate compile.yaml successful @@ -252,6 +282,13 @@ oebuild bitbake ''' logger.info(format_dir) + def _check_compile(self, compile_dir: str): + if not os.path.exists(compile_dir): + raise ValueError(f"the compile_dir:{compile_dir} is not exists, please check again") + + parse_compile = ParseCompile(compile_dir) + return parse_compile.platform + def _check_param_in_host(self, args): if args.toolchain_dir == '': raise ValueError("build in host must points toolchain directory in '-t' param") diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index 9a68819..02ae440 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -18,7 +18,7 @@ import sys from oebuild.command import OebuildCommand import oebuild.util as oebuild_util -from oebuild.configure import Configure, YOCTO_META_OPENEULER, ConfigBasicRepo, CONFIG, Config +from oebuild.configure import Configure, YOCTO_META_OPENEULER, ConfigBasicRepo, CONFIG, COMPILE_YAML, Config from oebuild.m_log import logger class Init(OebuildCommand): @@ -99,6 +99,9 @@ class Init(OebuildCommand): logger.info("init %s successful",args.directory) format_msg = f''' +There is a build configuration example file under {args.directory}/.oebuild/compile.yaml.sample, +if you want to block complex generate instructions, you can directly copy a configuration file, +and then modify it according to your own needs, and then execute `oebuild generate -c `. please execute the follow commands next cd {os.path.abspath(os.getcwd())} @@ -156,3 +159,14 @@ please execute the follow commands next shutil.copyfile(config, os.path.join(updir, CONFIG)) except FileNotFoundError: logger.error("mkdir config faild") + + @staticmethod + def copy_compile_file(updir : str): + ''' + copy oebuild compile.yaml.sample to some directory + ''' + try: + compile = oebuild_util.get_compile_yaml_dir() + shutil.copyfile(compile, os.path.join(updir, COMPILE_YAML)) + except FileNotFoundError: + logger.error("mkdir compile.yaml.sample faild") diff --git a/src/oebuild/configure.py b/src/oebuild/configure.py index f685754..6481210 100644 --- a/src/oebuild/configure.py +++ b/src/oebuild/configure.py @@ -21,6 +21,7 @@ PathType = Union[str, os.PathLike] YOCTO_META_OPENEULER = "yocto_meta_openeuler" CONFIG = "config" +COMPILE_YAML = "compile.yaml.sample" class OebuildNotFound(RuntimeError): '''Neither the current directory nor any parent has a oebuild workspace.''' diff --git a/src/oebuild/util.py b/src/oebuild/util.py index d012103..5378b3e 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -24,6 +24,7 @@ from oebuild.version import __version__ CONFIG_YAML = 'config.yaml' UPGRADE_YAML = 'upgrade.yaml' +COMPILE_YAML = 'compile.yaml.sample' def read_yaml(yaml_dir : pathlib.Path): ''' @@ -82,6 +83,12 @@ def get_config_yaml_dir(): ''' return os.path.join(get_base_oebuild(), 'app/conf', CONFIG_YAML) +def get_compile_yaml_dir(): + ''' + return compile.yaml.sample yaml dir + ''' + return os.path.join(get_base_oebuild(), 'app/conf', COMPILE_YAML) + def get_upgrade_yaml_dir(): ''' return upgrade yaml dir -- Gitee From 0371a5d16f7dfcdf3b1b5b9d476c7e14ff85c23b Mon Sep 17 00:00:00 2001 From: alichinese Date: Mon, 19 Jun 2023 11:30:59 +0800 Subject: [PATCH 2/2] version: upgrade to 0.0.25 * update version to 0.0.25 Signed-off-by: lixinyu --- src/oebuild/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oebuild/version.py b/src/oebuild/version.py index 45f3ab9..bc48636 100644 --- a/src/oebuild/version.py +++ b/src/oebuild/version.py @@ -10,4 +10,4 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' -__version__ = '0.0.24' +__version__ = '0.0.25' -- Gitee