diff --git a/src/oebuild/app/plugins/bitbake/bitbake.py b/src/oebuild/app/plugins/bitbake/bitbake.py index e9fc70703e217a92171d12ac37ccd9a427c1873c..6981e26ce86abee4d26f8e327b050ab6c6418d00 100644 --- a/src/oebuild/app/plugins/bitbake/bitbake.py +++ b/src/oebuild/app/plugins/bitbake/bitbake.py @@ -19,6 +19,7 @@ from oebuild.configure import Configure from oebuild.parse_compile import ParseCompile, CheckCompileError from oebuild.parse_env import ParseEnv import oebuild.util as oebuild_util +from oebuild.util import PROXY_LIST from oebuild.app.plugins.bitbake.in_container import InContainer from oebuild.app.plugins.bitbake.in_host import InHost from oebuild.parse_template import BUILD_IN_HOST @@ -101,7 +102,8 @@ class Bitbake(OebuildCommand): except DockerException as d_e: logger.error(str(d_e)) return - in_container = InContainer(self.configure) + host_proxy = oebuild_util.get_host_proxy(PROXY_LIST) + in_container = InContainer(self.configure, host_proxy) in_container.exec(parse_env=parse_env, parse_compile=parse_compile, command=command) diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index d497d7cab47ea196c7a9383221610cc9bf0d9f32..db2392c56c96d0c343fc5b40efde3f9b309c4e96 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -29,9 +29,10 @@ class InContainer(BaseBuild): bitbake command execute in container ''' - def __init__(self, configure: Configure): + def __init__(self, configure: Configure, host_proxy): self.configure = configure self.client = DockerProxy() + self.host_proxy = host_proxy self.container_id = None def __del__(self): @@ -292,7 +293,13 @@ class InContainer(BaseBuild): set_template = f'export TEMPLATECONF="{bitbake_const.CONTAINER_SRC}/yocto-meta-openeuler/.oebuild"' init_oe_comand = f'. {bitbake_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {bitbake_const.CONTAINER_BUILD}/{build_dir}' - init_command = [init_sdk_command, set_template, init_oe_comand] + + init_proxy_command = "" + for key, value in self.host_proxy.items(): + key_git = key.replace('_', '.') + command = f'export {key}={value}; git config --global {key_git} {value};' + init_proxy_command = f'{init_proxy_command} {command}' + init_command = [init_sdk_command, set_template, init_oe_comand, init_proxy_command] new_content = self._init_bashrc_content(content, init_command) self.update_bashrc(container=container, content=new_content) diff --git a/src/oebuild/util.py b/src/oebuild/util.py index 5378b3e49f0213569a22925f8eb6abae855c6972..2032536434a304366ee21281cbe07917a3b141be 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -15,6 +15,7 @@ import os import time import random import getpass +import subprocess from ruamel.yaml import YAML from docker.errors import DockerException @@ -25,6 +26,7 @@ from oebuild.version import __version__ CONFIG_YAML = 'config.yaml' UPGRADE_YAML = 'upgrade.yaml' COMPILE_YAML = 'compile.yaml.sample' +PROXY_LIST = ['http_proxy', 'https_proxy'] def read_yaml(yaml_dir : pathlib.Path): ''' @@ -138,3 +140,16 @@ def get_instance(factory): Instantiate a class ''' return factory() + +def get_host_proxy(proxy_name): + host_proxy = {} + if proxy_name is None: + return host_proxy + + for name in proxy_name: + command = "env | grep %s | awk -F'=' '{print$NF}'" % name + value = subprocess.run(command, shell=True, capture_output=True).stdout.decode().strip() + if value != "": + host_proxy[name] = value + + return host_proxy diff --git a/src/oebuild/version.py b/src/oebuild/version.py index d705e18486ec6c342aa62aa5c142fe5ff79bc4c7..c1c18458641508c9657ccb790093385a4479c0c9 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.26' +__version__ = '0.0.28'