-
Notifications
You must be signed in to change notification settings - Fork 57
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
add const UID attribute to allow constant IDs #352
Changes from 3 commits
355e948
2b4555a
1bc798b
fc07c5c
f46dd0c
621cb54
d3cf40f
21edf40
78d5784
5d1b797
ad0b093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2024 Contributors to COVESA | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Mozilla Public License 2.0 which is available at | ||
# https://www.mozilla.org/en-US/MPL/2.0/ | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
A.B.Int32: | ||
datatype: int32 | ||
type: sensor | ||
constUID: '0x00112233' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2024 Contributors to COVESA | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Mozilla Public License 2.0 which is available at | ||
# https://www.mozilla.org/en-US/MPL/2.0/ | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
A.B.OverlayNode: | ||
datatype: int32 | ||
type: sensor | ||
description: This is the description of the overlay node. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ class VSSNode(Node): | |
"$file_name$", | ||
"fka", | ||
"delete", | ||
"constUID", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should discuss how integrated we want the id-attributes to be in vss-tools. By adding There are two alternatives, one is to consider them as extended attributes and give warning unless they are specified by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @erikbosch can you please discuss this during the public meeting today? I have been sick yesterday / today, but can finish this tomorrow if you decide on how you want it to work. I would appreciate it, thank you!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets keep this for now, just add some documentation, then I can do a quick look and if ok I merge |
||
] | ||
|
||
# List of accepted extended attributes. In strict terminate if an attribute is | ||
|
@@ -90,6 +91,7 @@ class VSSNode(Node): | |
deprecation = "" | ||
fka = "" | ||
delete: bool = False | ||
constUID: str | None = None | ||
|
||
def __deepcopy__(self, memo): | ||
# Deep copy of source_dict and children needed as overlay or programmatic changes | ||
|
@@ -252,7 +254,7 @@ def validate_name_style(self, sourcefile): | |
) | ||
) | ||
|
||
camel_regexp = re.compile('[A-Z][A-Za-z0-9]*$') | ||
camel_regexp = re.compile("[A-Z][A-Za-z0-9]*$") | ||
# relax camel case requirement for struct properties | ||
if not self.is_property() and not camel_regexp.match(self.name): | ||
raise NameStyleValidationException( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,16 +22,18 @@ | |
from vspec.model.constants import VSSTreeType | ||
from vspec.model.vsstree import VSSNode | ||
from vspec.utils import vss2id_val | ||
from vspec.utils.idgen_utils import (fnv1_32_hash, get_all_keys_values, | ||
get_node_identifier_bytes) | ||
from vspec.utils.idgen_utils import ( | ||
fnv1_32_hash, | ||
get_all_keys_values, | ||
get_node_identifier_bytes, | ||
) | ||
from vspec.vss2x import Vss2X | ||
from vspec.vspec2vss_config import Vspec2VssConfig | ||
|
||
|
||
def generate_split_id( | ||
node: VSSNode, id_counter: int, strict_mode: bool | ||
) -> Tuple[str, int]: | ||
|
||
"""Generates static UIDs using 4-byte FNV-1 hash. | ||
|
||
@param node: VSSNode that we want to generate a static UID for | ||
|
@@ -68,7 +70,15 @@ def export_node(yaml_dict, node, id_counter, strict_mode: bool) -> Tuple[int, in | |
@param strict_mode: strict mode means case sensitivity for static UID generation | ||
@return: id_counter, id_counter | ||
""" | ||
node_id, id_counter = generate_split_id(node, id_counter, strict_mode) | ||
|
||
if not node.constUID: | ||
node_id, id_counter = generate_split_id(node, id_counter, strict_mode) | ||
else: | ||
assert node.constUID.startswith( | ||
"0x" | ||
), f"constUID has to begin with '0x': {node.constUID}" | ||
assert len(node.constUID) == 10, f"Invalid constUID: {node.constUID}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am considering to move these two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a better way to solve this here f46dd0c |
||
node_id = node.constUID[2:] | ||
|
||
# check for hash duplicates | ||
for key, value in get_all_keys_values(yaml_dict): | ||
|
@@ -121,7 +131,10 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None: | |
@param parser: the pre-existing argument parser | ||
""" | ||
parser.add_argument( | ||
"--validate-static-uid", type=str, default="", help="Path to validation file." | ||
"--validate-static-uid", | ||
type=str, | ||
default="", | ||
help="Path to validation file.", | ||
) | ||
parser.add_argument( | ||
"--only-validate-no-export", | ||
|
@@ -135,9 +148,13 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None: | |
help="Strict mode means that the generation of static UIDs is case-sensitive.", | ||
) | ||
|
||
def generate(self, config: argparse.Namespace, signal_root: VSSNode, vspec2vss_config: Vspec2VssConfig, | ||
data_type_root: Optional[VSSNode] = None) -> None: | ||
|
||
def generate( | ||
self, | ||
config: argparse.Namespace, | ||
signal_root: VSSNode, | ||
vspec2vss_config: Vspec2VssConfig, | ||
data_type_root: Optional[VSSNode] = None, | ||
) -> None: | ||
"""Main export function used to generate the output id vspec. | ||
|
||
@param config: Command line arguments it was run with | ||
|
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.
To me it is not obvious why you have
"--only-validate-no-export"
here but not for the overlay alternative. Possibly add a comment.Updated:
Now I noticed that in one of the overlay tests we actually check output. I suggest that we remove
--only-validate-no-export
here as well so that the two variants behave in the same way, i.e. both generate files. Or have a separate option to control that.