aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2018-08-07 21:20:49 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2018-10-05 00:14:44 +0300
commit1c6b8b72cb2b55a65d0a0784bb16acef58dc66c4 (patch)
tree917b4dfcd5f9c13495813dc5ffb4a9362bb097de /mesonbuild/interpreter.py
parenta0e4548c4169cd0db3992e8fc923e523e93643ed (diff)
downloadmeson-1c6b8b72cb2b55a65d0a0784bb16acef58dc66c4.zip
meson-1c6b8b72cb2b55a65d0a0784bb16acef58dc66c4.tar.gz
meson-1c6b8b72cb2b55a65d0a0784bb16acef58dc66c4.tar.bz2
Centralize description of build, host, and target, machines
Instead of just putting these together in the interpreter, put them together in `environment.py` so Meson's implementation can also better take advantage of them.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py87
1 files changed, 22 insertions, 65 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index a4d9472..c05b92a 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -31,7 +31,7 @@ from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabl
from .interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs
from .modules import ModuleReturnValue
-import os, sys, shutil, uuid
+import os, shutil, uuid
import re, shlex
import subprocess
from collections import namedtuple
@@ -573,57 +573,11 @@ class GeneratedListHolder(InterpreterObject, ObjectHolder):
def add_file(self, a):
self.held_object.add_file(a)
-class BuildMachine(InterpreterObject, ObjectHolder):
- def __init__(self, compilers):
- self.compilers = compilers
+# A machine that's statically known from the cross file
+class MachineHolder(InterpreterObject, ObjectHolder):
+ def __init__(self, machine_info):
InterpreterObject.__init__(self)
- held_object = environment.MachineInfo(environment.detect_system(),
- environment.detect_cpu_family(self.compilers),
- environment.detect_cpu(self.compilers),
- sys.byteorder)
- ObjectHolder.__init__(self, held_object)
- self.methods.update({'system': self.system_method,
- 'cpu_family': self.cpu_family_method,
- 'cpu': self.cpu_method,
- 'endian': self.endian_method,
- })
-
- @noPosargs
- @permittedKwargs({})
- def cpu_family_method(self, args, kwargs):
- return self.held_object.cpu_family
-
- @noPosargs
- @permittedKwargs({})
- def cpu_method(self, args, kwargs):
- return self.held_object.cpu
-
- @noPosargs
- @permittedKwargs({})
- def system_method(self, args, kwargs):
- return self.held_object.system
-
- @noPosargs
- @permittedKwargs({})
- def endian_method(self, args, kwargs):
- return self.held_object.endian
-
-# This class will provide both host_machine and
-# target_machine
-class CrossMachineInfo(InterpreterObject, ObjectHolder):
- def __init__(self, cross_info):
- InterpreterObject.__init__(self)
- minimum_cross_info = {'cpu', 'cpu_family', 'endian', 'system'}
- if set(cross_info) < minimum_cross_info:
- raise InterpreterException(
- 'Machine info is currently {}\n'.format(cross_info) +
- 'but is missing {}.'.format(minimum_cross_info - set(cross_info)))
- self.info = cross_info
- minfo = environment.MachineInfo(cross_info['system'],
- cross_info['cpu_family'],
- cross_info['cpu'],
- cross_info['endian'])
- ObjectHolder.__init__(self, minfo)
+ ObjectHolder.__init__(self, machine_info)
self.methods.update({'system': self.system_method,
'cpu': self.cpu_method,
'cpu_family': self.cpu_family_method,
@@ -1937,20 +1891,23 @@ class Interpreter(InterpreterBase):
self.build_def_files = [os.path.join(self.subdir, environment.build_filename)]
if not mock:
self.parse_project()
- self.builtin['build_machine'] = BuildMachine(self.coredata.compilers)
- if not self.build.environment.is_cross_build():
- self.builtin['host_machine'] = self.builtin['build_machine']
- self.builtin['target_machine'] = self.builtin['build_machine']
- else:
- cross_info = self.build.environment.cross_info
- if cross_info.has_host():
- self.builtin['host_machine'] = CrossMachineInfo(cross_info.config['host_machine'])
- else:
- self.builtin['host_machine'] = self.builtin['build_machine']
- if cross_info.has_target():
- self.builtin['target_machine'] = CrossMachineInfo(cross_info.config['target_machine'])
- else:
- self.builtin['target_machine'] = self.builtin['host_machine']
+
+ # Initialize machine descriptions. We can do a better job now because we
+ # have the compilers needed to gain more knowledge, so wipe out old
+ # inferrence and start over.
+ self.build.environment.machines.miss_defaulting()
+ self.build.environment.machines.detect_build(self.coredata.compilers)
+ self.build.environment.machines.default_missing()
+ assert self.build.environment.machines.build.cpu is not None
+ assert self.build.environment.machines.host.cpu is not None
+ assert self.build.environment.machines.target.cpu is not None
+
+ self.builtin['build_machine'] = \
+ MachineHolder(self.build.environment.machines.build)
+ self.builtin['host_machine'] = \
+ MachineHolder(self.build.environment.machines.host)
+ self.builtin['target_machine'] = \
+ MachineHolder(self.build.environment.machines.target)
def get_non_matching_default_options(self):
env = self.environment