fix(datatype-generator): Cleaning up the NAMESPACE_MAP setting to also inherit it if DEPENDS is used

This commit is contained in:
Stefan Profanter 2020-10-02 14:26:01 +02:00 committed by Stefan Profanter
parent 8103c27992
commit 08acd2d0ab
5 changed files with 26 additions and 17 deletions

View File

@ -407,6 +407,7 @@ This DI nodeset makes use of some additional data types in ``deps/ua-nodeset/DI/
The ``NAMESPACE_MAP`` parameter is an array of strings which indicates the mapping of specific namespace uris to the resulting namespace index.
This mapping is required for correct mapping of DataType nodes and their node ids. Currently we need to rely that the namespace is also added at this position in the final server. There is no automatic inferring yet (pull requests are warmly welcome).
If you are using the `DEPENDS` option on the ``ua_generate_nodeset_and_datatypes``, the ``NAMESPACE_MAP`` is also inherited and you do not need to pass all mappings for dependent types.
The CSV and BSD files contain the metadata and definition for the types. ``TARGET_SUFFIX`` is used to create a new target with the name ``open62541-generator-TARGET_SUFFIX``.
Now you can compile the DI nodeset XML using the following command::

View File

@ -104,19 +104,13 @@ if(UA_NAMESPACE_ZERO STREQUAL "FULL")
${UA_TYPES_PLC_SOURCES})
add_dependencies(server_nodeset_plcopen open62541-generator-ns-plc)
endif()
# POWERLINK requires the full ns0 as basis
if(UA_NAMESPACE_ZERO STREQUAL "FULL")
# POWERLINK requires the full ns0 as basis
# generate powerlink namespace which is using DI
ua_generate_nodeset_and_datatypes(
NAME "powerlink"
FILE_CSV "${FILE_CSV_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeIds.csv"
FILE_BSD "${FILE_BSD_POWERLINK_DIRPREFIX}/Opc.Ua.POWERLINK.NodeSet2.bsd"
NAMESPACE_MAP "2:http://opcfoundation.org/UA/DI/" "3:http://opcfoundation.org/UA/POWERLINK/"
NAMESPACE_MAP "3:http://opcfoundation.org/UA/POWERLINK/"
FILE_NS "${FILE_NS_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeSet2.xml"
# POWERLINK depends on the di nodeset, which must be generated before
DEPENDS "di"

View File

@ -24,7 +24,7 @@ if(UA_NAMESPACE_ZERO STREQUAL "FULL")
NAME "tests-adi"
FILE_CSV "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/ADI/OpcUaAdiModel.csv"
FILE_BSD "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/ADI/Opc.Ua.Adi.Types.bsd"
NAMESPACE_MAP "2:http://opcfoundation.org/UA/DI/" "3:http://opcfoundation.org/UA/ADI/"
NAMESPACE_MAP "3:http://opcfoundation.org/UA/ADI/"
OUTPUT_DIR "${GENERATE_OUTPUT_DIR}"
FILE_NS "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/ADI/Opc.Ua.Adi.NodeSet2.xml"
DEPENDS "tests-di"
@ -67,7 +67,7 @@ if(UA_NAMESPACE_ZERO STREQUAL "FULL")
NAME "tests-autoid"
FILE_CSV "${PROJECT_SOURCE_DIR}/tests/nodeset-compiler/Opc.Ua.AutoID.NodeIds.csv"
FILE_BSD "${PROJECT_SOURCE_DIR}/tests/nodeset-compiler/Opc.Ua.AutoID.Types.bsd"
NAMESPACE_MAP "2:http://opcfoundation.org/UA/DI/" "3:http://opcfoundation.org/UA/AutoID/"
NAMESPACE_MAP "3:http://opcfoundation.org/UA/AutoID/"
OUTPUT_DIR "${GENERATE_OUTPUT_DIR}"
FILE_NS "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/AutoID/Opc.Ua.AutoID.NodeSet2.xml"
DEPENDS "tests-di"

View File

@ -501,12 +501,32 @@ function(ua_generate_nodeset_and_datatypes)
set(NODESET_TYPES_ARRAY "UA_TYPES")
if(NOT "${UA_GEN_FILE_BSD}" STREQUAL "")
set(NAMESPACE_MAP_DEPENDS "${UA_GEN_NAMESPACE_MAP}")
string(REPLACE "-" "_" GEN_NAME_UPPER ${GEN_NAME_UPPER})
string(TOUPPER "${GEN_NAME_UPPER}" GEN_NAME_UPPER)
# Create a list of namespace maps for dependent calls
if (UA_GEN_DEPENDS AND NOT "${UA_GEN_DEPENDS}" STREQUAL "" )
foreach(f ${UA_GEN_DEPENDS})
string(REPLACE "-" "_" DEPENDS_NAME "${f}")
string(TOUPPER "${DEPENDS_NAME}" DEPENDS_NAME)
get_property(DEPENDS_NAMESPACE_MAP GLOBAL PROPERTY "UA_GEN_DT_DEPENDS_NAMESPACE_MAP_${DEPENDS_NAME}")
if(NOT DEPENDS_NAMESPACE_MAP OR "${DEPENDS_NAMESPACE_MAP}" STREQUAL "")
message(FATAL_ERROR "Nodeset dependency ${f} needs to be generated before ${UA_GEN_NAME}")
endif()
set(NAMESPACE_MAP_DEPENDS ${NAMESPACE_MAP_DEPENDS} "${DEPENDS_NAMESPACE_MAP}")
endforeach()
endif()
set_property(GLOBAL PROPERTY "UA_GEN_DT_DEPENDS_NAMESPACE_MAP_${GEN_NAME_UPPER}" ${NAMESPACE_MAP_DEPENDS})
# Generate Datatypes for nodeset
ua_generate_datatypes(
NAME "types_${UA_GEN_NAME}"
TARGET_PREFIX "${UA_GEN_TARGET_PREFIX}"
TARGET_SUFFIX "types-${UA_GEN_NAME}"
NAMESPACE_MAP "${UA_GEN_NAMESPACE_MAP}"
NAMESPACE_MAP "${NAMESPACE_MAP_DEPENDS}"
FILE_CSV "${UA_GEN_FILE_CSV}"
FILES_BSD "${UA_GEN_FILE_BSD}"
IMPORT_BSD "${UA_GEN_IMPORT_BSD}"

View File

@ -22,12 +22,6 @@ parser.add_argument('-c', '--type-csv',
default=[],
help='csv file with type descriptions')
parser.add_argument('--namespaceUri',
type=str,
dest="namespaceUri",
default="http://opcfoundation.org/UA/",
help='namespace uri of the generated type nodeids (defaults to "http://opcfoundation.org/UA/")')
parser.add_argument('--namespaceMap',
metavar="<namespaceMap>",
type=str,