diff options
author | Andoni Morales Alastruey <ylatuya@gmail.com> | 2020-10-18 09:59:12 +0200 |
---|---|---|
committer | Andoni Morales Alastruey <ylatuya@gmail.com> | 2021-01-21 11:21:33 +0100 |
commit | cc34b78d9064bc9866242417f2051f83e92b74e7 (patch) | |
tree | d495d0e9317136a1475f93b7212e16deca639f7d | |
parent | e5a020caad967b72f35b905ce533ee5c6e3a65b9 (diff) |
config: Initialize the build-tools config as part of the master config
This allows in the config to correctly set LD_LIBRARY_PATH based
on the build tools lib_suffix instead of hardcoded to 'lib'
This will also allow to support other features such as reusing
all the list,build, buildone commands for the build-tools prefix
with a --build-tools switch, which is currently not possible.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/640>
-rw-r--r-- | cerbero/bootstrap/build_tools.py | 34 | ||||
-rw-r--r-- | cerbero/config.py | 75 |
2 files changed, 63 insertions, 46 deletions
diff --git a/cerbero/bootstrap/build_tools.py b/cerbero/bootstrap/build_tools.py index e1982a30..6f5c8095 100644 --- a/cerbero/bootstrap/build_tools.py +++ b/cerbero/bootstrap/build_tools.py @@ -90,39 +90,7 @@ class BuildTools (BootstrapperBase, Fetch): return ret def _setup_env(self): - # Use a common prefix for the build tools for all the configurations - # so that it can be reused - config = Config() - config.prefix = self.config.build_tools_prefix - config.home_dir = self.config.home_dir - config.local_sources = self.config.local_sources - config.load() - - config.prefix = self.config.build_tools_prefix - config.build_tools_prefix = self.config.build_tools_prefix - config.sources = self.config.build_tools_sources - config.build_tools_sources = self.config.build_tools_sources - config.logs = self.config.build_tools_logs - config.build_tools_logs = self.config.build_tools_logs - config.cache_file = self.config.build_tools_cache - config.build_tools_cache = self.config.build_tools_cache - config.external_recipes = self.config.external_recipes - config.extra_mirrors = self.config.extra_mirrors - config.cached_sources = self.config.cached_sources - config.vs_install_path = self.config.vs_install_path - config.vs_install_version = self.config.vs_install_version - - if config.toolchain_prefix and not os.path.exists(config.toolchain_prefix): - os.makedirs(config.toolchain_prefix) - if not os.path.exists(config.prefix): - os.makedirs(config.prefix) - if not os.path.exists(config.sources): - os.makedirs(config.sources) - if not os.path.exists(config.logs): - os.makedirs(config.logs) - - config.do_setup_env() - self.cookbook = CookBook(config, offline=self.offline) + self.cookbook = CookBook(self.config.build_tools_config, offline=self.offline) self.recipes = self.BUILD_TOOLS self.recipes += self.PLAT_BUILD_TOOLS.get(self.config.platform, []) diff --git a/cerbero/config.py b/cerbero/config.py index e078fe61..c4de323d 100644 --- a/cerbero/config.py +++ b/cerbero/config.py @@ -143,6 +143,12 @@ class Variants(object): class Config (object): + ''' + Holds the configuration for the build + + @ivar build_tools_config: Configuration for build tools + @type build_tools_config: L{cerbero.config.Config} + ''' _properties = ['platform', 'target_platform', 'arch', 'target_arch', 'prefix', 'recipes_dir', 'host', 'build', 'target', @@ -173,9 +179,11 @@ class Config (object): cookbook = None - def __init__(self): + def __init__(self, is_build_tools_config=False): self._check_uninstalled() self.python_exe = Path(sys.executable).as_posix() + self.build_tools_config = None + self._is_build_tools_config = is_build_tools_config for a in self._properties: setattr(self, a, None) @@ -251,6 +259,10 @@ class Config (object): self._validate_properties() self._check_windows_is_x86_64() + # The build tools config is required to properly configure the environment + if not self._is_build_tools_config: + self._create_build_tools_config() + for config in list(self.arch_config.values()): if self.target_arch == Architecture.UNIVERSAL: config.sources = os.path.join(self.sources, config.target_arch) @@ -266,6 +278,7 @@ class Config (object): config._load_last_defaults() config._load_platform_config() config._validate_properties() + config.build_tools_config = self.build_tools_config # Ensure that variants continue to override all other configuration self.variants.override(variants_override) @@ -285,7 +298,10 @@ class Config (object): if self.vs_install_path: m.message('Using Visual Studio installed at {!r}'.format(self.vs_install_path)) - m.message('Install prefix will be {}'.format(self.prefix)) + if self._is_build_tools_config: + m.message('Build tools install prefix will be {}'.format(self.prefix)) + else: + m.message('Install prefix will be {}'.format(self.prefix)) # Store current os.environ data arches = [] if isinstance(self.universal_archs, dict): @@ -297,15 +313,12 @@ class Config (object): if arches: m.message('Building the following arches: ' + ' '.join(arches)) + def do_setup_env(self): self._create_path(self.prefix) # dict universal arches do not have an active prefix if not isinstance(self.universal_archs, dict): self._create_path(os.path.join(self.prefix, 'share', 'aclocal')) - self._create_path(os.path.join( - self.build_tools_prefix, 'share', 'aclocal')) - self._create_path(os.path.join( - self.build_tools_prefix, 'var', 'tmp')) libdir = os.path.join(self.prefix, 'lib%s' % self.lib_suffix) self.libdir = libdir @@ -432,14 +445,16 @@ class Config (object): ldflags = self._join_values(ldflags, ldflags_libdir) path = self.config_env.get('PATH', None) - path = self._join_path( - os.path.join(self.build_tools_prefix, 'bin'), path) + if not self._is_build_tools_config: + path = self._join_path( + os.path.join(self.build_tools_config.prefix, 'bin'), path) # Add the prefix bindir after the build-tools bindir so that on Windows # binaries are run with the same libraries that they are linked with. if bindir not in path and self.prefix_is_executable(): path = self._join_path(bindir, path) - - ld_library_path = os.path.join(self.build_tools_prefix, 'lib') + ld_library_path = '' + if not self._is_build_tools_config: + ld_library_path = os.path.join(self.build_tools_config.libdir) if self.prefix_is_executable(): ld_library_path = self._join_path(libdir, ld_library_path) if self.extra_lib_path is not None: @@ -621,12 +636,45 @@ class Config (object): return True def prefix_is_build_tools(self): - return self.build_tools_prefix == self.prefix + return self._is_build_tools_config def target_distro_version_gte(self, distro_version): assert distro_version.startswith(self.target_distro + "_") return self.target_distro_version >= distro_version + def _create_build_tools_config(self): + # Use a common prefix for the build tools for all the configurations + # so that it can be reused + self.build_tools_config = Config(is_build_tools_config=True) + self.build_tools_config.prefix = self.build_tools_prefix + self.build_tools_config.home_dir = self.home_dir + self.build_tools_config.local_sources = self.local_sources + self.build_tools_config.load() + + self.build_tools_config.prefix = self.build_tools_prefix + self.build_tools_config.build_tools_prefix = self.build_tools_prefix + self.build_tools_config.sources = self.build_tools_sources + self.build_tools_config.build_tools_sources = self.build_tools_sources + self.build_tools_config.logs = self.build_tools_logs + self.build_tools_config.build_tools_logs = self.build_tools_logs + self.build_tools_config.cache_file = self.build_tools_cache + self.build_tools_config.build_tools_cache = self.build_tools_cache + self.build_tools_config.external_recipes = self.external_recipes + self.build_tools_config.extra_mirrors = self.extra_mirrors + self.build_tools_config.cached_sources = self.cached_sources + self.build_tools_config.vs_install_path = self.vs_install_path + self.build_tools_config.vs_install_version = self.vs_install_version + + if self.build_tools_config.toolchain_prefix and not os.path.exists(self.build_tools_config.toolchain_prefix): + os.makedirs(self.build_tools_config.toolchain_prefix) + if not os.path.exists(self.build_tools_config.prefix): + os.makedirs(self.build_tools_config.prefix) + if not os.path.exists(self.build_tools_config.sources): + os.makedirs(self.build_tools_config.sources) + if not os.path.exists(self.build_tools_config.logs): + os.makedirs(self.build_tools_config.logs) + self.build_tools_config.do_setup_env() + def _parse(self, filename, reset=True): config = {'os': os, '__file__': filename, 'env': self.config_env, 'cross': self.cross_compiling()} @@ -677,7 +725,8 @@ class Config (object): def _load_user_config(self): if os.path.exists(USER_CONFIG_FILE): - m.message('Loading default configuration from {}'.format(USER_CONFIG_FILE)) + if not self._is_build_tools_config: + m.message('Loading default configuration from {}'.format(USER_CONFIG_FILE)) self._parse(USER_CONFIG_FILE) def _load_cmd_config(self, filenames): @@ -706,7 +755,7 @@ class Config (object): def _get_toolchain_target_platform_arch(self): platform_arch = '{}_' + self.target_arch - if self.target_platform != Platform.WINDOWS or self.prefix_is_build_tools(): + if self.target_platform != Platform.WINDOWS or self._is_build_tools_config: return (self.target_platform, self.target_arch) if not self.variants.visualstudio: return ('mingw', self.target_arch) |