Snap for 9981223 from 9aacc7b81d7d2cb1ef286eec15d949f1b879798e to udc-release

Change-Id: I2b8b2ee4b7d103c3322e6eec9e9fe3cc0501a725
diff --git a/README.md b/README.md
index 345de8a..d5e251e 100644
--- a/README.md
+++ b/README.md
@@ -16,16 +16,22 @@
 tools/external_updater/updater.sh update ${LIBNAME}
 ```
 
-Update a library without committing and uploading:
+Update a library without committing and uploading to Gerrit:
 
 ```shell
-tools/external_updater/updater.sh update --stop_after_merge ${LIBNAME}
+tools/external_updater/updater.sh update --no-upload ${LIBNAME}
 ```
 
 Update a library on top of the local changes in the current branch, commit, and upload the change to Gerrit:
 
 ```shell
-tools/external_updater/updater.sh update --keep_local_changes ${LIBNAME}
+tools/external_updater/updater.sh update --keep-local-changes ${LIBNAME}
+```
+
+Update a library without building:
+
+```shell
+tools/external_updater/updater.sh update --no-build ${LIBNAME}
 ```
 
 LIBNAME can be the path to a library under external/, e.g. kotlinc, or
diff --git a/external_updater.py b/external_updater.py
index d147d13..149eea9 100644
--- a/external_updater.py
+++ b/external_updater.py
@@ -116,7 +116,12 @@
         fileutils.write_metadata(full_path, updated_metadata, args.keep_date)
         git_utils.add_file(full_path, 'METADATA')
 
-        if args.stop_after_merge:
+        if args.build:
+            if not updater_utils.build(full_path):
+                print("Build failed. Aborting upload.")
+                return
+
+        if args.no_upload:
             return
 
         try:
@@ -267,7 +272,7 @@
         nargs='*',
         help='Paths of the project. '
         'Relative paths will be resolved from external/.')
-    check_parser.add_argument('--json_output',
+    check_parser.add_argument('--json-output',
                               help='Path of a json file to write result to.')
     check_parser.add_argument(
         '--all',
@@ -287,7 +292,7 @@
         nargs='*',
         help='Paths of the project as globs. '
         'Relative paths will be resolved from external/.')
-    update_parser.add_argument('--json_output',
+    update_parser.add_argument('--json-output',
                                help='Path of a json file to write result to.')
     update_parser.add_argument(
         '--force',
@@ -298,19 +303,23 @@
         help='Run update and refresh to the current version.',
         action='store_true')
     update_parser.add_argument(
-        '--keep_date',
+        '--keep-date',
         help='Run update and do not change date in METADATA.',
         action='store_true')
-    update_parser.add_argument('--stop_after_merge',
+    update_parser.add_argument('--no-upload',
                                action='store_true',
-                               help='Stops after merging new changes')
-    update_parser.add_argument('--keep_local_changes',
+                               help='Does not upload to Gerrit after upgrade')
+    update_parser.add_argument('--keep-local-changes',
                                action='store_true',
                                help='Updates the current branch')
-    update_parser.add_argument('--skip_post_update',
+    update_parser.add_argument('--skip-post-update',
                                action='store_true',
                                help='Skip post_update script')
-    update_parser.add_argument('--remote_name',
+    update_parser.add_argument('--no-build',
+                               action='store_false',
+                               dest='build',
+                               help='Skip building'),
+    update_parser.add_argument('--remote-name',
                                default='aosp',
                                required=False,
                                help='Upstream remote name.')
diff --git a/updater_utils.py b/updater_utils.py
index 3960d76..b263dcb 100644
--- a/updater_utils.py
+++ b/updater_utils.py
@@ -128,3 +128,9 @@
     if not latest:
         raise ValueError('No matching version.')
     return latest
+
+
+def build(proj_path: Path) -> None:
+    cmd = ['build/soong/soong_ui.bash', "--build-mode", "--modules-in-a-dir-no-deps", f"--dir={str(proj_path)}"]
+    print('Building...')
+    return subprocess.run(cmd, check=True, text=True)