From 9e0dc33f7b1895e084e70b0b18d84510eb6e0219 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 31 Dec 2024 11:01:12 +0100 Subject: [PATCH 09/10] Revert "a/bindings: improve reproducibility of bindings generation" This reverts commit d2fbd3ce8d962e4a46351df0f34f14de71871e00. --- src/xrt/auxiliary/bindings/bindings.py | 41 +++++++++++-------- .../auxiliary/bindings/steamvr_profiles.py | 2 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/xrt/auxiliary/bindings/bindings.py b/src/xrt/auxiliary/bindings/bindings.py index 3039629ef..28d4395ff 100755 --- a/src/xrt/auxiliary/bindings/bindings.py +++ b/src/xrt/auxiliary/bindings/bindings.py @@ -7,7 +7,8 @@ bindings.""" import argparse import json import copy -from operator import attrgetter +import itertools + def find_component_in_list_by_name(name, component_list, subaction_path=None, identifier_json_path=None): """Find a component with the given name in a list of components.""" @@ -123,6 +124,7 @@ class Component: Turn a Identifier's component paths into a list of Component objects. """ + monado_bindings = json_subpath["monado_bindings"] component_list = [] for component_name in json_subpath["components"]: # click, touch, ... matched_dpad_emulation = None @@ -130,7 +132,9 @@ class Component: json_subpath["dpad_emulation"]["position"] == component_name): matched_dpad_emulation = json_subpath["dpad_emulation"] - monado_binding = json_subpath["monado_bindings"].get(component_name, None) + monado_binding = None + if component_name in monado_bindings: + monado_binding = monado_bindings[component_name] steamvr_path = steamvr_subpath_name(identifier_json_path, json_subpath["type"]) if "steamvr_path" in json_subpath: @@ -220,9 +224,10 @@ class Identifier: identifier_list = [] for subaction_path in json_subaction_paths: # /user/hand/* - for json_path in sorted(json_subpaths.keys()): # /input/*, /output/* + for json_sub_path_itm in json_subpaths.items(): # /input/*, /output/* + json_path = json_sub_path_itm[0] # /input/trackpad # json object associated with a subpath (type, localized_name, ...) - json_subpath = json_subpaths[json_path] + json_subpath = json_sub_path_itm[1] # Oculus Touch a,b/x,y components only exist on one controller if "side" in json_subpath and "/user/hand/" + json_subpath["side"] != subaction_path: @@ -262,7 +267,7 @@ class Identifier: self.components = component_list self.dpad = dpad return - + class FeatureSet: """An AND of requirements (versions and/or extensions) under which a binding becomes available""" @@ -317,7 +322,7 @@ class Availability: if not optimize: self.feature_sets = set(feature_sets) return - + self.feature_sets = set() for feature_set in feature_sets: self.add_in_place(feature_set) @@ -460,8 +465,8 @@ class Profile: def __update_component_list(self): self.components = [] for identifier in self.identifiers: - self.components += identifier.components - self.components = sorted(self.components, key=attrgetter("steamvr_path")) + for component in identifier.components: + self.components.append(component) def availability(self): result = Availability(feature_sets=[]) @@ -499,8 +504,8 @@ class Bindings: def __init__(self, json_root): """Construct a bindings from a dictionary of profiles.""" - self.profiles = [Profile(profile_name, json_root["profiles"][profile_name]) for - profile_name in sorted(json_root["profiles"].keys())] + self.profiles = [Profile(profile_name, json_profile) for + profile_name, json_profile in json_root["profiles"].items()] self.__set_parent_profile_refs() self.__mine_for_diamond_errors() @@ -526,7 +531,7 @@ class Bindings: if profile.name in parent_path_set: return True parent_path_set.append(profile.name) - for parent in sorted(profile.parent_profiles, key=attrgetter("name")): + for parent in profile.parent_profiles: if self.__has_diamonds(parent, parent_path_set): return True return False @@ -572,7 +577,7 @@ def write_verify_switch_body(f, dict_of_lists, profile, profile_name, tab_char): Input is a file to write the code into, a dict where keys are length and the values are lists of strings of that length. And a suffix if any.""" f.write(f"{tab_char}\tswitch (length) {{\n") - for length in sorted(dict_of_lists.keys()): + for length in dict_of_lists.keys(): f.write(f"{tab_char}\tcase {str(length)}:\n\t\t{tab_char}") for path in sorted(dict_of_lists[length]): f.write(if_strcmp.format(exttab=tab_char, check=path)) @@ -613,7 +618,7 @@ def write_verify_func_switch(f, dict_of_lists, profile, profile_name, availabili closing.append(f'{tab_char}}}\n#endif // {ext_defines}\n') write_verify_switch_body(f, dict_of_lists, profile, profile_name, tab_char) - + for closer in reversed(closing): f.write(closer) @@ -624,7 +629,7 @@ def write_verify_func_body(f, profile, dict_name, availability): profile, dict_name), profile, profile.name, availability) if profile.parent_profiles is None: return - for pp in sorted(profile.parent_profiles, key=attrgetter("name")): + for pp in profile.parent_profiles: write_verify_func_body(f, pp, dict_name, availability.intersection(pp.availability())) @@ -832,7 +837,7 @@ def generate_bindings_c(file, b): f.write('{\n') f.write('\tswitch(input)\n') f.write('\t{\n') - for input in sorted(inputs): + for input in inputs: f.write(f'\tcase {input}: return "{input}";\n') f.write(f'\tdefault: return "UNKNOWN";\n') f.write('\t}\n') @@ -841,7 +846,7 @@ def generate_bindings_c(file, b): f.write('enum xrt_input_name\n') f.write('xrt_input_name_enum(const char *input)\n') f.write('{\n') - for input in sorted(inputs): + for input in inputs: f.write(f'\tif(strcmp("{input}", input) == 0) return {input};\n') f.write(f'\treturn XRT_INPUT_GENERIC_TRACKER_POSE;\n') f.write('}\n') @@ -851,7 +856,7 @@ def generate_bindings_c(file, b): f.write('{\n') f.write('\tswitch(output)\n') f.write('\t{\n') - for output in sorted(outputs): + for output in outputs: f.write(f'\tcase {output}: return "{output}";\n') f.write(f'\tdefault: return "UNKNOWN";\n') f.write('\t}\n') @@ -860,7 +865,7 @@ def generate_bindings_c(file, b): f.write('enum xrt_output_name\n') f.write('xrt_output_name_enum(const char *output)\n') f.write('{\n') - for output in sorted(outputs): + for output in outputs: f.write(f'\tif(strcmp("{output}", output) == 0) return {output};\n') f.write(f'\treturn XRT_OUTPUT_NAME_SIMPLE_VIBRATION;\n') f.write('}\n') diff --git a/src/xrt/auxiliary/bindings/steamvr_profiles.py b/src/xrt/auxiliary/bindings/steamvr_profiles.py index f54a303f9..abcbfabe6 100644 --- a/src/xrt/auxiliary/bindings/steamvr_profiles.py +++ b/src/xrt/auxiliary/bindings/steamvr_profiles.py @@ -114,7 +114,7 @@ def main(): # print("Creating SteamVR input profile", f.name) - json.dump(j, f, indent=2, sort_keys=True) + json.dump(j, f, indent=2) f.close() -- 2.48.0