From 04614c57c96c556461186fea0668fc929d9edb05 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 6 Sep 2024 21:49:11 +0000 Subject: [PATCH] meson_to_hermetic: Fix cpu/cpu family not syncing on project configs Also handles some new configs that are needed for lavapipe Test: Run build--turnip.sh Bug: 357080225 Change-Id: I6270cabbc3916b3bb3d2167957ae561a4893e514 --- meson_to_hermetic/aosp.toml | 5 +- meson_to_hermetic/meson_impl.py | 55 ++++--------------- meson_to_hermetic/meson_to_hermetic.py | 6 +- .../templates/generate_python_build.txt | 8 +-- meson_to_hermetic_test/meson_impl_unittest.py | 22 -------- 5 files changed, 21 insertions(+), 75 deletions(-) diff --git a/meson_to_hermetic/aosp.toml b/meson_to_hermetic/aosp.toml index 18e25903e34..3c7c0885986 100644 --- a/meson_to_hermetic/aosp.toml +++ b/meson_to_hermetic/aosp.toml @@ -69,8 +69,9 @@ name = 'glibc_x86_64_build' [project_config.meson_options] platforms = 'none' -gallium-drivers = '' -vulkan-drivers = 'swrast' +gallium-drivers = 'swrast' +vulkan-drivers = '' +glx = 'disabled' [project_config.host_machine] cpu_family = 'x86_64' diff --git a/meson_to_hermetic/meson_impl.py b/meson_to_hermetic/meson_impl.py index b2c8be5eb78..7df48dd25fc 100644 --- a/meson_to_hermetic/meson_impl.py +++ b/meson_to_hermetic/meson_impl.py @@ -16,10 +16,6 @@ _gRelativeDir = '' _gProjectCflags = [] _gProjectCppflags = [] -# Parameters set by config file -_gCpuFamily = 'unknown' -_gCpu = _gCpuFamily - _gProjectVersion = 'unknown' _gProjectOptions = [] @@ -54,8 +50,10 @@ class File: class Machine: - def __init__(self, system): + def __init__(self, system, cpu, cpu_family): self._system = system + self._cpu = cpu + self._cpu_family = cpu_family def system(self): return self._system @@ -64,10 +62,10 @@ class Machine: self._system = system def cpu_family(self): - return _gCpuFamily + return self._cpu_family def cpu(self): - return _gCpuFamily + return self._cpu class DependencyTargetType(Enum): @@ -383,8 +381,9 @@ class Meson: class Compiler(ABC): - def __init__(self): + def __init__(self, cpu_family): self._id = 'clang' + self._cpu_family = cpu_family @abstractmethod def has_header_symbol( @@ -503,7 +502,7 @@ class Compiler(ABC): exit('Unhandled library: ' + name) def sizeof(self, string): - table = _get_sizeof_table() + table = _get_sizeof_table(self._cpu_family) if string not in table: exit('Unhandled compiler sizeof: ' + string) @@ -572,36 +571,6 @@ def get_project_options(): return _gProjectOptions -def load_config_file(filename): - if not filename.endswith('.toml'): - exit('Config file that is not .toml is not supported.') - - with open(filename, 'rb') as f: - data = tomllib.load(f) - project_configs = data.get('project_config') - if project_configs is None: - exit(f'meson_options not defined in {filename}.') - project_config = project_configs[0] - # TODO(bpnguyen): Make so project config isn't hardcoded to pick the first set of configs - host_machine_settings = project_config.get('host_machine') - for key in host_machine_settings: - match key: - case 'cpu_family': - cpu_fam = host_machine_settings.get(key) - global _gCpuFamily - _gCpuFamily = cpu_fam - print(f'Config: cpu_family={_gCpuFamily}') - case 'cpu': - cpu = host_machine_settings.get(key) - global _gCpu - _gCpu = cpu - print(f'Config: cpu={_gCpu}') - case 'host_machine' | 'build_machine': - continue - case _: # Default case - exit(f'Unhandled config key: {key}') - - def add_project_arguments(args, language=[], native=False): global _gProjectCflags, _gProjectCppflags if type(args) is not list: @@ -630,15 +599,15 @@ def get_project_cppflags(): return _gProjectCppflags -def _get_sizeof_table(): +def _get_sizeof_table(cpu_family): table_32 = {'void*': 4} table_64 = {'void*': 8} - if _gCpuFamily == 'arm': + if cpu_family == 'arm' or cpu_family == 'x86_64': table = table_32 - elif _gCpuFamily == 'aarch64': + elif cpu_family == 'aarch64': table = table_64 else: - exit('sizeof unhandled cpu family: %s' % _gCpuFamily) + exit('sizeof unhandled cpu family: %s' % cpu_family) return table diff --git a/meson_to_hermetic/meson_to_hermetic.py b/meson_to_hermetic/meson_to_hermetic.py index 15c63a969ba..596b7882eb7 100644 --- a/meson_to_hermetic/meson_to_hermetic.py +++ b/meson_to_hermetic/meson_to_hermetic.py @@ -274,7 +274,7 @@ class MesonTranslator: print('CONFIG:', self._config_file) self._init_metadata() _generator = ( - SoongGenerator() if self._build.lower() == 'soong' else BazelGenerator() + SoongGenerator(self.config.cpu_family) if self._build.lower() == 'soong' else BazelGenerator(self.config.cpu_family) ) self._generator: impl.Compiler = _generator return self @@ -417,7 +417,9 @@ def module_import(name: str): return BazelPkgConfigModule() if name == 'pkgconfig' and meson_translator.host_machine.lower() == 'android': return impl.PkgConfigModule() - exit(f'Unhandled module: {name}') + if name == 'pkgconfig' and meson_translator.host_machine.lower() == 'linux': + return impl.PkgConfigModule() + exit(f'Unhandled module: "{name}" for host machine: "{meson_translator.host_machine}"') def load_dependencies(): diff --git a/meson_to_hermetic/templates/generate_python_build.txt b/meson_to_hermetic/templates/generate_python_build.txt index 72b0b4052e8..7e67c0f734b 100644 --- a/meson_to_hermetic/templates/generate_python_build.txt +++ b/meson_to_hermetic/templates/generate_python_build.txt @@ -39,17 +39,13 @@ def get_variable(name: str): meson = impl.Meson(meson_translator.generator) -host_machine = impl.Machine(meson_translator.host_machine) -build_machine = impl.Machine(meson_translator.build_machine) +host_machine = impl.Machine(meson_translator.host_machine, meson_translator.config.cpu, meson_translator.config.cpu_family) +build_machine = impl.Machine(meson_translator.build_machine, meson_translator.config.cpu, meson_translator.config.cpu_family) ### Open the build definition file open_output_file() -### Load config -load_config_file() - - ### Load dependencies load_dependencies() diff --git a/meson_to_hermetic_test/meson_impl_unittest.py b/meson_to_hermetic_test/meson_impl_unittest.py index 69c6d55dedf..f0b3ffa8d7e 100644 --- a/meson_to_hermetic_test/meson_impl_unittest.py +++ b/meson_to_hermetic_test/meson_impl_unittest.py @@ -35,28 +35,6 @@ class TestConfigParsing(unittest.TestCase): I.E. *.toml files """ - def test_load_config_file(self): - path = abs_toml_path / 'test.toml' - impl.load_config_file(str(path)) - - self.assertEqual(impl._gCpuFamily, 'cpu_family_test', 'gCpuFamily was not assigned ' - 'correctly after parsing') - self.assertEqual(impl._gCpu, 'cpu_test', 'gCpu was not assigned correctly after parsing') - - def test_load_config_file_fails_non_toml(self): - with self.assertRaises(SystemExit): - impl.load_config_file('non_toml.txt') - - def test_no_project_config_defined(self): - with self.assertRaises(SystemExit): - path = abs_toml_path / 'empty.toml' - impl.load_config_file(str(path)) - - def test_invalid_host_setting(self): - with self.assertRaises(SystemExit): - path = str(abs_toml_path / 'unhandled_host_settings.toml') - impl.load_config_file(path) - def test_load_dependencies(self): expected = { 'test_dep': {