Give update_prebuilts.py --bug support

Good idea in general, but the extension finalization
scripts also requires it so sets us up for that.

Test: ./update_prebuilts.py -p --bug 1
Change-Id: I03280a494da32607e39da24eea2153cd76d94a92
diff --git a/update_prebuilts/update_prebuilts.py b/update_prebuilts/update_prebuilts.py
index a1ddbd9..7c343ba 100755
--- a/update_prebuilts/update_prebuilts.py
+++ b/update_prebuilts/update_prebuilts.py
@@ -869,6 +869,7 @@
 parser.add_argument(
     '-f', '--finalize_sdk', type=int,
     help='If specified, imports the source build as the specified finalized SDK version')
+parser.add_argument('--bug', type=int, help='The bug number to add to the commit message.')
 parser.add_argument(
     '--sdk_target',
     default=framework_sdk_target,
@@ -904,6 +905,9 @@
         and which('pom2bp') is None:
     parser.error("Cannot find pom2bp in path; please run lunch to set up build environment. You may also need to run 'm pom2bp' if it hasn't been built already.")
     sys.exit(1)
+if args.finalize_sdk and not args.bug:
+    parser.error("Specifying a bug ID with --bug is required when finalizing an SDK.")
+    sys.exit(1)
 
 if uncommittedChangesExist():
     if args.commit_first:
@@ -914,6 +918,10 @@
     print_e('FAIL: There are uncommitted changes here. Please commit or stash before continuing, because %s will run "git reset --hard" if execution fails' % os.path.basename(__file__))
     sys.exit(1)
 
+commit_message_suffix = ""
+if args.bug:
+    commit_message_suffix = "\n\nBug: %d" % args.bug
+
 try:
     components = None
     if args.constraint:
@@ -952,7 +960,7 @@
         n = args.finalize_sdk
         if finalize_sdk(args.sdk_target, getBuildId(args), n):
             # We commit the finalized dir separately from the current sdk update.
-            msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id)
+            msg = "Import final sdk version %d from build %s%s" % (n, getBuildId(args).url_id, commit_message_suffix)
             subprocess.check_call(['git', 'add', '%d' % n])
             subprocess.check_call(['git', 'add', 'Android.bp'])
             subprocess.check_call(['git', 'commit', '-m', msg])
@@ -983,7 +991,7 @@
         src_msg = "local Maven ZIP"
     else:
         src_msg = "build %s" % (getBuildId(args).url_id)
-    msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
+    msg = "Import %s from %s\n\n%s%s" % (components, src_msg, flatten(sys.argv), commit_message_suffix)
     subprocess.check_call(['git', 'commit', '-m', msg])
     if args.finalize_sdk:
         print('NOTE: Created two commits:')