meson_to_hermetic: Add global base project config / inheritence
Current changes to configs actually breaks the scripts to produce a valid Android.bp file Test: Refactor CL Bug: 357080225 Change-Id: I1d9064b8e9c206b5b8f410a0adc7dab552c0b232
This commit is contained in:
parent
801c7d64b3
commit
85de971256
4 changed files with 168 additions and 43 deletions
|
|
@ -2,36 +2,36 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
build = 'Soong'
|
||||
|
||||
[[project_config]]
|
||||
name = 'android_aarch64_drivers'
|
||||
# Base project config which contain shared attributes which
|
||||
# all other projects must contain / override
|
||||
[base_project_config]
|
||||
name = 'base_project_config'
|
||||
inherits_from = ''
|
||||
|
||||
[project_config.host_machine]
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
host_machine = 'android'
|
||||
build_machine = 'linux'
|
||||
[base_project_config.host_machine]
|
||||
cpu_family = ''
|
||||
cpu = ''
|
||||
host_machine = ''
|
||||
build_machine = ''
|
||||
|
||||
[project_config.meson_options]
|
||||
platforms = 'android'
|
||||
android-libbacktrace = 'disabled'
|
||||
[base_project_config.meson_options]
|
||||
platforms = ''
|
||||
gallium-drivers = ''
|
||||
vulkan-drivers = 'freedreno'
|
||||
freedreno-kmds = 'kgsl'
|
||||
platform-sdk-version = 33
|
||||
vulkan-drivers = ''
|
||||
|
||||
[project_config.header_not_supported]
|
||||
[base_project_config.header_not_supported]
|
||||
headers = []
|
||||
|
||||
[project_config.symbol_not_supported]
|
||||
[base_project_config.symbol_not_supported]
|
||||
symbols = []
|
||||
|
||||
[project_config.function_not_supported]
|
||||
[base_project_config.function_not_supported]
|
||||
functions = []
|
||||
|
||||
[project_config.link_not_supported]
|
||||
[base_project_config.link_not_supported]
|
||||
links = []
|
||||
|
||||
[project_config.ext_dependencies]
|
||||
[base_project_config.ext_dependencies]
|
||||
# DependencyTargetType
|
||||
# SHARED_LIBRARY = 1
|
||||
# STATIC_LIBRARY = 2
|
||||
|
|
@ -63,23 +63,24 @@ sync = [
|
|||
{ target_name = 'libutils', target_type = 1 }
|
||||
]
|
||||
|
||||
# Define new project configs
|
||||
[[project_config]]
|
||||
name = 'glibc_x86_64_build'
|
||||
|
||||
[project_config.meson_options]
|
||||
platforms = 'none'
|
||||
gallium-drivers = 'swrast'
|
||||
vulkan-drivers = ''
|
||||
glx = 'disabled'
|
||||
shared-glapi = 'disabled'
|
||||
[[project_config]] # Turnip + gfxstream
|
||||
name = 'android_aarch64_drivers'
|
||||
inherits_from = 'base_project_config'
|
||||
|
||||
[project_config.host_machine]
|
||||
cpu_family = 'x86_64'
|
||||
cpu = 'x86_64'
|
||||
host_machine = 'linux'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
host_machine = 'android'
|
||||
build_machine = 'linux'
|
||||
|
||||
[project_config.meson_options]
|
||||
platforms = 'android'
|
||||
android-libbacktrace = 'disabled'
|
||||
gallium-drivers = ''
|
||||
vulkan-drivers = 'freedreno,gfxstream-experimental'
|
||||
freedreno-kmds = 'kgsl'
|
||||
platform-sdk-version = 33
|
||||
|
||||
[project_config.header_not_supported]
|
||||
headers = []
|
||||
|
||||
|
|
@ -98,6 +99,40 @@ links = []
|
|||
# STATIC_LIBRARY = 2
|
||||
# HEADER_LIBRARY = 3
|
||||
# See meson_impl.py
|
||||
zlib = [
|
||||
{ target_name = 'libz', target_type = 2 }
|
||||
]
|
||||
|
||||
# Define new project configs
|
||||
[[project_config]]
|
||||
name = 'glibc_x86_64_build'
|
||||
inherits_from = 'base_project_config'
|
||||
|
||||
[project_config.meson_options]
|
||||
platforms = 'none'
|
||||
gallium-drivers = ''
|
||||
vulkan-drivers = 'gfxstream-experimental,swrast'
|
||||
glx = 'disabled'
|
||||
shared-glapi = 'disabled'
|
||||
|
||||
[project_config.header_not_supported]
|
||||
headers = []
|
||||
|
||||
[project_config.symbol_not_supported]
|
||||
symbols = []
|
||||
|
||||
[project_config.function_not_supported]
|
||||
functions = []
|
||||
|
||||
[project_config.link_not_supported]
|
||||
links = []
|
||||
|
||||
[project_config.host_machine]
|
||||
cpu_family = 'x86_64'
|
||||
cpu = 'x86_64'
|
||||
host_machine = 'linux'
|
||||
build_machine = 'linux'
|
||||
|
||||
[project_config.ext_dependencies]
|
||||
# DependencyTargetType
|
||||
# SHARED_LIBRARY = 1
|
||||
# STATIC_LIBRARY = 2
|
||||
# HEADER_LIBRARY = 3
|
||||
# See meson_impl.py
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class StaticLibrary(IncludeDirectories):
|
|||
return self.generated_headers + self.generated_sources
|
||||
|
||||
def __str__(self):
|
||||
return f"@StaticLibrary: name: {self.name}, LibraryType: {self.library_type}"
|
||||
return f'@StaticLibrary: name: {self.name}, LibraryType: {self.library_type}'
|
||||
|
||||
|
||||
class CustomTarget:
|
||||
|
|
@ -107,10 +107,10 @@ class ProjectConfig:
|
|||
in python objects. There are multiple project_config within each .toml
|
||||
file
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._build: str = '' # Global across all configs
|
||||
self._name: str = '' # name of this config
|
||||
self._inherits_from = ''
|
||||
# project_config.host_machine
|
||||
self._cpu_family: str = ''
|
||||
self._cpu: str = ''
|
||||
|
|
@ -141,8 +141,9 @@ class ProjectConfig:
|
|||
@staticmethod
|
||||
def create_project_config(build, **kwargs):
|
||||
project_config = ProjectConfig()
|
||||
project_config._build = kwargs.get(build) # Global across all configs
|
||||
project_config._build = build # Global across all configs
|
||||
project_config._name = kwargs.get('name') # name of this config
|
||||
project_config._inherits_from = kwargs.get('inherits_from')
|
||||
project_config._cpu_family = kwargs.get('host_machine').get('cpu_family')
|
||||
project_config._cpu = kwargs.get('host_machine').get('cpu')
|
||||
project_config._host_machine = kwargs.get('host_machine').get('host_machine')
|
||||
|
|
@ -163,6 +164,47 @@ class ProjectConfig:
|
|||
project_config._ext_dependencies = kwargs.get('ext_dependencies')
|
||||
return project_config
|
||||
|
||||
def extend(self, proj_config):
|
||||
"""
|
||||
Appends to the current instance of ProjectConfig with another
|
||||
This also overrides attributes like self._name to the given param
|
||||
:param proj_config: ProjectConfig
|
||||
:return: ProjectConfig
|
||||
"""
|
||||
self._build = proj_config.build
|
||||
self._name = proj_config.name
|
||||
self._inherits_from = proj_config.inherits_from
|
||||
self._cpu_family = proj_config.cpu_family
|
||||
self._cpu = proj_config.cpu
|
||||
self._host_machine = proj_config.host_machine
|
||||
self._build_machine = proj_config.build_machine
|
||||
|
||||
self._meson_options.update(proj_config.meson_options)
|
||||
self._headers_not_supported.extend(proj_config.headers_not_supported)
|
||||
self._symbols_not_supported.extend(proj_config.symbols_not_supported)
|
||||
self._functions_not_supported.extend(proj_config.functions_not_supported)
|
||||
self._links_not_supported.extend(proj_config.links_not_supported)
|
||||
self._ext_dependencies.update(proj_config.ext_dependencies)
|
||||
return self
|
||||
|
||||
def deepcopy(self):
|
||||
proj = ProjectConfig()
|
||||
proj._build = self._build
|
||||
proj._name = self._name
|
||||
proj._inherits_from = self._inherits_from
|
||||
proj._cpu_family = self._cpu_family
|
||||
proj._cpu = self._cpu
|
||||
proj._host_machine = self._host_machine
|
||||
proj._build_machine = self._build_machine
|
||||
|
||||
proj._meson_options.update(self._meson_options)
|
||||
proj._headers_not_supported.extend(self._headers_not_supported)
|
||||
proj._symbols_not_supported.extend(self._symbols_not_supported)
|
||||
proj._functions_not_supported.extend(self._functions_not_supported)
|
||||
proj._links_not_supported.extend(self._links_not_supported)
|
||||
proj._ext_dependencies.update(self._ext_dependencies)
|
||||
return proj
|
||||
|
||||
@property
|
||||
def build(self):
|
||||
return self._build
|
||||
|
|
@ -171,6 +213,10 @@ class ProjectConfig:
|
|||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def inherits_from(self):
|
||||
return self._inherits_from
|
||||
|
||||
@property
|
||||
def cpu(self):
|
||||
return self._cpu
|
||||
|
|
@ -211,6 +257,23 @@ class ProjectConfig:
|
|||
def ext_dependencies(self):
|
||||
return self._ext_dependencies
|
||||
|
||||
def __str__(self):
|
||||
return f"""
|
||||
@ProjectConfig: {self._name}
|
||||
inherits_from: {self._inherits_from}
|
||||
build: {self._build}
|
||||
cpu_family: {self._cpu_family}
|
||||
cpu: {self._cpu}
|
||||
host_machine: {self._host_machine}
|
||||
build_machine: {self._build_machine}
|
||||
meson_options: {self._meson_options}
|
||||
headers_not_supported: {self._headers_not_supported}
|
||||
symbols_not_supported: {self._symbols_not_supported}
|
||||
functions_not_supported: {self._functions_not_supported}
|
||||
links_not_supported: {self._links_not_supported}
|
||||
ext_dependencies: {self._ext_dependencies}
|
||||
"""
|
||||
|
||||
|
||||
class MesonProjectState:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -635,6 +635,14 @@ def load_dependencies(config):
|
|||
with open(config, 'rb') as f:
|
||||
data = tomllib.load(f)
|
||||
project_configs = data.get('project_config')
|
||||
base_config = data.get('base_project_config')
|
||||
# global dependencies
|
||||
for dep_name, targets in base_config.get('ext_dependencies').items():
|
||||
dep_targets = {
|
||||
t.get('target_name'): t.get('target_type') for t in targets
|
||||
}
|
||||
external_dep[dep_name] = dep_targets
|
||||
# project specific dependencies
|
||||
for project_config in project_configs:
|
||||
dependencies = project_config.get('ext_dependencies')
|
||||
for dep_name, targets in dependencies.items():
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ jinja_env = Environment(
|
|||
|
||||
# A map that holds the build-system to build file
|
||||
# Keep the keys lower-case for non-case sensitivity
|
||||
OUTPUT_FILES = {'soong': r'Android.bp', 'bazel': r'BUILD.bazel'}
|
||||
OUTPUT_FILES = {'soong': r'Android_res.bp', 'bazel': r'BUILD.bazel'}
|
||||
|
||||
|
||||
def generate_build_file(translator, build_type: str):
|
||||
|
|
@ -37,7 +37,6 @@ def generate_build_file(translator, build_type: str):
|
|||
static_libs_template = jinja_env.get_template(
|
||||
path + 'shared_library.txt'
|
||||
)
|
||||
print(static_lib)
|
||||
cc_lib = static_libs_template.render(
|
||||
name=static_lib.name,
|
||||
host_supported='false', # TODO(bpnguyen): Fix hardcoded host_supported
|
||||
|
|
@ -281,9 +280,6 @@ class MesonTranslator:
|
|||
|
||||
@property
|
||||
def config(self) -> ProjectConfig:
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return self._configs[self._state]
|
||||
|
||||
@property
|
||||
|
|
@ -309,13 +305,36 @@ class MesonTranslator:
|
|||
with open(self._config_file, 'rb') as f:
|
||||
data = tomllib.load(f)
|
||||
self._build = data.get('build')
|
||||
base_config = data.get('base_project_config')
|
||||
|
||||
configs = data.get('project_config')
|
||||
for config in configs:
|
||||
proj_config = ProjectConfig.create_project_config(self._build, **config)
|
||||
self._configs.append(
|
||||
ProjectConfig.create_project_config(self._build, **config)
|
||||
proj_config
|
||||
)
|
||||
self._meson_project_states.append(MesonProjectState())
|
||||
|
||||
new_configs = []
|
||||
# Handle Inheritance
|
||||
for config in self._configs:
|
||||
# Parent config, that contains shared attributes
|
||||
base_proj_config = ProjectConfig.create_project_config(self._build, **base_config)
|
||||
if not config.inherits_from:
|
||||
new_configs.append(config)
|
||||
continue
|
||||
if config.inherits_from == 'base_project_config':
|
||||
new_configs.append(
|
||||
base_proj_config.extend(config).deepcopy()
|
||||
)
|
||||
else:
|
||||
for proj_config in self._configs:
|
||||
if config.inherits_from == proj_config.name:
|
||||
new_configs.append(
|
||||
proj_config.extend(config).deepcopy()
|
||||
)
|
||||
self._configs = new_configs
|
||||
|
||||
|
||||
# Declares an empty attribute data class
|
||||
# metadata is allocated during Generators-runtime (I.E. generate_<host>_build.py)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue