From fa31fa96b8088e5157cbb9022f3e77664cf7e5d8 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 25 Mar 2021 19:27:20 -0600 Subject: print out everything if asked to --- yapymake/makefile/__init__.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'yapymake/makefile/__init__.py') diff --git a/yapymake/makefile/__init__.py b/yapymake/makefile/__init__.py index 70b61d8..ddd049d 100644 --- a/yapymake/makefile/__init__.py +++ b/yapymake/makefile/__init__.py @@ -48,6 +48,20 @@ class Makefile: # TODO either discern command line vs MAKEFLAGS or don't pretend we can self._macros[name] = (MacroSource.CommandLine, TokenString.text(value)) + def __str__(self) -> str: + def header(text: str) -> str: + return text + '\n' + ('=' * len(text)) + return '\n'.join([ + header('Inference Rules'), + *[str(x) for x in self._inference_rules], + '', + header('Macros'), + *[f'{k}={v}' for k, (_, v) in self._macros.items()], + '', + header('Targets'), + *[str(x) for x in self._targets.values()], + ]) + def read(self, file: TextIO) -> None: lines_iter: PeekableIterator[str] = PeekableIterator(iter(file)) for line in lines_iter: @@ -263,6 +277,12 @@ class InferenceRule: s2: str commands: List['CommandLine'] + def __str__(self) -> str: + return '\n'.join([ + f'{self.s1}{self.s2}:', + *[f'\t{x}' for x in self.commands], + ]) + @dataclass() class Target: name: str @@ -270,6 +290,12 @@ class Target: commands: List['CommandLine'] already_updated: bool = False + def __str__(self) -> str: + return '\n'.join([ + f'{self.name}: {" ".join(self.prerequisites)}', + *[f'\t{x}' for x in self.commands], + ]) + def _path(self) -> ImpurePath: return ImpurePath(self.name) @@ -345,6 +371,14 @@ class CommandLine: first_token.text = first_token.text[1:] self.execution_line = TokenString(list((first_token, *tokens_iter))) + def __str__(self) -> str: + return ''.join([ + '-' if self.ignore_errors else '', + '@' if self.silent else '', + '+' if self.always_execute else '', + str(self.execution_line) + ]) + def execute(self, file: Makefile, current_target: 'Target') -> None: # POSIX: # > If the command prefix contains a , or the -i option is present, or the special target .IGNORE -- cgit v1.2.3