-
Notifications
You must be signed in to change notification settings - Fork 474
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
Merge equivalent require blocks #2406
Conversation
Addresses KhronosGroup#2404 Merges extension require blocks that have identical children, extending the depends attribute with a logical or.
Here is a script I made in python that finds these cases, I'm not really sure how to handle license stuff, and I'm not sure where it should go so I didn't add it with this pull request. I'm also not very familiar with python so it has some flaws, namely that it just looks for a vk.xml in the same directory as the script, so I don't feel like it's good enough to be included as-is. import xml.etree.ElementTree as etree
import itertools
tree = etree.parse('vk.xml')
doc = tree.getroot()
extensions = doc.find('extensions')
def check_if_children_equal(req1, req2):
if len(req1) != len(req2):
return False
for child1, child2 in zip(req1, req2):
if child1.tag != child2.tag:
return False
if child1.attrib != child2.attrib:
return False
return True
# def check_if_children_equal
for ext in extensions:
req_with_depends = []
# put all candidates into a list
for req, count in zip(ext, itertools.count()):
if 'depends' in req.attrib:
req_with_depends.append((req, count))
# compare candidates in a pairwise manner
for tup1, it2_start in zip(req_with_depends[:-1], range(1, len(req_with_depends))):
for tup2 in req_with_depends[it2_start:]:
req1, req_count1 = tup1
req2, req_count2 = tup2
all_match = check_if_children_equal(req1, req2)
if all_match:
print('Found matching require block in extension {}:'.format(ext.attrib['name']))
print('blocks {} and {} are equal'.format(req_count1, req_count2))
print('require block {} attributes: {}'.format(req_count1, req1.attrib))
print('require block {} attributes: {}'.format(req_count2, req2.attrib))
print(' block children:')
for child1, child2 in zip(req1, req2):
print(' ', req_count1, ': ', child1.attrib)
print(' ', req_count2, ': ', child2.attrib) |
Thanks! If you are comfortable putting this at the start:
in the header, that will place it under Apache 2.0 on the same terms as other scripts in the repo and allow us to redistribute it while still giving you credit. It should go in the "scripts/" directory. |
Should be good now I think |
@@ -0,0 +1,46 @@ | |||
#!/usr/bin/env python3 | |||
# | |||
# Copyright 2024 <your actual name, or other organization holding copyright> |
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.
Please replace "your actual name, or other organization holding copyright" with, well, what it says :-)
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.
Oops, xd, yeah let me fix that
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 believe my pseudonym should be fine, I contributed to GCC under this name, the Free Software Foundation has the paperwork for that. I don't know if that's compatible or whatnot, but hopefully it's fine. If not I guess I can use my legal name but I would like to avoid that if possible.
This script prints out require blocks that are eligible to be merged together.
Addresses #2404
Merges extension require blocks that have identical children, extending the depends attribute with a logical or.