2018-08-13 14:11:22 +02:00
|
|
|
# kas - setup tool for bitbake based projects
|
|
|
|
#
|
|
|
|
# Copyright (c) Siemens AG, 2018
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
"""
|
|
|
|
This module contains the implementation of the kas context.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import logging
|
2018-08-24 19:17:57 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
import distro
|
|
|
|
|
|
|
|
def get_distro_id_base():
|
|
|
|
"""
|
|
|
|
Returns a compatible distro id.
|
|
|
|
"""
|
|
|
|
return distro.like() or distro.id()
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
import platform
|
|
|
|
|
|
|
|
def get_distro_id_base():
|
|
|
|
"""
|
|
|
|
Wrapper around platform.dist to simulate distro.id
|
|
|
|
platform.dist is deprecated and will be removed in python 3.7
|
|
|
|
Use the 'distro' package instead.
|
|
|
|
"""
|
|
|
|
return platform.dist()[0]
|
2018-08-13 14:11:22 +02:00
|
|
|
|
2018-08-24 19:17:59 +02:00
|
|
|
|
2018-08-24 19:17:58 +02:00
|
|
|
__context__ = None
|
|
|
|
|
|
|
|
|
2020-06-15 22:03:29 +02:00
|
|
|
def create_global_context(args):
|
2018-08-24 19:17:58 +02:00
|
|
|
"""
|
2018-09-05 11:13:03 +02:00
|
|
|
Creates global context as singleton.
|
2018-08-24 19:17:58 +02:00
|
|
|
"""
|
|
|
|
global __context__
|
2020-06-15 22:03:29 +02:00
|
|
|
__context__ = Context(args)
|
2018-08-24 19:17:58 +02:00
|
|
|
return __context__
|
|
|
|
|
|
|
|
|
|
|
|
def get_context():
|
|
|
|
"""
|
2018-09-05 11:13:03 +02:00
|
|
|
Returns singleton global context.
|
2018-08-24 19:17:58 +02:00
|
|
|
"""
|
|
|
|
return __context__
|
|
|
|
|
2018-08-13 14:11:22 +02:00
|
|
|
|
|
|
|
class Context:
|
|
|
|
"""
|
|
|
|
Implements the kas build context.
|
|
|
|
"""
|
2020-06-15 22:03:29 +02:00
|
|
|
def __init__(self, args):
|
2018-08-13 14:11:22 +02:00
|
|
|
self.__kas_work_dir = os.environ.get('KAS_WORK_DIR', os.getcwd())
|
|
|
|
self.__kas_repo_ref_dir = os.environ.get('KAS_REPO_REF_DIR', None)
|
|
|
|
self.setup_initial_environ()
|
|
|
|
self.keep_config = False
|
2018-08-24 19:17:59 +02:00
|
|
|
self.config = None
|
2020-06-15 22:03:29 +02:00
|
|
|
self.args = args
|
2018-08-13 14:11:22 +02:00
|
|
|
|
|
|
|
def setup_initial_environ(self):
|
|
|
|
"""
|
2018-09-05 11:13:03 +02:00
|
|
|
Sets the environment variables for processes that are
|
2018-08-13 14:11:22 +02:00
|
|
|
started by kas.
|
|
|
|
"""
|
2018-08-21 10:58:19 +02:00
|
|
|
self.environ = {}
|
|
|
|
distro_bases = get_distro_id_base().lower().split()
|
|
|
|
for distro_base in distro_bases:
|
|
|
|
if distro_base in ['fedora', 'suse', 'opensuse']:
|
|
|
|
self.environ = {'LC_ALL': 'en_US.utf8',
|
|
|
|
'LANG': 'en_US.utf8',
|
|
|
|
'LANGUAGE': 'en_US'}
|
|
|
|
break
|
|
|
|
elif distro_base in ['debian', 'ubuntu', 'gentoo']:
|
|
|
|
self.environ = {'LC_ALL': 'en_US.UTF-8',
|
|
|
|
'LANG': 'en_US.UTF-8',
|
|
|
|
'LANGUAGE': 'en_US:en'}
|
|
|
|
break
|
|
|
|
if self.environ == {}:
|
|
|
|
logging.warning('kas: No supported distros found in %s. '
|
|
|
|
'No default locales set.', distro_bases)
|
2018-08-13 14:11:22 +02:00
|
|
|
|
2018-09-11 16:15:20 +02:00
|
|
|
for key in ['http_proxy', 'https_proxy', 'ftp_proxy', 'no_proxy',
|
2018-09-14 19:27:47 +02:00
|
|
|
'SSH_AUTH_SOCK']:
|
2018-08-13 14:11:22 +02:00
|
|
|
val = os.environ.get(key, None)
|
|
|
|
if val:
|
|
|
|
self.environ[key] = val
|
|
|
|
|
|
|
|
@property
|
|
|
|
def build_dir(self):
|
|
|
|
"""
|
2018-09-05 11:13:03 +02:00
|
|
|
The path to the build directory
|
2018-08-13 14:11:22 +02:00
|
|
|
"""
|
|
|
|
return os.path.join(self.__kas_work_dir, 'build')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def kas_work_dir(self):
|
|
|
|
"""
|
|
|
|
The path to the kas work directory
|
|
|
|
"""
|
|
|
|
return self.__kas_work_dir
|
|
|
|
|
|
|
|
@property
|
|
|
|
def kas_repo_ref_dir(self):
|
|
|
|
"""
|
|
|
|
The reference directory for the repo
|
|
|
|
"""
|
|
|
|
return self.__kas_repo_ref_dir
|
2020-06-15 22:03:30 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def force_checkout(self):
|
|
|
|
return getattr(self.args, 'force_checkout', None)
|