util: Auto generate the packet proto definitions
authorAndreas Hansson <andreas.hansson@arm.com>
Thu, 30 May 2013 16:53:53 +0000 (12:53 -0400)
committerAndreas Hansson <andreas.hansson@arm.com>
Thu, 30 May 2013 16:53:53 +0000 (12:53 -0400)
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.

util/decode_packet_trace.py
util/encode_packet_trace.py

index 9ee877e39d9017c94fc6e90d0ca480280bd83f96..fa0ea9604c12f0b776d8f53f46657aa3dff99874 100755 (executable)
 
 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):
     """
index cbfc7d9213f9eae69e64f93de4277140c8adfde3..fc6ddf7fd8967b19ce1f6d178a90f1679ef19297 100755 (executable)
 
 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):
   """