aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-11-20 23:10:09 -0500
committerOle Tr�an <otroan@employees.org>2020-11-21 15:44:56 +0000
commit9046e44c8493354d51237a92706a830a9db1872e (patch)
tree9721bb94740a4fdb46cb35753d043747a0bff8ab /src
parent79b3f8ce33849fd789c8fc31b219373749ad9678 (diff)
vppapigen: move import processing logic to individual plugins
Vppapigen currently embeds the import following control logic in the runner. This change delegates the control to the plugins. Type: refactor Change-Id: Iad20341bc9d652bedb71ca7037d3957fe60c7a0d Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py80
-rw-r--r--src/tools/vppapigen/vppapigen_c.py2
-rw-r--r--src/tools/vppapigen/vppapigen_crc.py3
-rw-r--r--src/tools/vppapigen/vppapigen_json.py2
4 files changed, 50 insertions, 37 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index 5219bfd9ece..b828706f814 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -1401,43 +1401,6 @@ def main():
else:
logging.basicConfig()
- parser = VPPAPI(debug=args.debug, filename=filename, logger=log,
- revision=args.git_revision)
-
- try:
- if not args.input:
- parsed_objects = parser.parse_fd(sys.stdin, log)
- else:
- parsed_objects = parser.parse_filename(args.input, log)
- except ParseError as e:
- print('Parse error: ', e, file=sys.stderr)
- sys.exit(1)
-
- # Build a list of objects. Hash of lists.
- result = []
-
- if args.output_module == 'C':
- s = parser.process(parsed_objects)
- else:
- result = parser.process_imports(parsed_objects, False, result)
- s = parser.process(result)
-
- # Add msg_id field
- s['Define'] = add_msg_id(s['Define'])
-
- # Fold up CRCs
- foldup_crcs(s['Define'])
-
- #
- # Debug
- if args.debug:
- import pprint
- pp = pprint.PrettyPrinter(indent=4, stream=sys.stderr)
- for t in s['Define']:
- pp.pprint([t.name, t.flags, t.block])
- for t in s['types']:
- pp.pprint([t.name, t.block])
-
#
# Generate representation
#
@@ -1472,6 +1435,49 @@ def main():
.format(module_path, err))
return 1
+ parser = VPPAPI(debug=args.debug, filename=filename, logger=log,
+ revision=args.git_revision)
+
+ try:
+ if not args.input:
+ parsed_objects = parser.parse_fd(sys.stdin, log)
+ else:
+ parsed_objects = parser.parse_filename(args.input, log)
+ except ParseError as e:
+ print('Parse error: ', e, file=sys.stderr)
+ sys.exit(1)
+
+ # Build a list of objects. Hash of lists.
+ result = []
+
+ # if the variable is not set in the plugin, assume it to be false.
+ try:
+ plugin.process_imports
+ except AttributeError:
+ plugin.process_imports = False
+
+ if plugin.process_imports:
+ result = parser.process_imports(parsed_objects, False, result)
+ s = parser.process(result)
+ else:
+ s = parser.process(parsed_objects)
+
+ # Add msg_id field
+ s['Define'] = add_msg_id(s['Define'])
+
+ # Fold up CRCs
+ foldup_crcs(s['Define'])
+
+ #
+ # Debug
+ if args.debug:
+ import pprint
+ pp = pprint.PrettyPrinter(indent=4, stream=sys.stderr)
+ for t in s['Define']:
+ pp.pprint([t.name, t.flags, t.block])
+ for t in s['types']:
+ pp.pprint([t.name, t.block])
+
result = plugin.run(args, filename, s)
if result:
print(result, file=args.output)
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py
index 07975ce23b4..a8790744054 100644
--- a/src/tools/vppapigen/vppapigen_c.py
+++ b/src/tools/vppapigen/vppapigen_c.py
@@ -6,6 +6,8 @@ import sys
from io import StringIO
import shutil
+process_imports = False
+
datestring = datetime.datetime.utcfromtimestamp(
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
input_filename = 'inputfil'
diff --git a/src/tools/vppapigen/vppapigen_crc.py b/src/tools/vppapigen/vppapigen_crc.py
index b3cb5855c9d..6947f12d467 100644
--- a/src/tools/vppapigen/vppapigen_crc.py
+++ b/src/tools/vppapigen/vppapigen_crc.py
@@ -1,6 +1,9 @@
# CRC generation
import json
+process_imports = True
+
+
#
# Plugin entry point
#
diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py
index f41bfb08c58..19f7d65b8c5 100644
--- a/src/tools/vppapigen/vppapigen_json.py
+++ b/src/tools/vppapigen/vppapigen_json.py
@@ -1,6 +1,8 @@
# JSON generation
import json
+process_imports = True
+
def walk_imports(s):
r = []