-# 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:
- 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