diff options
-rw-r--r-- | mesonbuild/mlog.py | 3 | ||||
-rw-r--r-- | mesonbuild/mparser.py | 70 | ||||
-rw-r--r-- | mesonbuild/rewriter.py | 36 |
3 files changed, 54 insertions, 55 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 3f33240..440ce8b 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -233,7 +233,6 @@ def get_error_location_string(fname: str, lineno: str) -> str: def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], once: bool = False, **kwargs: T.Any) -> None: - from .environment import build_filename from .mesonlib import MesonException, relpath # The typing requirements here are non-obvious. Lists are invariant, @@ -251,7 +250,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], location = kwargs.pop('location', None) if location is not None: - location_file = relpath(location.subdir, os.getcwd()) + location_file = relpath(location.filename, os.getcwd()) location_str = get_error_location_string(location_file, location.lineno) # Unions are frankly awful, and we have to T.cast here to get mypy # to understand that the list concatenation is safe diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 2b503f1..430c89e 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -72,9 +72,9 @@ class BlockParseException(MesonException): self.colno = colno class Token: - def __init__(self, tid, subdir, line_start, lineno, colno, bytespan, value): + def __init__(self, tid, filename, line_start, lineno, colno, bytespan, value): self.tid = tid - self.subdir = subdir + self.filename = filename self.line_start = line_start self.lineno = lineno self.colno = colno @@ -132,7 +132,7 @@ class Lexer: def getline(self, line_start): return self.code[line_start:self.code.find('\n', line_start)] - def lex(self, subdir): + def lex(self, filename): line_start = 0 lineno = 1 loc = 0 @@ -205,9 +205,9 @@ This will become a hard error in a future Meson release.""", self.getline(line_s else: if match_text in self.future_keywords: mlog.warning("Identifier '{}' will become a reserved keyword in a future release. Please rename it.".format(match_text), - location=types.SimpleNamespace(subdir=subdir, lineno=lineno)) + location=types.SimpleNamespace(filename=filename, lineno=lineno)) value = match_text - yield Token(tid, subdir, curline_start, curline, col, bytespan, value) + yield Token(tid, filename, curline_start, curline, col, bytespan, value) break if not matched: raise ParseException('lexer', self.getline(line_start), lineno, col) @@ -223,7 +223,7 @@ class BaseNode: class ElementaryNode(BaseNode): def __init__(self, token): self.lineno = token.lineno - self.subdir = token.subdir + self.filename = token.filename self.colno = token.colno self.value = token.value self.bytespan = token.bytespan @@ -263,7 +263,7 @@ class BreakNode(ElementaryNode): class ArrayNode(BaseNode): def __init__(self, args, lineno, colno, end_lineno, end_colno): - self.subdir = args.subdir + self.filename = args.filename self.lineno = lineno self.colno = colno self.end_lineno = end_lineno @@ -272,7 +272,7 @@ class ArrayNode(BaseNode): class DictNode(BaseNode): def __init__(self, args, lineno, colno, end_lineno, end_colno): - self.subdir = args.subdir + self.filename = args.filename self.lineno = lineno self.colno = colno self.end_lineno = end_lineno @@ -281,14 +281,14 @@ class DictNode(BaseNode): class EmptyNode(BaseNode): def __init__(self, lineno, colno): - self.subdir = '' + self.filename = '' self.lineno = lineno self.colno = colno self.value = None class OrNode(BaseNode): def __init__(self, left, right): - self.subdir = left.subdir + self.filename = left.filename self.lineno = left.lineno self.colno = left.colno self.left = left @@ -296,7 +296,7 @@ class OrNode(BaseNode): class AndNode(BaseNode): def __init__(self, left, right): - self.subdir = left.subdir + self.filename = left.filename self.lineno = left.lineno self.colno = left.colno self.left = left @@ -306,14 +306,14 @@ class ComparisonNode(BaseNode): def __init__(self, ctype, left, right): self.lineno = left.lineno self.colno = left.colno - self.subdir = left.subdir + self.filename = left.filename self.left = left self.right = right self.ctype = ctype class ArithmeticNode(BaseNode): def __init__(self, operation, left, right): - self.subdir = left.subdir + self.filename = left.filename self.lineno = left.lineno self.colno = left.colno self.left = left @@ -322,14 +322,14 @@ class ArithmeticNode(BaseNode): class NotNode(BaseNode): def __init__(self, location_node, value): - self.subdir = location_node.subdir + self.filename = location_node.filename self.lineno = location_node.lineno self.colno = location_node.colno self.value = value class CodeBlockNode(BaseNode): def __init__(self, location_node): - self.subdir = location_node.subdir + self.filename = location_node.filename self.lineno = location_node.lineno self.colno = location_node.colno self.lines = [] @@ -338,13 +338,13 @@ class IndexNode(BaseNode): def __init__(self, iobject, index): self.iobject = iobject self.index = index - self.subdir = iobject.subdir + self.filename = iobject.filename self.lineno = iobject.lineno self.colno = iobject.colno class MethodNode(BaseNode): - def __init__(self, subdir, lineno, colno, source_object, name, args): - self.subdir = subdir + def __init__(self, filename, lineno, colno, source_object, name, args): + self.filename = filename self.lineno = lineno self.colno = colno self.source_object = source_object @@ -353,8 +353,8 @@ class MethodNode(BaseNode): self.args = args class FunctionNode(BaseNode): - def __init__(self, subdir, lineno, colno, end_lineno, end_colno, func_name, args): - self.subdir = subdir + def __init__(self, filename, lineno, colno, end_lineno, end_colno, func_name, args): + self.filename = filename self.lineno = lineno self.colno = colno self.end_lineno = end_lineno @@ -364,8 +364,8 @@ class FunctionNode(BaseNode): self.args = args class AssignmentNode(BaseNode): - def __init__(self, subdir, lineno, colno, var_name, value): - self.subdir = subdir + def __init__(self, filename, lineno, colno, var_name, value): + self.filename = filename self.lineno = lineno self.colno = colno self.var_name = var_name @@ -373,8 +373,8 @@ class AssignmentNode(BaseNode): self.value = value class PlusAssignmentNode(BaseNode): - def __init__(self, subdir, lineno, colno, var_name, value): - self.subdir = subdir + def __init__(self, filename, lineno, colno, var_name, value): + self.filename = filename self.lineno = lineno self.colno = colno self.var_name = var_name @@ -398,7 +398,7 @@ class IfClauseNode(BaseNode): class UMinusNode(BaseNode): def __init__(self, current_location, value): - self.subdir = current_location.subdir + self.filename = current_location.filename self.lineno = current_location.lineno self.colno = current_location.colno self.value = value @@ -411,8 +411,8 @@ class IfNode(BaseNode): self.block = block class TernaryNode(BaseNode): - def __init__(self, subdir, lineno, colno, condition, trueblock, falseblock): - self.subdir = subdir + def __init__(self, filename, lineno, colno, condition, trueblock, falseblock): + self.filename = filename self.lineno = lineno self.colno = colno self.condition = condition @@ -423,7 +423,7 @@ class ArgumentNode(BaseNode): def __init__(self, token): self.lineno = token.lineno self.colno = token.colno - self.subdir = token.subdir + self.filename = token.filename self.arguments = [] self.commas = [] self.kwargs = {} @@ -485,9 +485,9 @@ comparison_map = {'equal': '==', # 9 plain token class Parser: - def __init__(self, code, subdir): + def __init__(self, code, filename): self.lexer = Lexer(code) - self.stream = self.lexer.lex(subdir) + self.stream = self.lexer.lex(filename) self.current = Token('eof', '', 0, 0, 0, (0, 0), None) self.getsym() self.in_ternary = False @@ -531,13 +531,13 @@ class Parser: value = self.e1() if not isinstance(left, IdNode): raise ParseException('Plusassignment target must be an id.', self.getline(), left.lineno, left.colno) - return PlusAssignmentNode(left.subdir, left.lineno, left.colno, left.value, value) + return PlusAssignmentNode(left.filename, left.lineno, left.colno, left.value, value) elif self.accept('assign'): value = self.e1() if not isinstance(left, IdNode): raise ParseException('Assignment target must be an id.', self.getline(), left.lineno, left.colno) - return AssignmentNode(left.subdir, left.lineno, left.colno, left.value, value) + return AssignmentNode(left.filename, left.lineno, left.colno, left.value, value) elif self.accept('questionmark'): if self.in_ternary: raise ParseException('Nested ternary operators are not allowed.', @@ -547,7 +547,7 @@ class Parser: self.expect('colon') falseblock = self.e1() self.in_ternary = False - return TernaryNode(left.subdir, left.lineno, left.colno, left, trueblock, falseblock) + return TernaryNode(left.filename, left.lineno, left.colno, left, trueblock, falseblock) return left def e2(self): @@ -626,7 +626,7 @@ class Parser: if not isinstance(left, IdNode): raise ParseException('Function call must be applied to plain id', self.getline(), left.lineno, left.colno) - left = FunctionNode(left.subdir, left.lineno, left.colno, self.current.lineno, self.current.colno, left.value, args) + left = FunctionNode(left.filename, left.lineno, left.colno, self.current.lineno, self.current.colno, left.value, args) go_again = True while go_again: go_again = False @@ -718,7 +718,7 @@ class Parser: self.expect('lparen') args = self.args() self.expect('rparen') - method = MethodNode(methodname.subdir, methodname.lineno, methodname.colno, source_object, methodname.value, args) + method = MethodNode(methodname.filename, methodname.lineno, methodname.colno, source_object, methodname.value, args) if self.accept('dot'): return self.method_call(method) return method diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index 2a65746..39d8337 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -651,8 +651,8 @@ class Rewriter: mlog.log(' -- Source', mlog.green(i), 'is already defined for the target --> skipping') continue mlog.log(' -- Adding source', mlog.green(i), 'at', - mlog.yellow('{}:{}'.format(node.subdir, node.lineno))) - token = Token('string', node.subdir, 0, 0, 0, None, i) + mlog.yellow('{}:{}'.format(node.filename, node.lineno))) + token = Token('string', node.filename, 0, 0, 0, None, i) to_append += [StringNode(token)] # Append to the AST at the right place @@ -695,7 +695,7 @@ class Rewriter: arg_node = root assert(arg_node is not None) mlog.log(' -- Removing source', mlog.green(i), 'from', - mlog.yellow('{}:{}'.format(string_node.subdir, string_node.lineno))) + mlog.yellow('{}:{}'.format(string_node.filename, string_node.lineno))) arg_node.arguments.remove(string_node) # Mark the node as modified @@ -712,24 +712,24 @@ class Rewriter: id_base = re.sub(r'[- ]', '_', cmd['target']) target_id = id_base + '_exe' if cmd['target_type'] == 'executable' else '_lib' source_id = id_base + '_sources' - subdir = os.path.join(cmd['subdir'], environment.build_filename) + filename = os.path.join(cmd['subdir'], environment.build_filename) # Build src list - src_arg_node = ArgumentNode(Token('string', subdir, 0, 0, 0, None, '')) + src_arg_node = ArgumentNode(Token('string', filename, 0, 0, 0, None, '')) src_arr_node = ArrayNode(src_arg_node, 0, 0, 0, 0) - src_far_node = ArgumentNode(Token('string', subdir, 0, 0, 0, None, '')) - src_fun_node = FunctionNode(subdir, 0, 0, 0, 0, 'files', src_far_node) - src_ass_node = AssignmentNode(subdir, 0, 0, source_id, src_fun_node) - src_arg_node.arguments = [StringNode(Token('string', subdir, 0, 0, 0, None, x)) for x in cmd['sources']] + src_far_node = ArgumentNode(Token('string', filename, 0, 0, 0, None, '')) + src_fun_node = FunctionNode(filename, 0, 0, 0, 0, 'files', src_far_node) + src_ass_node = AssignmentNode(filename, 0, 0, source_id, src_fun_node) + src_arg_node.arguments = [StringNode(Token('string', filename, 0, 0, 0, None, x)) for x in cmd['sources']] src_far_node.arguments = [src_arr_node] # Build target - tgt_arg_node = ArgumentNode(Token('string', subdir, 0, 0, 0, None, '')) - tgt_fun_node = FunctionNode(subdir, 0, 0, 0, 0, cmd['target_type'], tgt_arg_node) - tgt_ass_node = AssignmentNode(subdir, 0, 0, target_id, tgt_fun_node) + tgt_arg_node = ArgumentNode(Token('string', filename, 0, 0, 0, None, '')) + tgt_fun_node = FunctionNode(filename, 0, 0, 0, 0, cmd['target_type'], tgt_arg_node) + tgt_ass_node = AssignmentNode(filename, 0, 0, target_id, tgt_fun_node) tgt_arg_node.arguments = [ - StringNode(Token('string', subdir, 0, 0, 0, None, cmd['target'])), - IdNode(Token('string', subdir, 0, 0, 0, None, source_id)) + StringNode(Token('string', filename, 0, 0, 0, None, cmd['target'])), + IdNode(Token('string', filename, 0, 0, 0, None, source_id)) ] src_ass_node.accept(AstIndentationGenerator()) @@ -742,7 +742,7 @@ class Rewriter: to_remove = target['node'] self.to_remove_nodes += [to_remove] mlog.log(' -- Removing target', mlog.green(cmd['target']), 'at', - mlog.yellow('{}:{}'.format(to_remove.subdir, to_remove.lineno))) + mlog.yellow('{}:{}'.format(to_remove.filename, to_remove.lineno))) elif cmd['operation'] == 'info': # T.List all sources in the target @@ -777,8 +777,8 @@ class Rewriter: self.functions[cmd['type']](cmd) def apply_changes(self): - assert(all(hasattr(x, 'lineno') and hasattr(x, 'colno') and hasattr(x, 'subdir') for x in self.modefied_nodes)) - assert(all(hasattr(x, 'lineno') and hasattr(x, 'colno') and hasattr(x, 'subdir') for x in self.to_remove_nodes)) + assert(all(hasattr(x, 'lineno') and hasattr(x, 'colno') and hasattr(x, 'filename') for x in self.modefied_nodes)) + assert(all(hasattr(x, 'lineno') and hasattr(x, 'colno') and hasattr(x, 'filename') for x in self.to_remove_nodes)) assert(all(isinstance(x, (ArrayNode, FunctionNode)) for x in self.modefied_nodes)) assert(all(isinstance(x, (ArrayNode, AssignmentNode, FunctionNode)) for x in self.to_remove_nodes)) # Sort based on line and column in reversed order @@ -797,7 +797,7 @@ class Rewriter: printer.post_process() new_data = printer.result.strip() data = { - 'file': i['node'].subdir, + 'file': i['node'].filename, 'str': new_data, 'node': i['node'], 'action': i['action'] |