grading_lib.makefile#
Makefile related routines.
The parser is high-level by design since the homework requirement do not need the full Makefile to be parsed. So far we only need the target names of a rule. If this parser is too much to mataintain we can offload checking- if-a-target-exist to GNU Make itself as well.
Module Contents#
Classes#
A high-level representation of a Makefile. |
|
Functions#
Invoke the target(s) in the Makefile. |
Data#
API#
- grading_lib.makefile.RULE_PATTERN = 'compile(...)'#
- grading_lib.makefile.VAR_DEF_PATTERN = 'compile(...)'#
- grading_lib.makefile.run_targets(targets: list[str], makefile_name: str = 'answer.mk', cwd: Optional[str | pathlib.Path] = None) grading_lib.common.CommandResult#
Invoke the target(s) in the Makefile.
Return True if the call is successful, False otherwise. Also return the output of the executation.
- class grading_lib.makefile.Rule(targets: str | list[str], prerequisites: list[str], recipe: list[str])#
Initialization
- property prereqs: list[str]#
Alias for prerequisites.
- __str__() str#
- __repr__() str#
- is_empty() bool#
- class grading_lib.makefile.VariableDefinition(name: str, value: str)#
Initialization
- class grading_lib.makefile.Makefile(path: pathlib.Path | str, rules: list[grading_lib.makefile.Rule])#
A high-level representation of a Makefile.
Alternative includes a tree-sitter’s one (alemuller/tree-sitter-make) via its python binding at tree-sitter/py-tree-sitter.
A Python one linuxlizard/pymake.
Initialization
- classmethod from_path(path: pathlib.Path | str) grading_lib.makefile.Makefile#
- classmethod from_text(text: str)#
- get_rule(targets: str | list[str]) Optional[grading_lib.makefile.Rule]#
- has_rule(targets: str | list[str]) bool#
- class grading_lib.makefile.MakefileBaseTestCase(methodName='runTest')#
Bases:
grading_lib.common.BaseTestCase- makefile_path: str | pathlib.Path = None#
- makefile: grading_lib.makefile.Makefile = None#
- classmethod setUpClass() None#
- copy_makefile(dest: Optional[pathlib.Path] = None, as_name: str = 'answer.mk') None#
Copy the student’s Makefile.
When dest is None, make a copy of the student’s Makefile in the same folder but with the name answer.mk.
- assertHasRuleForTarget(target_name: str, msg_template: str = "Rule for a target '{target_name}' does not exist. Its behavior cannot be verified.")#
The Makefile must have target target_name.
- assertRuleRecipeIsEmpty(target_name: str, msg_template: str = "Recipe of the rule for a target '{target_name}' is not empty.")#