Repository navigation
Replace GNU Make Codegen with Python - #2241
ni-jfitzger wants to merge 12 commits into
Conversation
…nto replace-gnu-make-with-python
…doing codegen" Turns out the templates do tweak some metadata, even though we can't see a difference in the output. This reverts commit 8fad161.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2241 +/- ##
==========================================
- Coverage 88.12% 87.89% -0.23%
==========================================
Files 88 89 +1
Lines 22830 23071 +241
==========================================
+ Hits 20118 20278 +160
- Misses 2712 2793 +81
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Something seems off about the reported code coverage for build/helper. |
Apparently --source is supposed to be a comma-separated list. You can't pass it twice in the same command. |
This is (or should be) irrelevant. |
Please ensure there is an open issue for this. |
Yes, I created one last week and we fixed and closed it. |
…ce-gnu-make-with-python
| @@ -23,8 +23,6 @@ In order to have the ability to build and run the tests you will need a few thin | |||
|
|
|||
| - Install and enable [Windows Subsystem for Linux](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) | |||
There was a problem hiding this comment.
Is WSL still needed? I would hope not.
There was a problem hiding this comment.
Not sure. I'll need to try setting up without it.
For internal contributors, pyenv might make it difficult for tox to find multiple Python installations.
|
|
||
| tox -e clean | ||
|
|
||
| 1. To regenerate only some drivers, pass arguments to the code generator through `tox`. For example: |
There was a problem hiding this comment.
To generate the code for a subset of the driver APIs, pass arguments to the code generator through `tox`. For example:
- We try to call these "driver APIs" not drivers, iirc. consistently.
- I think this applies to first time generation, not only to re-generation.
|
|
||
| tox -e py312-codegen -- --driver nidmm --driver nitclk | ||
|
|
||
| `tox` isn't required: with the `codegen` dependencies installed (see `deps` in [tox.ini](./tox.ini)), you can run the |
There was a problem hiding this comment.
How about:
You can bypass `tox` and run the code generator directly if for some reason you prefer it. In order to do this, you must install all dependencies as listed in the `deps` section of in [tox.ini](./tox.ini); then run:
python -m build.codegen generate [--driver DRIVER ...]
The code generator also supports `clean` and `installers` commands. Use `--help` for details.
| """Generate the driver bindings, documentation and installers. | ||
|
|
||
| Run from anywhere with ``python -m build.codegen {generate,clean,installers}``. Everything is | ||
| regenerated on every run; no attempt is made to skip work that is already up to date. |
There was a problem hiding this comment.
Everything is
regenerated on every run; no attempt is made to skip work that is already up to date.
I would remove this. It's distracting noise only relevant to someone familiar with the history of the repo. Someone looking at script would reasonably assume otherwise.
|
|
||
| ROOT_DIR = Path(__file__).resolve().parent.parent | ||
| BUILD_HELPER_DIR = ROOT_DIR / 'build' | ||
| TEMPLATE_DIR = BUILD_HELPER_DIR / 'templates' |
There was a problem hiding this comment.
TEMPLATES_DIR
weird to be inconsistent
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Driver: |
There was a problem hiding this comment.
Let's consistently call these things driver API or driver bindings
Please check the repo to see which one we use more, including the main README.md.
| proto_file_name: str = None | ||
|
|
||
| @property | ||
| def src_dir(self): |
There was a problem hiding this comment.
How do you feel about adding type hints to this script?
There was a problem hiding this comment.
It shouldn't be too difficult.
|
|
||
| # In alphabetical order except put nifake first and nimodinst/nitclk last | ||
| # - nifake first to get the most code generator coverage | ||
| # - nimodinst last so that the version from nimodinst is used for any global versions (docs/conf.py) |
| print(f'{action:>15}: {path}') | ||
|
|
||
|
|
||
| def _find_template(driver, template_name): |
There was a problem hiding this comment.
how come the arg driver is not self?
There was a problem hiding this comment.
Consider calling this _get_template
[ ] I've updated CHANGELOG.md if applicable.What does this Pull Request accomplish?
The GNU Make code used for code generation was a barrier to entry for anyone not familar with GNU Make and, frankly, even for those who are familiar with it. Some of the code was very difficult to read. Variables and recipes were also scattered across the repo, making it more difficult to read.
This PR replaces those files and some of their Python code with a consolidated
build/codegen.py, which implements thecodegen,cleanandinstallerssteps.Performance: This seems to be faster than the old codegen, though how much faster may vary depending on your machine and your environment. Why is it faster? Because we don't launch Python every time we need to render a template. We use the active Python process, instead.
List issues fixed by this Pull Request below, if any.
What testing has been done?
Ran
tox -e clean,tox -e codegen,tox -e installers,tox -e codegen -- -driver nidmm. No difference seen in the generated files.Ran newly generated unit tests. These don't cover all of codegen.py, but it's more than we had for the MAKEFILE code. Our primary method of catching issues remains ensure_codegen_up_to_date.py, diffs and code review of PRs.