Skip to content

Commit

Permalink
Merge branch 'development/stubgen-omit-supresses-warning' of github.c…
Browse files Browse the repository at this point in the history
…om:rdkcentral/ThunderTools into development/stubgen-omit-supresses-warning
  • Loading branch information
sebaszm committed Jan 15, 2024
2 parents 23c745a + fc338e6 commit 763c098
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 68 deletions.
6 changes: 3 additions & 3 deletions JsonGenerator/JsonGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if __name__ == "__main__":
argparser, args = config.Parse(sys.argv)

log = logger.Create(NAME, args.verbose, not args.no_duplicates_warnings, not args.no_style_warnings)
log = logger.Create(NAME, args.verbose, not args.no_warnings, not args.no_style_warnings)
trackers.SetLogger(log)
json_loader.SetLogger(log)

Expand All @@ -59,8 +59,6 @@
else:
files.append(p)

joint_headers = {}

for path in files:

trackers.object_tracker.Reset()
Expand All @@ -71,6 +69,8 @@

schemas, additional_includes, temp_files = json_loader.Load(log, path, args.if_dir, args.cppif_dir, args.includePaths)

joint_headers = {}

for schema in schemas:
if schema:
warnings = config.GENERATED_JSON
Expand Down
4 changes: 2 additions & 2 deletions JsonGenerator/source/class_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _EmitEnum(enum):
log.Info("Emitting enum {}".format(enum.cpp_class))

if enum.description:
emit.Line("// " + enum.description)
emit.Line("// " + enum.description.split("\n",1)[0])

emit.Line("enum%s %s : uint%i_t {" % (" class" if enum.is_scoped else "", enum.cpp_class, enum.size))
emit.Indent()
Expand Down Expand Up @@ -314,7 +314,7 @@ def _EmitValidator(json_obj):
emit.Indent()

for prop in json_obj.properties:
comment = prop.print_name if isinstance(prop, JsonMethod) else prop.description
comment = prop.print_name if isinstance(prop, JsonMethod) else prop.description.split("\n",1)[0] if prop.description else ""
emit.Line("%s %s;%s" % (prop.short_cpp_type, prop.cpp_name, (" // " + comment) if comment else ""))

if IsObjectRestricted(json_obj):
Expand Down
17 changes: 11 additions & 6 deletions JsonGenerator/source/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# Configurables
CLASSNAME_FROM_REF = True
DEFAULT_INT_SIZE = 32
SHOW_WARNINGS = True
DOC_ISSUES = True
DEFAULT_DEFINITIONS_FILE = "../../ProxyStubGenerator/default.h"
FRAMEWORK_NAMESPACE = "WPEFramework"
Expand Down Expand Up @@ -136,6 +135,12 @@ def Parse(cmdline):
action="store_true",
default=False,
help= "force code generation even if destination appears up-to-date (default: force disabled)")
argparser.add_argument(
"--no-warnings",
dest="no_warnings",
action="store_true",
default=False,
help= "disable all warnings (default: warnings enabled)")

json_group = argparser.add_argument_group("JSON parser arguments (optional)")
json_group.add_argument("-i",
Expand All @@ -151,11 +156,11 @@ def Parse(cmdline):
action="store_true",
default=False,
help="do not derive class names from $refs (default: derive class names from $ref)")
json_group.add_argument("--no-duplicates-warnings",
dest="no_duplicates_warnings",
json_group.add_argument("--duplicate-obj-warnings",
dest="duplicate_obj_warnings",
action="store_true",
default=not SHOW_WARNINGS,
help="suppress duplicate object warnings (default: show all duplicate object warnings)")
default=False,
help="enable duplicate object warnings (default: do not show duplicate object warnings)")

cpp_group = argparser.add_argument_group("C++ parser arguments (optional)")
cpp_group.add_argument("-j",
Expand Down Expand Up @@ -298,7 +303,7 @@ def Parse(cmdline):
args = argparser.parse_args(cmdline[1:])

DOC_ISSUES = not args.no_style_warnings
NO_DUP_WARNINGS = args.no_duplicates_warnings
NO_DUP_WARNINGS = not args.duplicate_obj_warnings
INDENT_SIZE = args.indent_size
ALWAYS_EMIT_COPY_CTOR = args.copy_ctor
KEEP_EMPTY = args.keep_empty
Expand Down
43 changes: 23 additions & 20 deletions JsonGenerator/source/documentation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def ExampleObj(name, obj, root=False):
if obj_type == "string":
json_data += "{ }" if obj.get("opaque") else ('"%s"' % (default if default else "..."))
elif obj_type == "integer":
if default and not str(default).isnumeric():
if default and not str(default).lstrip('-+').isnumeric():
raise DocumentationError("'%s': invalid example syntax for this integer type (see '%s')" % (name, default))

json_data += '%s' % (default if default else 0)
elif obj_type == "number":
if default and not str(default).replace('.','').isnumeric():
if default and not str(default).replace('.','').lstrip('-+').isnumeric():
raise DocumentationError("'%s': invalid example syntax for this numeric (floating-point) type (see '%s')" % (name, default))

if default and '.' not in str(default):
Expand Down Expand Up @@ -384,23 +384,25 @@ def MethodDump(method, props, classname, section, header, is_notification=False,
if is_notification:
method = "client.events.1." + method
elif is_property:
method = "%s.1.%s%s" % (classname, method, ("@" + props["index"]["example"]) if "index" in props and "example" in props["index"] else "")
method = "%s.1.%s%s" % (classname, method, ("@" + str(props["index"]["example"])) if "index" in props and "example" in props["index"] else "")
else:
method = "%s.1.%s" % (classname, method)

if "id" in props and "example" in props["id"]:
method = props["id"]["example"] + "." + method

jsonError = "Failed to generate JSON example"
jsonError = "Failed to generate JSON example for %s" % method
jsonResponse = jsonError
jsonRequest = jsonError

if is_property:
if not writeonly:
MdHeader("Get Request", 4)

text = '{ "jsonrpc": "2.0", "id": 42, "method": "%s" }' % method

try:
jsonRequest = json.dumps(json.loads('{ "jsonrpc": "2.0", "id": 42, "method": "%s" }' % method,
object_pairs_hook=OrderedDict), indent=2)
jsonRequest = json.dumps(json.loads(text, object_pairs_hook=OrderedDict), indent=2)
except:
jsonRequest = jsonError
log.Error(jsonError)
Expand All @@ -409,11 +411,12 @@ def MethodDump(method, props, classname, section, header, is_notification=False,
MdHeader("Get Response", 4)

parameters = (props["result"] if "result" in props else (props["params"] if "params" in props else None))
text = '{ "jsonrpc": "2.0", "id": 42, %s }' % ExampleObj("result", parameters, True)

try:
jsonResponse = json.dumps(json.loads('{ "jsonrpc": "2.0", "id": 42, %s }' % ExampleObj("result", parameters, True),
object_pairs_hook=OrderedDict), indent=2)
jsonResponse = json.dumps(json.loads(text, object_pairs_hook=OrderedDict), indent=2)
except:
jsonResponse = jsonError
jsonResponse = jsonError
log.Error(jsonError)

MdCode(jsonResponse, "json")
Expand All @@ -437,18 +440,18 @@ def MethodDump(method, props, classname, section, header, is_notification=False,
MdCode(jsonRequest, "json")

if not is_notification and not is_property:
if "result" in props:
MdHeader("Response", 4)
try:
jsonResponse = json.dumps(json.loads('{ "jsonrpc": "2.0", "id": 42, %s }' % ExampleObj("result", props["result"], True),
object_pairs_hook=OrderedDict), indent=2)
except:
jsonResponse = jsonError
log.Error(jsonError)
if "result" not in props:
props["result"] = { "type": "null" }

MdCode(jsonResponse, "json")
elif "noresult" not in props or not props["noresult"]:
raise DocumentationError("'%s': missing 'result' in this method" % method)
MdHeader("Response", 4)
try:
jsonResponse = json.dumps(json.loads('{ "jsonrpc": "2.0", "id": 42, %s }' % ExampleObj("result", props["result"], True),
object_pairs_hook=OrderedDict), indent=2)
except:
jsonResponse = jsonError
log.Error(jsonError)

MdCode(jsonResponse, "json")

if is_property:
MdHeader("Set Response", 4)
Expand Down
3 changes: 3 additions & 0 deletions JsonGenerator/source/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __exit__(self, exc_type, exc_value, traceback):
self.file.close()

def Line(self, text = ""):
if "\n" in text:
assert("Invalid characters in the emitted line")

if text != "":
commented = "// " if "//" in text else ""
text = (" " * self.indent) + str(text)
Expand Down
21 changes: 17 additions & 4 deletions JsonGenerator/source/header_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def GenerateObject(ctype, was_typdef):
properties[name] = props
properties[name]["type"] = "object"
properties[name]["original_type"] = StripFrameworkNamespace(p.type.Type().full_name)

if p.meta.brief:
properties[name]["description"] = p.meta.brief
else:
properties[name] = ConvertParameter(p)

Expand Down Expand Up @@ -658,7 +661,7 @@ def BuildResult(vars, is_property=False):
obj["summary"] = method.retval.meta.brief.strip()

if method.retval.meta.details:
obj["description"] = method.retval.meta.details
obj["description"] = method.retval.meta.details.strip()

if method.retval.meta.retval:
errors = []
Expand All @@ -679,6 +682,12 @@ def BuildResult(vars, is_property=False):
idx = prefix + method.retval.meta.alt
obj["alt"] = idx

if method.retval.meta.alt_is_deprecated:
obj["altisdeprecated"] = method.retval.meta.alt_is_deprecated

if method.retval.meta.alt_is_obsolete:
obj["altisobsolete"] = method.retval.meta.alt_is_obsolete

if config.LEGACY_ALT:
idx = prefix + method.retval.meta.alt
upd[idx] = copy.deepcopy(obj)
Expand Down Expand Up @@ -759,7 +768,7 @@ def BuildResult(vars, is_property=False):
obj["summary"] = method.retval.meta.brief.strip()

if method.retval.meta.details:
obj["description"] = method.retval.meta.details
obj["description"] = method.retval.meta.details.strip()

if params:
obj["params"] = params
Expand All @@ -776,8 +785,12 @@ def BuildResult(vars, is_property=False):

if method.retval.meta.alt:
obj["alt"] = method.retval.meta.alt
obj["altisdeprecated"] = method.retval.meta.alt_is_deprecated
obj["altisobsolete"] = method.retval.meta.alt_is_obsolete

if method.retval.meta.alt_is_deprecated:
obj["altisdeprecated"] = method.retval.meta.alt_is_deprecated

if method.retval.meta.alt_is_obsolete:
obj["altisobsolete"] = method.retval.meta.alt_is_obsolete

events[prefix + method_name] = obj

Expand Down
Loading

0 comments on commit 763c098

Please sign in to comment.