Skip to content
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

platform: add a mechanism for AFU's to set platform macros #3130

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platforms/platmgr/tools/afu_platform_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ def getAfuIfc(args):
def injectAfuIfcChanges(args, afu_ifc_db, afu_ifc_req):
fname = afu_ifc_req['file_path']

# Allow an AFU's JSON configuration to create macros
if ('define' in afu_ifc_req):
if ('define' in afu_ifc_db):
afu_ifc_db['define'] += afu_ifc_req['define']
else:
afu_ifc_db['define'] = afu_ifc_req['define']
Comment on lines +289 to +292
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is concatenating lists, would this pattern work?

Suggested change
if ('define' in afu_ifc_db):
afu_ifc_db['define'] += afu_ifc_req['define']
else:
afu_ifc_db['define'] = afu_ifc_req['define']
afu_ifc_db.setdefault('define', []) += afu_ifc_req['define']

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yours does look better, but the base object doesn't have setdefault(). I think it's just a list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are of course right, it's a dict. But it looks like setdefault() can't be used as an l-value, so can't be the left side of +=.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks. This should work:

Suggested change
if ('define' in afu_ifc_db):
afu_ifc_db['define'] += afu_ifc_req['define']
else:
afu_ifc_db['define'] = afu_ifc_req['define']
afu_ifc_db.setdefault('define', []).extend(afu_ifc_req['define'])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that harder to understand than the original. Is it important to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important; merely a preference to avoid repetition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the first suggestion had actually worked I'd be totally on board. Thanks for trying.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small semantic difference; the first list afu_ifc_req['define'] is modified as well when a second list afu_ifc_req['define'] is concatenated, since = does not create a deep copy. I assume it does not make a difference here though.


if ('module-ports' not in afu_ifc_req):
return
if (not isinstance(afu_ifc_req['module-ports'], list)):
Expand Down
Loading