aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yapymake/__init__.py3
-rw-r--r--yapymake/makefile/__init__.py34
-rw-r--r--yapymake/makefile/token.py13
3 files changed, 50 insertions, 0 deletions
diff --git a/yapymake/__init__.py b/yapymake/__init__.py
index 8a0c31d..c90c250 100644
--- a/yapymake/__init__.py
+++ b/yapymake/__init__.py
@@ -18,5 +18,8 @@ def main() -> None:
assert file.first_non_special_target is not None
targets = [file.first_non_special_target]
+ if these_args.print_everything:
+ print(file)
+
for target in targets:
file.target(target).update(file)
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 <hyphen-minus>, or the -i option is present, or the special target .IGNORE
diff --git a/yapymake/makefile/token.py b/yapymake/makefile/token.py
index fd7de5b..57ad4f9 100644
--- a/yapymake/makefile/token.py
+++ b/yapymake/makefile/token.py
@@ -33,6 +33,9 @@ class TokenString(Iterable['Token']):
def __repr__(self) -> str:
return f'TokenString({repr(self._tokens)})'
+ def __str__(self) -> str:
+ return ''.join(str(x) for x in self._tokens)
+
def split_once(self, delimiter: str) -> Optional[Tuple['TokenString', 'TokenString']]:
result0: List[Token] = []
self_iter = iter(self._tokens)
@@ -65,11 +68,21 @@ class Token:
class TextToken(Token):
text: str
+ def __str__(self) -> str:
+ return self.text
+
@dataclass()
class MacroToken(Token):
name: str
replacement: Optional[Tuple[TokenString, TokenString]]
+ def __str__(self) -> str:
+ if self.replacement is None:
+ return f'$({self.name})'
+ else:
+ r1, r2 = self.replacement
+ return f'$({self.name}:{r1}={r2})'
+
macro_name = take_while1(lambda c: c.isalnum() or c in ['.', '_'])
def macro_expansion_body(end: str) -> Parser[MacroToken]: