-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace autogen DIF code by bazel rules #25775
Conversation
5770b36
to
abeb7fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pamaury. This looks good to me.
a373123
to
f0eaf86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I like that some of our path assumptions are removed here 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
""", | ||
), | ||
"_autogen_dif": attr.label( | ||
default = "//util:autogen_dif", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nt: autogen_dif is a misnomer since there is nothing "auto" about invoking a tool to generate something. "gen_dif" is better, but I know "autogen" is unfortunately pervasive in our project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tool is invoked by bazel which I guess is why it was called autogen
to start with. But generally I agree that gen would be better.
Amaury, I left some comments. You can ignore some of the Nits :) It is not clear this deals with the path change for ipgens, and for these did you fix the path in the href near the top in files like dif_clkmgr_autogen.h? It should refer to a specific top. |
b160c60
to
bc2fca6
Compare
util/autogen_dif.py
Outdated
|
||
# This file is $REPO_TOP/util/make_new_dif.py, so it takes two parent() | ||
# calls to get back to the top. | ||
REPO_TOP = Path(__file__).resolve().parent.parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REPO_TOP = Path(__file__).resolve().parent.parent | |
REPO_TOP = Path(__file__).resolve().parents[1] |
I think repo_top could be provided by a library like util/base/lib.py, since all sorts of tools get it in all sorts of ways, and we could make a single more reliable way to get it. It could, for example, at least check that REPO_TOP / "util" is_dir().
A potentially more stable way to get REPO_TOP is from git, as in https://github.com/lowRISC/opentitan/blob/master/util/dvsim/dvsim.py#L154, but that fires a new subprocess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think relying on git is good idea because if someone downloads the code as a tarball checkout, this will make the tool fail for no good reason. I generally agree that this way of doing things is ugly but I think the issue that our python codebase is fundamentally broken in how it is organized.
Anyway, I have removed this particular REPO_TOP
as it turns out I could do without.
@@ -368,6 +368,23 @@ def search_ips(ip_path): # return list of config files | |||
return ips | |||
|
|||
|
|||
def get_ip_hjson_path(ip_name_snake: str, topcfg: Dict[str, object], repotop: Path) -> Path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will traverse through all modules twice and generate lists, once for ipgens, once for reggens, and then the "in" operator on lists is also O(N).
It is probably much better to get the module with lib.find_module(ip_name_snake) and then decide based on lib.is_ipgen and lib.is_top_reggen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The REPO_TOP comment is up to you, but I think creating a library function to retrieve repo_top will be good.
I would encourage you to take the comment about get_ip_hjson_path more seriously. Topgen uses code like I suggest and it is way more efficient and clean.
Otherwise LGTM
Currently, the code assumes earlgrey by hardcoding some paths in the library. This commit changes the code to remove assumption and directly take the hjson path in. The leaves the path guessing dance to the frontend. Signed-off-by: Amaury Pouly <[email protected]>
I have address your comment about
What do you think? I also fixed an issue with |
Instead of hardcoding REPO_TOP in everything, this library provides a generic way of finding the path. Signed-off-by: Amaury Pouly <[email protected]>
This tool is basically extracted from make_new_dif and focuses on generating the dif_<ip>.{c,h} and _unitest.cc files for a given IP. This tool will be used in conjunction with bazel to generate those files. Signed-off-by: Amaury Pouly <[email protected]>
Those files are currently generated by make_new_dif and checked-in the repository. With this rule, we will switch to generating them dynamically. Signed-off-by: Amaury Pouly <[email protected]>
Signed-off-by: Amaury Pouly <[email protected]>
In the next commit, we will remove all the autogenerated files in sw/device/lib/dif/autogen. This will break how autogen_testutils detects IPs with diff. The logic is change to the following: go through the list of IPs for the top of interest, check in sw/device/lib/dif if there is a file called dif_<ip>.h. This produces exactly the same result. Signed-off-by: Amaury Pouly <[email protected]>
There are not useful anymore. Signed-off-by: Amaury Pouly <[email protected]>
Signed-off-by: Amaury Pouly <[email protected]>
This functionality has been move to autogen_dif so simplify make_new_dif to actually... make NEW difs! The command line is also changed: instead of requiring a top-level cfg file (which makes little sense and pulls it topgen.lib), require to point to the IP's hjson directly. Signed-off-by: Amaury Pouly <[email protected]>
On second thought, I have introduce a new library, |
Thanks for adding the detection of repo_top. We can improve on this now, like recursing down till MODULE.bazel, BLOCKFILE, and/or util are found as you mention. |
The CI failures are unrelated to this PR. The check for unauthorized changes is failing because the PR changes too many files but this PR does not actually change any unauthorized files. |
This PR changes the way we manage the autogenerated part of the DIFs: instead of checking-in the autogenerated files, which is not super compatible with multitop, move those to bazel rules. This requires to split
make_new_dif
into two: the actual autogen part, and the part generating actually new DIFs.