fix test_cmake_as_package fail

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
diff --git a/scripts/generate_ssl_debug_helpers.py b/scripts/generate_ssl_debug_helpers.py
index 711bfd3..ad1f949 100755
--- a/scripts/generate_ssl_debug_helpers.py
+++ b/scripts/generate_ssl_debug_helpers.py
@@ -25,8 +25,10 @@
 import re
 import os
 import textwrap
+import argparse
 from mbedtls_dev import build_tree
 
+
 def remove_c_comments(string):
     """
         Remove C style comments from input string
@@ -34,16 +36,19 @@
     string_pattern = r"(?P<string>\".*?\"|\'.*?\')"
     comment_pattern = r"(?P<comment>/\*.*?\*/|//[^\r\n]*$)"
     pattern = re.compile(string_pattern + r'|' + comment_pattern,
-                         re.MULTILINE|re.DOTALL)
+                         re.MULTILINE | re.DOTALL)
+
     def replacer(match):
         if match.lastgroup == 'comment':
             return ""
         return match.group()
     return pattern.sub(replacer, string)
 
+
 class CondDirectiveNotMatch(Exception):
     pass
 
+
 def preprocess_c_source_code(source, *classes):
     """
         Simple preprocessor for C source code.
@@ -124,7 +129,6 @@
     assert not stack, len(stack)
 
 
-
 class EnumDefinition:
     """
         Generate helper functions around enumeration.
@@ -153,7 +157,7 @@
         enum_pattern = re.compile(r'enum\s*(?P<prefix_name>\w*)\s*' +
                                   r'{\s*(?P<body>[^}]*)}' +
                                   r'\s*(?P<suffix_name>\w*)\s*;',
-                                  re.MULTILINE|re.DOTALL)
+                                  re.MULTILINE | re.DOTALL)
 
         for match in enum_pattern.finditer(source_code, start, end):
             yield EnumDefinition(source_code,
@@ -233,6 +237,7 @@
                                      prototype=self._prototype)
         return body, prototype
 
+
 OUTPUT_C_TEMPLATE = '''\
 /* Automatically generated by generate_ssl_debug_helpers.py. DO NOT EDIT. */
 
@@ -272,11 +277,11 @@
 '''
 
 
-def generate_ssl_debug_helpers(target_dir):
+def generate_ssl_debug_helpers(output_directory, mbedtls_root):
     """
         Generate functions of debug helps
     """
-    with open('include/mbedtls/ssl.h') as f:
+    with open(os.path.join(mbedtls_root, 'include/mbedtls/ssl.h')) as f:
         source_code = remove_c_comments(f.read())
 
     definitions = dict()
@@ -292,19 +297,38 @@
         definitions[start] = definition
         prototypes[start] = prototype
 
-    functions = [str(v) for _, v in sorted(definitions.items())]
-    with open(os.path.join(target_dir, 'ssl_debug_helpers_generated.c'), 'w') as f:
-        f.write(OUTPUT_C_TEMPLATE.format(functions='\n'.join(functions)))
+    function_definitions = [str(v) for _, v in sorted(definitions.items())]
+    function_prototypes = [str(v) for _, v in sorted(prototypes.items())]
+    if output_directory == sys.stdout:
+        sys.stdout.write(OUTPUT_H_TEMPLATE.format(
+            functions='\n'.join(function_prototypes)))
+        sys.stdout.write(OUTPUT_C_TEMPLATE.format(
+            functions='\n'.join(function_definitions)))
+    else:
+        with open(os.path.join(output_directory, 'ssl_debug_helpers_generated.c'), 'w') as f:
+            f.write(OUTPUT_C_TEMPLATE.format(
+                functions='\n'.join(function_definitions)))
 
-    functions = [str(v) for _, v in sorted(prototypes.items())]
-    with open(os.path.join(target_dir, 'ssl_debug_helpers_generated.h'), 'w') as f:
-        f.write(OUTPUT_H_TEMPLATE.format(functions='\n'.join(functions)))
+        with open(os.path.join(output_directory, 'ssl_debug_helpers_generated.h'), 'w') as f:
+            f.write(OUTPUT_H_TEMPLATE.format(
+                functions='\n'.join(function_prototypes)))
 
 
+def main():
+    """
+    Command line entry
+    """
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--mbedtls-root', nargs='?', default=build_tree.guess_mbedtls_root(),
+                        help='root directory of mbedtls source code')
+    parser.add_argument('output_directory', nargs='?',
+                        default=sys.stdout, help='source/header files location')
 
+    args = parser.parse_args()
+
+    generate_ssl_debug_helpers(args.output_directory, args.mbedtls_root)
+    return 0
 
 
 if __name__ == '__main__':
-    build_tree.chdir_to_root()
-    OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "library"
-    generate_ssl_debug_helpers(OUTPUT_FILE_DIR)
+    sys.exit(main())