summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2017-10-04 20:02:43 -0700
committerGabe Black <gabeblack@google.com>2017-10-05 09:16:35 +0000
commit9de3d9441648079e46d734fc8415c5b1dc12ec6a (patch)
treeccc9caf3e3233c37100f9e07f3274eb85ab207dd /util
parentedc8cffbead0b76cf8ea537f5d612963d975aa56 (diff)
downloadgem5-9de3d9441648079e46d734fc8415c5b1dc12ec6a.tar.xz
misc: Use a Makefile to ensure util/packet_pb2.py is up to date.
Rather than just ensuring that packet_pb2.py is available in general, use a Makefile to ensure that it's also up to date in case packet.proto has changed. Also, remove a check that ensures that the protobuf module is available, since python will complain if it needs it and can't find it. Finally, remove a comment which talks about manually regenerating the packet_pb2.py module, something that hasn't been necessary for a while, even with the old version of this code. Change-Id: I40c5c1f577e6d7ad1af9a209309a1eb92f073317 Reviewed-on: https://gem5-review.googlesource.com/5005 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'util')
-rw-r--r--util/Makefile4
-rwxr-xr-xutil/decode_packet_trace.py42
2 files changed, 11 insertions, 35 deletions
diff --git a/util/Makefile b/util/Makefile
new file mode 100644
index 000000000..f7254518b
--- /dev/null
+++ b/util/Makefile
@@ -0,0 +1,4 @@
+PROTO_PATH=../src/proto
+
+packet_pb2.py: $(PROTO_PATH)/packet.proto
+ protoc --python_out=. --proto_path=$(PROTO_PATH) $<
diff --git a/util/decode_packet_trace.py b/util/decode_packet_trace.py
index dab43c314..9ef9b5fa9 100755
--- a/util/decode_packet_trace.py
+++ b/util/decode_packet_trace.py
@@ -38,45 +38,17 @@
# Authors: Andreas Hansson
# This script is used to dump protobuf packet traces to ASCII
-# format. It assumes that protoc has been executed and already
-# generated the Python package for the packet messages. This can
-# be done manually using:
-# protoc --python_out=. --proto_path=src/proto src/proto/packet.proto
-#
-# The ASCII trace format uses one line per request on the format cmd,
-# addr, size, tick,flags. For example:
-# r,128,64,4000,0
-# w,232123,64,500000,0
+# format.
+import os
import protolib
+import subprocess
import sys
-# Import the packet proto definitions. If they are not found, attempt
-# to generate them automatically.
-try:
- import packet_pb2
-except:
- print "Did not find packet proto definitions, attempting to generate"
- import os
- util_dir = os.path.dirname(os.path.realpath(__file__))
- proto_dir = os.path.join(os.path.dirname(util_dir), 'src', 'proto')
- proto_file = os.path.join(proto_dir, 'packet.proto')
- from subprocess import call
- error = call(['protoc', '--python_out=' + util_dir,
- '--proto_path=' + proto_dir, proto_file])
- if not error:
- print "Generated packet proto definitions"
-
- try:
- import google.protobuf
- except:
- print "Please install Python protobuf module"
- exit(-1)
-
- import packet_pb2
- else:
- print "Failed to import packet proto definitions"
- exit(-1)
+util_dir = os.path.dirname(os.path.realpath(__file__))
+# Make sure the proto definitions are up to date.
+subprocess.check_call(['make', '--quiet', '-C', util_dir, 'packet_pb2.py'])
+import packet_pb2
def main():
if len(sys.argv) != 3: