changeset fbb19814adbc in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=fbb19814adbc
description:
        util: Auto generate the packet proto definitions

        This patch simplifies the usage of the packet trace encoder/decoder by
        attempting to automatically generating the packet proto definitions in
        case they cannot be found.

diffstat:

 util/decode_packet_trace.py |  18 +++++++++++++++++-
 util/encode_packet_trace.py |  18 +++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diffs (56 lines):

diff -r 177e8d8e50fc -r fbb19814adbc util/decode_packet_trace.py
--- a/util/decode_packet_trace.py       Thu May 30 12:53:53 2013 -0400
+++ b/util/decode_packet_trace.py       Thu May 30 12:53:53 2013 -0400
@@ -80,7 +80,23 @@
 
 import struct
 import sys
-import packet_pb2
+
+# Import the packet proto definitions. If they are not found, attempt
+# to generate them automatically. This assumes that the script is
+# executed from the gem5 root.
+try:
+    import packet_pb2
+except:
+    print "Did not find packet proto definitions, attempting to generate"
+    from subprocess import call
+    error = call(['protoc', '--python_out=util', '--proto_path=src/proto',
+                  'src/proto/packet.proto'])
+    if not error:
+        import packet_pb2
+        print "Generated packet proto definitions"
+    else:
+        print "Failed to import packet proto definitions"
+        exit(-1)
 
 def DecodeVarint(in_file):
     """
diff -r 177e8d8e50fc -r fbb19814adbc util/encode_packet_trace.py
--- a/util/encode_packet_trace.py       Thu May 30 12:53:53 2013 -0400
+++ b/util/encode_packet_trace.py       Thu May 30 12:53:53 2013 -0400
@@ -85,7 +85,23 @@
 
 import struct
 import sys
-import packet_pb2
+
+# Import the packet proto definitions. If they are not found, attempt
+# to generate them automatically. This assumes that the script is
+# executed from the gem5 root.
+try:
+    import packet_pb2
+except:
+    print "Did not find packet proto definitions, attempting to generate"
+    from subprocess import call
+    error = call(['protoc', '--python_out=util', '--proto_path=src/proto',
+                  'src/proto/packet.proto'])
+    if not error:
+        import packet_pb2
+        print "Generated packet proto definitions"
+    else:
+        print "Failed to import packet proto definitions"
+        exit(-1)
 
 def EncodeVarint(out_file, value):
   """
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to