The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
7.2 KiB
186 lines
7.2 KiB
8 years ago
|
# Copyright 2016 The Meson development team
|
||
|
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
# This class contains the basic functionality needed to run any interpreter
|
||
|
# or an interpreter-based tool.
|
||
|
|
||
6 years ago
|
from .. import interpreterbase, mparser, mesonlib
|
||
|
from .. import environment
|
||
8 years ago
|
|
||
6 years ago
|
from ..interpreterbase import InterpreterException, InvalidArguments, BreakRequest, ContinueRequest
|
||
8 years ago
|
|
||
8 years ago
|
import os, sys
|
||
8 years ago
|
|
||
|
class DontCareObject(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
8 years ago
|
|
||
|
class MockExecutable(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
8 years ago
|
|
||
8 years ago
|
class MockStaticLibrary(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
|
|
||
|
class MockSharedLibrary(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
|
|
||
8 years ago
|
class MockCustomTarget(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
|
|
||
|
class MockRunTarget(interpreterbase.InterpreterObject):
|
||
|
pass
|
||
|
|
||
8 years ago
|
ADD_SOURCE = 0
|
||
8 years ago
|
REMOVE_SOURCE = 1
|
||
8 years ago
|
|
||
8 years ago
|
class AstInterpreter(interpreterbase.InterpreterBase):
|
||
|
def __init__(self, source_root, subdir):
|
||
|
super().__init__(source_root, subdir)
|
||
6 years ago
|
self.visited_subdirs = {}
|
||
8 years ago
|
self.funcs.update({'project': self.func_do_nothing,
|
||
|
'test': self.func_do_nothing,
|
||
|
'benchmark': self.func_do_nothing,
|
||
|
'install_headers': self.func_do_nothing,
|
||
|
'install_man': self.func_do_nothing,
|
||
|
'install_data': self.func_do_nothing,
|
||
|
'install_subdir': self.func_do_nothing,
|
||
|
'configuration_data': self.func_do_nothing,
|
||
|
'configure_file': self.func_do_nothing,
|
||
|
'find_program': self.func_do_nothing,
|
||
|
'include_directories': self.func_do_nothing,
|
||
|
'add_global_arguments': self.func_do_nothing,
|
||
|
'add_global_link_arguments': self.func_do_nothing,
|
||
|
'add_project_arguments': self.func_do_nothing,
|
||
|
'add_project_link_arguments': self.func_do_nothing,
|
||
|
'message': self.func_do_nothing,
|
||
|
'generator': self.func_do_nothing,
|
||
|
'error': self.func_do_nothing,
|
||
|
'run_command': self.func_do_nothing,
|
||
|
'assert': self.func_do_nothing,
|
||
|
'subproject': self.func_do_nothing,
|
||
|
'dependency': self.func_do_nothing,
|
||
|
'get_option': self.func_do_nothing,
|
||
|
'join_paths': self.func_do_nothing,
|
||
|
'environment': self.func_do_nothing,
|
||
|
'import': self.func_do_nothing,
|
||
|
'vcs_tag': self.func_do_nothing,
|
||
|
'add_languages': self.func_do_nothing,
|
||
|
'declare_dependency': self.func_do_nothing,
|
||
6 years ago
|
'files': self.func_do_nothing,
|
||
|
'executable': self.func_do_nothing,
|
||
|
'static_library': self.func_do_nothing,
|
||
|
'shared_library': self.func_do_nothing,
|
||
|
'library': self.func_do_nothing,
|
||
|
'build_target': self.func_do_nothing,
|
||
|
'custom_target': self.func_do_nothing,
|
||
|
'run_target': self.func_do_nothing,
|
||
6 years ago
|
'subdir': self.func_subdir,
|
||
6 years ago
|
'set_variable': self.func_do_nothing,
|
||
|
'get_variable': self.func_do_nothing,
|
||
|
'is_variable': self.func_do_nothing,
|
||
|
})
|
||
|
|
||
|
def func_do_nothing(self, node, args, kwargs):
|
||
|
return True
|
||
|
|
||
6 years ago
|
def func_subdir(self, node, args, kwargs):
|
||
|
args = self.flatten_args(args)
|
||
|
if len(args) != 1 or not isinstance(args[0], str):
|
||
|
sys.stderr.write('Unable to evaluate subdir({}) in AstInterpreter --> Skipping\n'.format(args))
|
||
|
return
|
||
|
|
||
|
prev_subdir = self.subdir
|
||
|
subdir = os.path.join(prev_subdir, args[0])
|
||
|
absdir = os.path.join(self.source_root, subdir)
|
||
|
buildfilename = os.path.join(self.subdir, environment.build_filename)
|
||
|
absname = os.path.join(self.source_root, buildfilename)
|
||
|
symlinkless_dir = os.path.realpath(absdir)
|
||
|
if symlinkless_dir in self.visited_subdirs:
|
||
|
sys.stderr.write('Trying to enter {} which has already been visited --> Skipping\n'.format(args[0]))
|
||
|
return
|
||
|
self.visited_subdirs[symlinkless_dir] = True
|
||
|
|
||
|
if not os.path.isfile(absname):
|
||
|
sys.stderr.write('Unable to find build file {} --> Skipping\n'.format(buildfilename))
|
||
|
return
|
||
|
with open(absname, encoding='utf8') as f:
|
||
|
code = f.read()
|
||
|
assert(isinstance(code, str))
|
||
|
try:
|
||
|
codeblock = mparser.Parser(code, self.subdir).parse()
|
||
|
except mesonlib.MesonException as me:
|
||
|
me.file = buildfilename
|
||
|
raise me
|
||
|
|
||
|
self.subdir = subdir
|
||
|
self.evaluate_codeblock(codeblock)
|
||
|
self.subdir = prev_subdir
|
||
|
|
||
6 years ago
|
def method_call(self, node):
|
||
|
return True
|
||
|
|
||
|
def evaluate_arithmeticstatement(self, cur):
|
||
|
return 0
|
||
|
|
||
|
def evaluate_plusassign(self, node):
|
||
|
return 0
|
||
|
|
||
|
def evaluate_indexing(self, node):
|
||
|
return 0
|
||
|
|
||
|
def unknown_function_called(self, func_name):
|
||
6 years ago
|
pass
|
||
6 years ago
|
|
||
|
def reduce_arguments(self, args):
|
||
|
assert(isinstance(args, mparser.ArgumentNode))
|
||
|
if args.incorrect_order():
|
||
|
raise InvalidArguments('All keyword arguments must be after positional arguments.')
|
||
|
return args.arguments, args.kwargs
|
||
|
|
||
6 years ago
|
def evaluate_comparison(self, node):
|
||
|
return False
|
||
|
|
||
|
def evaluate_foreach(self, node):
|
||
|
try:
|
||
|
self.evaluate_codeblock(node.block)
|
||
|
except ContinueRequest:
|
||
|
pass
|
||
|
except BreakRequest:
|
||
|
pass
|
||
|
|
||
|
def evaluate_if(self, node):
|
||
|
for i in node.ifs:
|
||
|
self.evaluate_codeblock(i.block)
|
||
|
if not isinstance(node.elseblock, mparser.EmptyNode):
|
||
|
self.evaluate_codeblock(node.elseblock)
|
||
|
|
||
|
def get_variable(self, varname):
|
||
|
return 0
|
||
|
|
||
|
def assignment(self, node):
|
||
|
pass
|
||
|
|
||
6 years ago
|
def flatten_args(self, args):
|
||
|
# Resolve mparser.ArrayNode if needed
|
||
|
flattend_args = []
|
||
|
if isinstance(args, mparser.ArrayNode):
|
||
|
args = [x.value for x in args.args.arguments]
|
||
|
for i in args:
|
||
|
if isinstance(i, mparser.ArrayNode):
|
||
|
flattend_args += [x.value for x in i.args.arguments]
|
||
|
elif isinstance(i, str):
|
||
|
flattend_args += [i]
|
||
|
else:
|
||
|
pass
|
||
|
return flattend_args
|