Explorar el Código

DatatypeGenerator: Check for valid node id in csv

If there's a type definition in the .bsd file, but there is no corresponding
entry in the .csv, then the old code silently set the type id to NODEID_NULL.

This will then cause the server to fail on a later stage. To avoid this,
the datatype generator should check this immediately and inform the user.
Stefan Profanter hace 5 años
padre
commit
8c77bf35d5
Se han modificado 3 ficheros con 22 adiciones y 2 borrados
  1. 1 0
      CMakeLists.txt
  2. 8 1
      tools/cmake/macros_public.cmake
  3. 13 1
      tools/generate_datatypes.py

+ 1 - 0
CMakeLists.txt

@@ -761,6 +761,7 @@ ua_generate_datatypes(
 
 # transport data types
 ua_generate_datatypes(
+    INTERNAL
     NAME "ua_transport"
     TARGET_SUFFIX "transport"
     NAMESPACE_IDX 1

+ 8 - 1
tools/cmake/macros_public.cmake

@@ -79,6 +79,7 @@ endfunction()
 #   Options:
 #
 #   [BUILTIN]       Optional argument. If given, then builtin types will be generated.
+#   [INTERNAL]      Optional argument. If given, then the given types file is seen as internal file (e.g. does not require a .csv)
 #
 #   Arguments taking one value:
 #
@@ -100,7 +101,7 @@ endfunction()
 #
 #
 function(ua_generate_datatypes)
-    set(options BUILTIN)
+    set(options BUILTIN INTERNAL)
     set(oneValueArgs NAME TARGET_SUFFIX TARGET_PREFIX NAMESPACE_IDX OUTPUT_DIR FILE_CSV)
     set(multiValueArgs FILES_BSD FILES_SELECTED)
     cmake_parse_arguments(UA_GEN_DT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
@@ -143,6 +144,11 @@ function(ua_generate_datatypes)
         set(UA_GEN_DT_NO_BUILTIN "")
     endif()
 
+    set(UA_GEN_DT_INTERNAL_ARG "")
+    if (UA_GEN_DT_INTERNAL)
+        set(UA_GEN_DT_INTERNAL_ARG "--internal")
+    endif()
+
 
     set(SELECTED_TYPES_TMP "")
     foreach(f ${UA_GEN_DT_FILES_SELECTED})
@@ -170,6 +176,7 @@ function(ua_generate_datatypes)
         ${BSD_FILES_TMP}
         --type-csv=${UA_GEN_DT_FILE_CSV}
         ${UA_GEN_DT_NO_BUILTIN}
+        ${UA_GEN_DT_INTERNAL_ARG}
         ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}
         DEPENDS ${open62541_TOOLS_DIR}/generate_datatypes.py
         ${UA_GEN_DT_FILES_BSD}

+ 13 - 1
tools/generate_datatypes.py

@@ -36,6 +36,9 @@ builtin_types = ["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32
                  "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
                  "Variant", "DiagnosticInfo"]
 
+# If set to False, every defined datatype must have a corresponding ID entry in the csv file
+isInternalTypes = False
+
 # Some types can be memcpy'd off the binary stream. That's especially important
 # for arrays. But we need to check if they contain padding and whether the
 # endianness is correct. This dict gives the C-statement that must be true for the
@@ -129,7 +132,10 @@ class Type(object):
             # xmlEncodingId = description.xmlEncodingId
             binaryEncodingId = description.binaryEncodingId
         else:
-            typeid = "{0, UA_NODEIDTYPE_NUMERIC, {0}}"
+            if not isInternalTypes:
+                raise RuntimeError("NodeId for " + self.name + " not found in .csv file")
+            else:
+                typeid = "{0, UA_NODEIDTYPE_NUMERIC, {0}}"
         idName = makeCIdentifier(self.name)
         return "{\n    UA_TYPENAME(\"%s\") /* .typeName */\n" % idName + \
             "    " + typeid + ", /* .typeId */\n" + \
@@ -473,6 +479,11 @@ parser.add_argument('--opaque-map',
                     default=[],
                     help='JSON file with opaque type mapping: { \'typename\': { \'ns\': 0,  \'id\': 7, \'name\': \'UInt32\' }, ... }')
 
+parser.add_argument('--internal',
+                    action='store_true',
+                    dest="internal",
+                    help='Given bsd are internal types which do not have any .csv file')
+
 parser.add_argument('-t', '--type-bsd',
                     metavar="<typeBsds>",
                     type=argparse.FileType('r'),
@@ -489,6 +500,7 @@ args = parser.parse_args()
 outname = args.outfile.split("/")[-1]
 inname = ', '.join(list(map(lambda x:x.name.split("/")[-1], args.type_bsd)))
 
+isInternalTypes = args.internal
 
 ################
 # Create Types #