[build] Determine whether to include archives in the build based on the
include_archives spec property.

Bug: 43568
Change-Id: I08507605a7dfe08b9a99b99ff8132ef121268960
diff --git a/recipe_modules/build/api.py b/recipe_modules/build/api.py
index 7bf4edf..23b262b 100644
--- a/recipe_modules/build/api.py
+++ b/recipe_modules/build/api.py
@@ -669,14 +669,22 @@
       A FuchsiaBuildResults, representing the build.
     """
     archives_to_build = []
-    # If we are not building images, then we need not build package-related
-    # targets.
-    if not build_spec.exclude_images:
-      archives_to_build.extend(['archive', 'package-archive'])
-    if build_spec.include_breakpad_symbols:
-      archives_to_build.append('breakpad-symbol-archive')
-    if build_spec.include_symbol_archive:
-      archives_to_build.append('symbol-archive')
+    ninja_targets = build_spec.ninja_targets
+
+    # TODO(fxb/43568): Remove once it is always false.
+    if build_spec.include_archives:
+      # If we are not building images, then we need not build package-related
+      # targets.
+      if not build_spec.exclude_images:
+        archives_to_build.extend(['archive', 'package-archive'])
+      if build_spec.include_breakpad_symbols:
+        archives_to_build.append('breakpad-symbol-archive')
+      if build_spec.include_symbol_archive:
+        archives_to_build.append('symbol-archive')
+    elif not build_spec.exclude_images:
+      # This will build the amber-files tree that was included in the
+      # package-archive.
+      ninja_targets.append('build/images:updates')
 
     build_dir = checkout.root_dir.join('out')
 
@@ -690,7 +698,7 @@
         variants=build_spec.variants,
         gn_args=build_spec.gn_args,
         sdk_id=sdk_id,
-        ninja_targets=list(build_spec.ninja_targets),
+        ninja_targets=ninja_targets,
         board=build_spec.board,
         product=build_spec.product,
         collect_build_metrics=collect_build_metrics,
diff --git a/recipe_modules/build/examples/full.expected/default_cq.json b/recipe_modules/build/examples/full.expected/default_cq.json
index 10f93fb..8f1206a 100644
--- a/recipe_modules/build/examples/full.expected/default_cq.json
+++ b/recipe_modules/build/examples/full.expected/default_cq.json
@@ -1378,10 +1378,9 @@
       "[START_DIR]/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
       "fvm.blk",
diff --git a/recipe_modules/build/examples/full.py b/recipe_modules/build/examples/full.py
index acfc88a..c874d1c 100644
--- a/recipe_modules/build/examples/full.py
+++ b/recipe_modules/build/examples/full.py
@@ -118,6 +118,11 @@
             default=False),
     'sdk_id':
         Property(kind=str, help='sdk_id to set in GN', default='sdk-id'),
+    'include_archives':
+        Property(
+            kind=bool,
+            help='Whether to include archives in the build',
+            default=True),
 }
 
 
@@ -125,7 +130,7 @@
              gn_args, ninja_targets, board, product, gcs_bucket,
              debug_symbol_gcs_bucket, checkout_snapshot, release_version,
              extract_artifacts, include_breakpad_symbols,
-             include_symbol_archive, exclude_images, sdk_id):
+             include_symbol_archive, exclude_images, sdk_id, include_archives):
   checkout = api.checkout.CheckoutResults(
       api=api,
       root_dir=api.path['start_dir'],
@@ -149,6 +154,7 @@
       # we frequently exclude images when we're not running tests.
       run_tests=not exclude_images,
       product=product,
+      include_archives=include_archives,
       include_breakpad_symbols=include_breakpad_symbols,
       include_symbol_archive=include_symbol_archive,
       exclude_images=exclude_images,
@@ -242,7 +248,8 @@
   # Test cases that run no tests.
   yield api.build.test('default')
 
-  yield api.build.test('default_cq', tryjob=True)
+  yield api.build.test(
+      'default_cq', properties={'include_archives': False}, tryjob=True)
 
   yield (
       # A subbuild should use the duration file corresponding to its parent
diff --git a/recipes/fuchsia/build.expected/build_type_release_not_run_tests.json b/recipes/fuchsia/build.expected/build_type_release_not_run_tests.json
index 3a26a26..6d18e37 100644
--- a/recipes/fuchsia/build.expected/build_type_release_not_run_tests.json
+++ b/recipes/fuchsia/build.expected/build_type_release_not_run_tests.json
@@ -1751,10 +1751,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
@@ -2023,46 +2022,6 @@
   },
   {
     "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/packages.tar.gz",
-      "gs://fuchsia-infra/builds/8945511751514863184/packages.tar.gz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload packages.tar.gz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@packages.tar.gz@https://storage.cloud.google.com/fuchsia-infra/builds/8945511751514863184/packages.tar.gz@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/build-archive.tgz",
-      "gs://fuchsia-infra/builds/8945511751514863184/build-archive.tgz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload build-archive.tgz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@build-archive.tgz@https://storage.cloud.google.com/fuchsia-infra/builds/8945511751514863184/build-archive.tgz@@@"
-    ]
-  },
-  {
-    "cmd": [
       "python",
       "-u",
       "[START_DIR]/fuchsia/third_party/catapult/tracing/bin/trace2html",
diff --git a/recipes/fuchsia/build.expected/default.json b/recipes/fuchsia/build.expected/default.json
index 4960982..e93907d 100644
--- a/recipes/fuchsia/build.expected/default.json
+++ b/recipes/fuchsia/build.expected/default.json
@@ -1794,10 +1794,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
@@ -2067,46 +2066,6 @@
   },
   {
     "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/packages.tar.gz",
-      "gs://fuchsia-infra/builds/8945511751514863184/packages.tar.gz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload packages.tar.gz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@packages.tar.gz@https://storage.cloud.google.com/fuchsia-infra/builds/8945511751514863184/packages.tar.gz@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/build-archive.tgz",
-      "gs://fuchsia-infra/builds/8945511751514863184/build-archive.tgz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload build-archive.tgz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@build-archive.tgz@https://storage.cloud.google.com/fuchsia-infra/builds/8945511751514863184/build-archive.tgz@@@"
-    ]
-  },
-  {
-    "cmd": [
       "python",
       "-u",
       "[START_DIR]/fuchsia/third_party/catapult/tracing/bin/trace2html",
diff --git a/recipes/fuchsia/build.expected/default_cq.json b/recipes/fuchsia/build.expected/default_cq.json
index c2508fa..7f0ac99 100644
--- a/recipes/fuchsia/build.expected/default_cq.json
+++ b/recipes/fuchsia/build.expected/default_cq.json
@@ -1870,10 +1870,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
diff --git a/recipes/fuchsia/build.expected/non-numeric-parent-id.json b/recipes/fuchsia/build.expected/non-numeric-parent-id.json
index d12a6d3..90f672e 100644
--- a/recipes/fuchsia/build.expected/non-numeric-parent-id.json
+++ b/recipes/fuchsia/build.expected/non-numeric-parent-id.json
@@ -1794,10 +1794,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
@@ -2067,46 +2066,6 @@
   },
   {
     "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/packages.tar.gz",
-      "gs://fuchsia-infra/builds/not-a-number/packages.tar.gz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload packages.tar.gz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@packages.tar.gz@https://storage.cloud.google.com/fuchsia-infra/builds/not-a-number/packages.tar.gz@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "vpython",
-      "-vpython-spec",
-      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
-      "-u",
-      "[START_DIR]/cipd/gsutil/gsutil",
-      "-o",
-      "GSUtil:software_update_check_period=0",
-      "cp",
-      "[START_DIR]/fuchsia/out/default/build-archive.tgz",
-      "gs://fuchsia-infra/builds/not-a-number/build-archive.tgz"
-    ],
-    "infra_step": true,
-    "name": "upload build results.upload build-archive.tgz to fuchsia-infra",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
-      "@@@STEP_LINK@build-archive.tgz@https://storage.cloud.google.com/fuchsia-infra/builds/not-a-number/build-archive.tgz@@@"
-    ]
-  },
-  {
-    "cmd": [
       "python",
       "-u",
       "[START_DIR]/fuchsia/third_party/catapult/tracing/bin/trace2html",
diff --git a/recipes/fuchsia/build.expected/not_test_in_shards.json b/recipes/fuchsia/build.expected/not_test_in_shards.json
index 4b918d5..90ea3ba 100644
--- a/recipes/fuchsia/build.expected/not_test_in_shards.json
+++ b/recipes/fuchsia/build.expected/not_test_in_shards.json
@@ -1713,10 +1713,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
diff --git a/recipes/fuchsia/build.expected/sdk.json b/recipes/fuchsia/build.expected/sdk.json
index 6b3fdc9..a0e7195 100644
--- a/recipes/fuchsia/build.expected/sdk.json
+++ b/recipes/fuchsia/build.expected/sdk.json
@@ -1673,10 +1673,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
diff --git a/recipes/fuchsia/build.expected/spec_remote_cq.json b/recipes/fuchsia/build.expected/spec_remote_cq.json
index 5c0f923..efc732e 100644
--- a/recipes/fuchsia/build.expected/spec_remote_cq.json
+++ b/recipes/fuchsia/build.expected/spec_remote_cq.json
@@ -1892,10 +1892,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",
diff --git a/recipes/fuchsia/build.expected/spec_remote_cq_with_spec_revision.json b/recipes/fuchsia/build.expected/spec_remote_cq_with_spec_revision.json
index c079a50..e14191e 100644
--- a/recipes/fuchsia/build.expected/spec_remote_cq_with_spec_revision.json
+++ b/recipes/fuchsia/build.expected/spec_remote_cq_with_spec_revision.json
@@ -1892,10 +1892,9 @@
       "[START_DIR]/fuchsia/out/default",
       "-j",
       "80",
-      "build-archive.tgz",
-      "build/gn:package_archive",
       "build/images:record_filesystem_sizes",
       "build/images:system_snapshot",
+      "build/images:updates",
       "bundles:infratools",
       "fuchsia.esp.blk",
       "fuchsia.zbi",