[sdk] Build bootfs and non-bootfs Fuchsia images for packaging into SDK

This builds the bootfs-based SDK, using the sdk_bootfs package config
and the bootfs_packages=true flag, and the non-bootfs SDK build
side-by-side.  The makesdk.go script combines the relevant artifacts
from each into one tarball.  This allows consumers of the SDK to
transition off of the bootfs artifacts to FVM based flows gradually.

Change-Id: If81a512baffd7642be16b69fbcbb1301361e4c16
diff --git a/README.recipes.md b/README.recipes.md
index 4320a68..6aa8598 100644
--- a/README.recipes.md
+++ b/README.recipes.md
@@ -935,15 +935,15 @@
 
 &emsp; **@contextmanager**<br>&mdash; **def [GomaContext](/recipes/sdk.py#64)(api, use_goma):**
 
-&mdash; **def [MakeSdk](/recipes/sdk.py#109)(api, outdir, sdk):**
+&mdash; **def [MakeSdk](/recipes/sdk.py#108)(api, outdir, sdk):**
 
-&mdash; **def [PackageArchive](/recipes/sdk.py#117)(api, sdk):**
+&mdash; **def [PackageArchive](/recipes/sdk.py#116)(api, sdk):**
 
-&mdash; **def [RunSteps](/recipes/sdk.py#165)(api, category, patch_gerrit_url, patch_project, patch_ref, patch_storage, patch_repository_url, project, manifest, remote, use_goma, gn_args):**
+&mdash; **def [RunSteps](/recipes/sdk.py#164)(api, category, patch_gerrit_url, patch_project, patch_ref, patch_storage, patch_repository_url, project, manifest, remote, use_goma, gn_args):**
 
-&mdash; **def [UploadArchive](/recipes/sdk.py#122)(api, sdk, digest):**
+&mdash; **def [UploadArchive](/recipes/sdk.py#121)(api, sdk, digest):**
 
-&mdash; **def [UploadPackage](/recipes/sdk.py#138)(api, outdir, digest):**
+&mdash; **def [UploadPackage](/recipes/sdk.py#137)(api, outdir, digest):**
 ### *recipes* / [service\_account:examples/full](/recipe_modules/service_account/examples/full.py)
 
 [DEPS](/recipe_modules/service_account/examples/full.py#5): [service\_account](#recipe_modules-service_account)
diff --git a/recipes/sdk.expected/ci.json b/recipes/sdk.expected/ci.json
index 6805097..1bc6244 100644
--- a/recipes/sdk.expected/ci.json
+++ b/recipes/sdk.expected/ci.json
@@ -235,9 +235,7 @@
       "--goma=[START_DIR]/cipd/goma",
       "--release",
       "--args",
-      "test",
-      "--args",
-      "bootfs_packages=true"
+      "test"
     ],
     "name": "build fuchsia x86-64.gen",
     "~followup_annotations": [
@@ -338,6 +336,111 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia x86-64 (2)"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "restart"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "infra_step": true,
+    "name": "build fuchsia x86-64.start_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=x86-64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=x86",
+      "--goma=[START_DIR]/cipd/goma",
+      "--release",
+      "--args",
+      "test",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia x86-64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-x86-64-bootfs",
+      "-j",
+      "50"
+    ],
+    "name": "build fuchsia x86-64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "jsonstatus",
+      "[START_DIR]/cipd/goma/jsonstatus"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.goma_jsonstatus (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stat"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.goma_stat (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stop"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.stop_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/scripts/build-zircon.sh",
       "-p",
@@ -376,11 +479,7 @@
       "--goma=[START_DIR]/cipd/goma",
       "--release",
       "--args",
-      "test",
-      "--args",
-      "bootfs_packages=true",
-      "--args",
-      "bootfs_packages=true"
+      "test"
     ],
     "name": "build fuchsia aarch64.gen",
     "~followup_annotations": [
@@ -453,6 +552,111 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia aarch64 (2)"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "restart"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "infra_step": true,
+    "name": "build fuchsia aarch64.start_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=aarch64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=arm64",
+      "--goma=[START_DIR]/cipd/goma",
+      "--release",
+      "--args",
+      "test",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia aarch64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-aarch64-bootfs",
+      "-j",
+      "50"
+    ],
+    "name": "build fuchsia aarch64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "jsonstatus",
+      "[START_DIR]/cipd/goma/jsonstatus"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.goma_jsonstatus (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stat"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.goma_stat (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stop"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.stop_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/cipd/go/bin/go",
       "run",
diff --git a/recipes/sdk.expected/cq_try.json b/recipes/sdk.expected/cq_try.json
index 3b605b6..bdbf996 100644
--- a/recipes/sdk.expected/cq_try.json
+++ b/recipes/sdk.expected/cq_try.json
@@ -247,9 +247,7 @@
       "--packages=garnet/packages/sdk",
       "--platforms=x86",
       "--goma=[START_DIR]/cipd/goma",
-      "--release",
-      "--args",
-      "bootfs_packages=true"
+      "--release"
     ],
     "name": "build fuchsia x86-64.gen",
     "~followup_annotations": [
@@ -350,6 +348,109 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia x86-64 (2)"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "restart"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "infra_step": true,
+    "name": "build fuchsia x86-64.start_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=x86-64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=x86",
+      "--goma=[START_DIR]/cipd/goma",
+      "--release",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia x86-64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-x86-64-bootfs",
+      "-j",
+      "50"
+    ],
+    "name": "build fuchsia x86-64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "jsonstatus",
+      "[START_DIR]/cipd/goma/jsonstatus"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.goma_jsonstatus (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stat"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.goma_stat (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stop"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia x86-64.stop_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/scripts/build-zircon.sh",
       "-p",
@@ -386,11 +487,7 @@
       "--packages=garnet/packages/sdk",
       "--platforms=arm64",
       "--goma=[START_DIR]/cipd/goma",
-      "--release",
-      "--args",
-      "bootfs_packages=true",
-      "--args",
-      "bootfs_packages=true"
+      "--release"
     ],
     "name": "build fuchsia aarch64.gen",
     "~followup_annotations": [
@@ -463,6 +560,109 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia aarch64 (2)"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "restart"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "infra_step": true,
+    "name": "build fuchsia aarch64.start_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=aarch64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=arm64",
+      "--goma=[START_DIR]/cipd/goma",
+      "--release",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia aarch64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-aarch64-bootfs",
+      "-j",
+      "50"
+    ],
+    "name": "build fuchsia aarch64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "jsonstatus",
+      "[START_DIR]/cipd/goma/jsonstatus"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.goma_jsonstatus (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stat"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.goma_stat (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[START_DIR]/cipd/goma/goma_ctl.py",
+      "stop"
+    ],
+    "env": {
+      "GOMA_CACHE_DIR": "[CACHE]/goma",
+      "GOMA_DEPS_CACHE_FILE": "goma_deps_cache",
+      "GOMA_SERVICE_ACCOUNT_JSON_FILE": "/creds/service_accounts/service-account-goma-client.json"
+    },
+    "name": "build fuchsia aarch64.stop_goma (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/cipd/go/bin/go",
       "run",
diff --git a/recipes/sdk.expected/no_goma.json b/recipes/sdk.expected/no_goma.json
index afeefb5..4ebc734 100644
--- a/recipes/sdk.expected/no_goma.json
+++ b/recipes/sdk.expected/no_goma.json
@@ -182,9 +182,7 @@
       "--target_cpu=x86-64",
       "--packages=garnet/packages/sdk",
       "--platforms=x86",
-      "--release",
-      "--args",
-      "bootfs_packages=true"
+      "--release"
     ],
     "name": "build fuchsia x86-64.gen",
     "~followup_annotations": [
@@ -205,6 +203,38 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia x86-64 (2)"
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=x86-64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=x86",
+      "--release",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia x86-64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-x86-64-bootfs",
+      "-j",
+      "2"
+    ],
+    "name": "build fuchsia x86-64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/scripts/build-zircon.sh",
       "-p",
@@ -222,11 +252,7 @@
       "--target_cpu=aarch64",
       "--packages=garnet/packages/sdk",
       "--platforms=arm64",
-      "--release",
-      "--args",
-      "bootfs_packages=true",
-      "--args",
-      "bootfs_packages=true"
+      "--release"
     ],
     "name": "build fuchsia aarch64.gen",
     "~followup_annotations": [
@@ -247,6 +273,38 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "build fuchsia aarch64 (2)"
+  },
+  {
+    "cmd": [
+      "[START_DIR]/build/gn/gen.py",
+      "--target_cpu=aarch64",
+      "--packages=garnet/packages/sdk_bootfs",
+      "--platforms=arm64",
+      "--release",
+      "--args",
+      "bootfs_packages=true"
+    ],
+    "name": "build fuchsia aarch64.gen (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/buildtools/ninja",
+      "-C",
+      "[START_DIR]/out/release-aarch64-bootfs",
+      "-j",
+      "2"
+    ],
+    "name": "build fuchsia aarch64.ninja (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [
       "[START_DIR]/cipd/go/bin/go",
       "run",
diff --git a/recipes/sdk.py b/recipes/sdk.py
index 78dd1b4..a5a6e45 100644
--- a/recipes/sdk.py
+++ b/recipes/sdk.py
@@ -86,7 +86,6 @@
     if release_build:
       gen_cmd.append('--release')
 
-    gn_args.append('bootfs_packages=true')
     for arg in gn_args:
       gen_cmd.append('--args')
       gen_cmd.append(arg)
@@ -177,7 +176,6 @@
   with api.context(infra_steps=True):
     api.jiri.checkout(manifest, remote, project, patch_ref, patch_gerrit_url)
 
-  packages = ['garnet/packages/sdk']
   build_type = 'release'
   release_build = True
   gn_target_and_zircon_platforms = [
@@ -189,9 +187,16 @@
 
   for gn_target, zircon_platform in gn_target_and_zircon_platforms:
     BuildZircon(api, zircon_platform)
+    # Build a version with bootfs and a version without so consumers can transition over.
     fuchsia_build_dir = fuchsia_out_dir.join('%s-%s' % (build_type, gn_target))
+    packages = ['garnet/packages/sdk']
     BuildFuchsia(api, release_build, gn_target, zircon_platform,
                  fuchsia_build_dir, packages, use_goma, gn_args)
+    fuchsia_build_dir_bootfs = fuchsia_out_dir.join('%s-%s-bootfs' % (build_type, gn_target))
+    packages = ['garnet/packages/sdk_bootfs']
+    gn_args_bootfs = gn_args + [ 'bootfs_packages=true' ]
+    BuildFuchsia(api, release_build, gn_target, zircon_platform,
+                 fuchsia_build_dir_bootfs, packages, use_goma, gn_args_bootfs)
 
   outdir = api.path.mkdtemp('sdk')
   sdk = api.path['tmp_base'].join('fuchsia-sdk.tgz')