Browse Source

new feature: cmake can now be configure with "TYPES_ONLY_NEEDED" resulting in the lowest possible number of types
relates to #103 #101

Stasik0 9 years ago
parent
commit
7aeccac7ac
6 changed files with 62 additions and 12 deletions
  1. 8 0
      .travis.yml
  2. 13 4
      CMakeLists.txt
  3. 1 1
      schema/Opc.Ua.Types.bsd
  4. 9 7
      tools/generate_builtin.py
  5. 6 0
      tools/generate_namespace.py
  6. 25 0
      tools/type_lists.py

+ 8 - 0
.travis.yml

@@ -27,6 +27,13 @@ before_install:
    - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
    - sudo update-alternatives --config gcc
 script: 
+   - mkdir -p build
+   - cd build
+   - echo "Only needed profile"
+   - cmake -DTYPES_ONLY_NEEDED ..
+   - make
+   - cd ..
+   - rm build -rf
    - mkdir -p build
    - cd build
    - cmake -DGENERATE_DOCUMENTATION=ON .. 
@@ -38,6 +45,7 @@ script:
    - make clean
    - cmake -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTS=ON -DENABLE_COVERAGE=ON .. 
    - make && make test
+
 after_success:
    - git clone --depth=50 -b gh-pages https://$GITAUTH@github.com/acplt/open62541
    - rm -rf open62541/doxygen

+ 13 - 4
CMakeLists.txt

@@ -47,11 +47,14 @@ if(UA_ENCODING_JSON)
     MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
 endif(UA_ENCODING_JSON)
 
+#included types
+set(TYPES_ONLY_NEEDED OFF CACHE BOOL "Inlcude only compile-needed types")
+
 # coverage
 option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
 if(ENABLE_COVERAGE)
     message(STATUS "Enabling gcov support")
-	set(CMAKE_BUILD_TYPE DEBUG)
+    set(CMAKE_BUILD_TYPE DEBUG)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
@@ -92,14 +95,14 @@ set(lib_sources src/ua_types.c
                 src/server/ua_channel_manager.c
                 src/server/ua_session_manager.c
                 src/server/ua_transport_connection_manager.c
-				src/server/ua_server.c
+		src/server/ua_server.c
                 src/server/ua_application.c
                 src/util/ua_util.c
                 src/util/ua_list.c
                 src/util/ua_indexedList.c
                 src/util/ua_base64.c
-				${headers}
-				${generated_headers})
+		${headers}
+		${generated_headers})
 
 if(MULTITHREADING)
     list(APPEND lib_sources src/server/ua_namespace_concurrent.c)
@@ -109,6 +112,12 @@ endif(MULTITHREADING)
 
 set(generate_src_options "")
 
+#types
+if(TYPES_ONLY_NEEDED)
+    set(generate_src_options "${generate_src_options}--only-needed")
+endif(TYPES_ONLY_NEEDED)
+
+
 if(UA_ENCODING_XML)
     list(APPEND lib_sources src/ua_types_encoding_xml.c
                             src/server/ua_namespace_xml.c

+ 1 - 1
schema/Opc.Ua.Types.bsd

@@ -2391,4 +2391,4 @@
     <opc:EnumeratedValue Name="Unknown" Value="4" />
   </opc:EnumeratedType>
 
-</opc:TypeDictionary>
+</opc:TypeDictionary>

+ 9 - 7
tools/generate_builtin.py

@@ -13,6 +13,7 @@ parser = argparse.ArgumentParser()
 parser.add_argument('--with-xml', action='store_true', help='generate xml encoding')
 parser.add_argument('--with-json', action='store_true', help='generate json encoding')
 parser.add_argument('--only-nano', action='store_true', help='generate only the types for the nano profile')
+parser.add_argument('--only-needed', action='store_true', help='generate only types needed for compile')
 parser.add_argument('types', help='path/to/Opc.Ua.Types.bsd')
 parser.add_argument('outfile', help='outfile w/o extension')
 args = parser.parse_args()
@@ -32,12 +33,12 @@ def printh(string):
 def printc(string):
     print(string % inspect.currentframe().f_back.f_locals, end='\n', file=fc)
 
+
 # types that are coded manually 
-existing_types = set(["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32",
-                      "Int64", "UInt64", "Float", "Double", "String", "DateTime", "Guid",
-                      "ByteString", "XmlElement", "NodeId", "ExpandedNodeId", "StatusCode", 
-                      "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
-                      "Variant", "DiagnosticInfo"])
+from type_lists import existing_types
+
+# whitelist for "only needed" profile
+from type_lists import only_needed_types
 
 # some types are omitted (pretend they exist already)
 existing_types.add("NodeIdType")
@@ -50,12 +51,14 @@ fixed_size = set(["UA_Boolean", "UA_SByte", "UA_Byte", "UA_Int16", "UA_UInt16",
 def skipType(name):
     if name in existing_types:
         return True
-    if "Test" in name:
+    if "Test" in name: #skip all Test types
         return True
     if re.search("Attributes$", name) != None:
         return True
     if re.search("NodeId$", name) != None:
         return True
+    if args.only_needed and not(name in only_needed_types):
+        return True
     return False
     
 def stripTypename(tn):
@@ -334,7 +337,6 @@ for element in types:
 	name = element.get("Name")
 	if skipType(name):
 		continue
-		
 	if element.tag == "{http://opcfoundation.org/BinarySchema/}EnumeratedType":
 		createEnumerated(element)
 		existing_types.add(name)

+ 6 - 0
tools/generate_namespace.py

@@ -10,10 +10,14 @@ import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument('--with-xml', action='store_true', help='generate xml encoding')
 parser.add_argument('--with-json', action='store_true', help='generate json encoding')
+parser.add_argument('--only-needed', action='store_true', help='generate only types needed for compile')
 parser.add_argument('nodeids', help='path/to/NodeIds.csv')
 parser.add_argument('outfile', help='outfile w/o extension')
 args = parser.parse_args()
 
+# whitelist for "only needed" profile
+from type_lists import only_needed_types
+
 # types that are to be excluded
 exclude_kinds = set(["Object","ObjectType","Variable","Method","ReferenceType"])
 exclude_types = set(["Number", "Integer", "UInteger", "Enumeration", "Image", "ImageBMP",
@@ -63,6 +67,8 @@ def skipType(row):
         return True
     if re.search("Attributes$", row[0]) != None:
         return True
+    if args.only_needed and not(row[0] in only_needed_types):
+        return True
     return False
 
 f = open(args.nodeids)

+ 25 - 0
tools/type_lists.py

@@ -0,0 +1,25 @@
+existing_types = set(["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32",
+                      "Int64", "UInt64", "Float", "Double", "String", "DateTime", "Guid",
+                      "ByteString", "XmlElement", "NodeId", "ExpandedNodeId", "StatusCode", 
+                      "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
+                      "Variant", "DiagnosticInfo"])
+                      
+only_needed_types = set([	"InvalidType", "Node", "NodeClass", "ReferenceNode", "ApplicationDescription", "ApplicationType",
+							"ChannelSecurityToken", "OpenSecureChannelRequest", "OpenSecureChannelResponse", 
+							"CloseSecureChannelRequest", "CloseSecureChannelResponse", "RequestHeader", "ResponseHeader",
+							"SecurityTokenRequestType", "MessageSecurityMode", "CloseSessionResponse", "CloseSessionRquest",
+							"ActivateSessionRequest", "ActivateSessionResponse", "SignatureData", "SignedSoftwareCertificate",
+							"CreateSessionResponse", "CreateSessionRequest", "EndpointDescription", "UserTokenPolicy", "UserTokenType",
+							"GetEndpointsRequest", "GetEndpointsResponse", "PublishRequest", "PublishResponse", "SetPublishingModeResponse",
+							"SubscriptionAcknowledgement", "NotificationMessage", "ExtensionObject", "Structure",
+							"ReadRequest", "ReadResponse", "ReadValueId", "TimestampsToReturn", "WriteRequest", "WriteResponse",
+							"WriteValue", "SetPublishingModeRequest", "CreateMonitoredItemsResponse", "MonitoredItemCreateResult",
+							"CreateMonitoredItemsRequest", "MonitoredItemCreateRequest", "MonitoringMode", "MonitoringParameters",
+							"TranslateBrowsePathsToNodeIdsRequest", "TranslateBrowsePathsToNodeIdsResponse", "BrowsePath", "BrowsePathResult",
+							"RelativePath", "BrowsePathTarget", "RelativePathElement", "CreateSubscriptionRequest", "CreateSubscriptionResponse",
+							"BrowseResponse", "BrowseResult", "ReferenceDescription", "BrowseRequest", "ViewDescription", "BrowseDescription",
+							"BrowseDirection", "CloseSessionRequest", "AddNodesRequest", "AddNodesResponse", "AddNodesItem", "AddNodesResult",
+							"AddReferencesRequest", "AddReferencesResponse", "AddReferencesItem", "VariableNode", "MethodNode", "VariableTypeNode",
+							"ViewNode", "ReferenceTypeNode", "BrowseResultMask", "ServerState", "ServerStatusDataType", "BuildInfo", "ObjectNode",
+							"DataTypeNode", "ObjectTypeNode", "IdType" ])
+only_needed_types = only_needed_types.union(existing_types)