[clang_toolchain][gcc_toolchain] Add fuchsia revision as a property and
trigger subbuild with the repo we want to track.

For the clang_toolchain, we want to track the llvm-project repo and for
gcc_toolchain we want to track the gcc repo. However, since the fuchsia
builds launched by these recipes are triggered with a fuchsia commit, in
the milo console, we see the builds tracking the fuchsia repo. Thus we
want to trigger the builds with the appropriate llvm-project/gcc repos
so they show up properly in the console, but still have the builds
checkout a revision of fuchsia.git which we will provide as a property
instead.

Bug: 43619
Change-Id: I5691c7d312d90ba607161464099ea7b0688e595f
diff --git a/recipe_modules/checkout/__init__.py b/recipe_modules/checkout/__init__.py
index ff5319c..b3606c2 100644
--- a/recipe_modules/checkout/__init__.py
+++ b/recipe_modules/checkout/__init__.py
@@ -19,4 +19,14 @@
 ]
 
 from recipe_engine.recipe_api import Property
-from recipe_engine.config import List
+from recipe_engine.config import ConfigGroup, Single
+
+PROPERTIES = {
+    'checkout.buildset':
+        Property(
+            help='gitiles commit to checkout',
+            param_name='buildset',
+            kind=str,
+            default=None,
+        ),
+}
diff --git a/recipe_modules/checkout/api.py b/recipe_modules/checkout/api.py
index b5acd5d..c75d086 100644
--- a/recipe_modules/checkout/api.py
+++ b/recipe_modules/checkout/api.py
@@ -9,6 +9,7 @@
 from urlparse import urlparse
 
 from . import patch
+from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
 
 # Set as an output property and consumed by other recipes code and the results
 # uploader code in google3.
@@ -98,9 +99,27 @@
   CheckoutResults = CheckoutResults
   REVISION_COUNT_PROPERTY = REVISION_COUNT_PROPERTY
 
-  def __init__(self, *args, **kwargs):
+  def __init__(self, buildset, *args, **kwargs):
     super(CheckoutApi, self).__init__(*args, **kwargs)
     self._nested = False
+    self._gitiles_commit = None
+    # If buildset != None, it will be of the format
+    # commit/gitiles/host/project/+/revision.
+    # If provided, it will override the gitiles_commit from the build input used
+    # in the checkout. This would happen in the case that the build input commit
+    # is tracking a different repo than the one we want to checkout (as in the
+    # fuchsia builds launched by the toolchain recipes).
+    if buildset:
+      buildset = buildset.replace('commit/gitiles/', '')
+      buildset_parts = buildset.split('/')
+      host = buildset_parts[0]
+      project = '/'.join(buildset_parts[1:-2])
+      revision = buildset_parts[-1]
+      self._gitiles_commit = common_pb2.GitilesCommit(
+          host=host,
+          project=project,
+          id=revision,
+      )
 
   @_nest
   def with_options(self,
@@ -156,6 +175,10 @@
       if build_input and build_input.gitiles_commit.id:
         commit = build_input.gitiles_commit
 
+      if self._gitiles_commit:
+        # Use gitiles_commit from properties instead of build input.
+        commit = self._gitiles_commit
+
       self.from_commit(
           path=path,
           manifest=manifest,
@@ -183,8 +206,12 @@
         checkout = self.from_patchset_snapshot(
             path=checkout_root, gerrit_change=build.input.gerrit_changes[0])
       else:
+        commit = build.input.gitiles_commit
+        if self._gitiles_commit:
+          # Use gitiles_commit from properties instead of build input.
+          commit = self._gitiles_commit
         checkout = self.from_commit_snapshot(
-            path=checkout_root, gitiles_commit=build.input.gitiles_commit)
+            path=checkout_root, gitiles_commit=commit)
     else:
       assert checkout_spec.manifest
       assert checkout_spec.remote
diff --git a/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties.json b/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties.json
new file mode 100644
index 0000000..319d771
--- /dev/null
+++ b/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties.json
@@ -0,0 +1,273 @@
+[
+  {
+    "cmd": [],
+    "name": "checkout"
+  },
+  {
+    "cmd": [],
+    "name": "checkout.ensure jiri",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "cipd",
+      "ensure",
+      "-root",
+      "[START_DIR]/cipd/jiri",
+      "-ensure-file",
+      "fuchsia/tools/jiri/${platform} git_revision:4bbab8725bd3c64b56e70af3d973d526cd894b49",
+      "-json-output",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "name": "checkout.ensure jiri.ensure_installed",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
+      "@@@STEP_LOG_LINE@json.output@      {@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-git_revision:4bb\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"package\": \"fuchsia/tools/jiri/resolved-platform\"@@@",
+      "@@@STEP_LOG_LINE@json.output@      }@@@",
+      "@@@STEP_LOG_LINE@json.output@    ]@@@",
+      "@@@STEP_LOG_LINE@json.output@  }@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "init",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-analytics-opt=false",
+      "-rewrite-sso-to-https=true",
+      "-cache",
+      "[CACHE]/git",
+      "-shared",
+      "[START_DIR]/fuchsia"
+    ],
+    "name": "checkout.jiri init",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "import",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-name",
+      "integration",
+      "-revision",
+      "HEAD",
+      "minimal",
+      "https://fuchsia.googlesource.com/manifest"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "name": "checkout.jiri import",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "override",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-revision",
+      "deadbeef",
+      "foo",
+      "https://fuchsia.googlesource.com/foo"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "name": "checkout.jiri override",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "update",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-autoupdate=false",
+      "-attempts=3",
+      "-run-hooks=false"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "name": "checkout.jiri update",
+    "timeout": 1800,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "run-hooks",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-attempts=3"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "name": "checkout.jiri run-hooks",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "source-manifest",
+      "-vv",
+      "-time",
+      "-j=50",
+      "/path/to/tmp/json"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "name": "checkout.jiri source-manifest",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@{@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@  \"directories\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@    \"manifest\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@      \"git_checkout\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@        \"repo_url\": \"https://fuchsia.googlesource.com/manifest\", @@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@        \"revision\": \"4c2b0da3c06341db5cebe4d02c78c93c3b2bd78b\"@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@      }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@    }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@  }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@}@@@",
+      "@@@STEP_LOG_END@json.output[source manifest]@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "snapshot",
+      "-vv",
+      "-time",
+      "-j=50",
+      "[CLEANUP]/jiri.snapshot"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "infra_step": true,
+    "name": "checkout.jiri snapshot",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[CLEANUP]/jiri.snapshot",
+      "/path/to/tmp/"
+    ],
+    "cwd": "[START_DIR]/fuchsia",
+    "infra_step": true,
+    "name": "checkout.read snapshot",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@jiri.snapshot@@@",
+      "@@@STEP_LOG_LINE@snapshot_contents@@@@",
+      "@@@STEP_LOG_END@snapshot_contents@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "upload checkout results",
+    "~followup_annotations": [
+      "@@@SET_BUILD_PROPERTY@integration-revision-count@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "upload checkout results.ensure gsutil",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "cipd",
+      "ensure",
+      "-root",
+      "[START_DIR]/cipd/gsutil",
+      "-ensure-file",
+      "infra/gsutil version:4.41",
+      "-json-output",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "name": "upload checkout results.ensure gsutil.ensure_installed",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
+      "@@@STEP_LOG_LINE@json.output@      {@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-version:4.41----\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"package\": \"infra/gsutil\"@@@",
+      "@@@STEP_LOG_LINE@json.output@      }@@@",
+      "@@@STEP_LOG_LINE@json.output@    ]@@@",
+      "@@@STEP_LOG_LINE@json.output@  }@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
+  {
+    "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",
+      "[CLEANUP]/jiri.snapshot",
+      "gs://gcs_bucket/builds/8945511751514863184/jiri.snapshot"
+    ],
+    "infra_step": true,
+    "name": "upload checkout results.upload jiri.snapshot to gcs_bucket",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@jiri.snapshot@https://storage.cloud.google.com/gcs_bucket/builds/8945511751514863184/jiri.snapshot@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "-C",
+      "[START_DIR]/fuchsia/integration",
+      "rev-list",
+      "--count",
+      "HEAD"
+    ],
+    "name": "upload checkout results.git -C",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "name": "$result"
+  }
+]
\ No newline at end of file
diff --git a/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties_with_snapshot.json b/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties_with_snapshot.json
new file mode 100644
index 0000000..22fa3f8
--- /dev/null
+++ b/recipe_modules/checkout/examples/full.expected/use_gitiles_commit_from_properties_with_snapshot.json
@@ -0,0 +1,338 @@
+[
+  {
+    "cmd": [],
+    "name": "checkout"
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "ensure-directory",
+      "--mode",
+      "0777",
+      "[CLEANUP]/snapshot_repo"
+    ],
+    "infra_step": true,
+    "name": "checkout.makedirs",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "init"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git init",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "remote",
+      "add",
+      "origin",
+      "https://fuchsia.googlesource.com/foo"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git remote",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "fetch",
+      "--tags",
+      "origin",
+      "deadbeef"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git fetch",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "checkout",
+      "-f",
+      "FETCH_HEAD"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git checkout",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "rev-parse",
+      "HEAD"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git rev-parse",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "clean",
+      "-f",
+      "-d",
+      "-x"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.git clean",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "checkout.submodule",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "submodule",
+      "sync"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.submodule.git submodule sync",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "submodule",
+      "update",
+      "--init"
+    ],
+    "cwd": "[CLEANUP]/snapshot_repo",
+    "infra_step": true,
+    "name": "checkout.submodule.git submodule update",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "checkout.ensure jiri",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "cipd",
+      "ensure",
+      "-root",
+      "[START_DIR]/cipd/jiri",
+      "-ensure-file",
+      "fuchsia/tools/jiri/${platform} git_revision:4bbab8725bd3c64b56e70af3d973d526cd894b49",
+      "-json-output",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "name": "checkout.ensure jiri.ensure_installed",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
+      "@@@STEP_LOG_LINE@json.output@      {@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-git_revision:4bb\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"package\": \"fuchsia/tools/jiri/resolved-platform\"@@@",
+      "@@@STEP_LOG_LINE@json.output@      }@@@",
+      "@@@STEP_LOG_LINE@json.output@    ]@@@",
+      "@@@STEP_LOG_LINE@json.output@  }@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "init",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-analytics-opt=false",
+      "-rewrite-sso-to-https=true",
+      "-cache",
+      "[CACHE]/git",
+      "-shared"
+    ],
+    "infra_step": true,
+    "name": "checkout.jiri init",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "update",
+      "-vv",
+      "-time",
+      "-j=50",
+      "-autoupdate=false",
+      "-attempts=3",
+      "[CLEANUP]/snapshot_repo/snapshot"
+    ],
+    "infra_step": true,
+    "name": "checkout.jiri update",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "[START_DIR]/cipd/jiri/jiri",
+      "source-manifest",
+      "-vv",
+      "-time",
+      "-j=50",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "name": "checkout.jiri source-manifest",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@{@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@  \"directories\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@    \"manifest\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@      \"git_checkout\": {@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@        \"repo_url\": \"https://fuchsia.googlesource.com/manifest\", @@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@        \"revision\": \"4c2b0da3c06341db5cebe4d02c78c93c3b2bd78b\"@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@      }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@    }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@  }@@@",
+      "@@@STEP_LOG_LINE@json.output[source manifest]@}@@@",
+      "@@@STEP_LOG_END@json.output[source manifest]@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[CLEANUP]/snapshot_repo/snapshot",
+      "/path/to/tmp/"
+    ],
+    "infra_step": true,
+    "name": "checkout.read snapshot",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@snapshot@@@",
+      "@@@STEP_LOG_LINE@snapshot_contents@@@@",
+      "@@@STEP_LOG_END@snapshot_contents@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "upload checkout results",
+    "~followup_annotations": [
+      "@@@SET_BUILD_PROPERTY@integration-revision-count@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "upload checkout results.ensure gsutil",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "cipd",
+      "ensure",
+      "-root",
+      "[START_DIR]/cipd/gsutil",
+      "-ensure-file",
+      "infra/gsutil version:4.41",
+      "-json-output",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "name": "upload checkout results.ensure gsutil.ensure_installed",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
+      "@@@STEP_LOG_LINE@json.output@      {@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-version:4.41----\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"package\": \"infra/gsutil\"@@@",
+      "@@@STEP_LOG_LINE@json.output@      }@@@",
+      "@@@STEP_LOG_LINE@json.output@    ]@@@",
+      "@@@STEP_LOG_LINE@json.output@  }@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
+  {
+    "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",
+      "[CLEANUP]/snapshot_repo/snapshot",
+      "gs://gcs_bucket/builds/8945511751514863184/snapshot"
+    ],
+    "infra_step": true,
+    "name": "upload checkout results.upload snapshot to gcs_bucket",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@snapshot@https://storage.cloud.google.com/gcs_bucket/builds/8945511751514863184/snapshot@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "-C",
+      "[START_DIR]/fuchsia/integration",
+      "rev-list",
+      "--count",
+      "HEAD"
+    ],
+    "name": "upload checkout results.git -C",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "name": "$result"
+  }
+]
\ No newline at end of file
diff --git a/recipe_modules/checkout/examples/full.py b/recipe_modules/checkout/examples/full.py
index 5a4dcf2..2ea310e 100644
--- a/recipe_modules/checkout/examples/full.py
+++ b/recipe_modules/checkout/examples/full.py
@@ -257,3 +257,21 @@
                           remote='https://fuchsia.googlesource.com/manifest',
                       ))),
       })
+
+  yield api.checkout.test(
+      'use_gitiles_commit_from_properties',
+      tryjob=False,
+      properties={
+          'checkout.buildset':
+              'commit/gitiles/fuchsia.googlesource.com/foo/+/deadbeef',
+      })
+
+  yield api.checkout.test(
+      'use_gitiles_commit_from_properties_with_snapshot',
+      tryjob=False,
+      properties={
+          'checkout.buildset':
+              'commit/gitiles/fuchsia.googlesource.com/foo/+/deadbeef',
+          'use_snapshot':
+              True,
+      })
diff --git a/recipes/clang_toolchain.expected/prod-linux-x64.json b/recipes/clang_toolchain.expected/prod-linux-x64.json
index 9803ea3..89b7ac7 100644
--- a/recipes/clang_toolchain.expected/prod-linux-x64.json
+++ b/recipes/clang_toolchain.expected/prod-linux-x64.json
@@ -1718,7 +1718,7 @@
     ],
     "infra_step": true,
     "name": "luci-scheduler.EmitTriggers",
-    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"clang_toolchain.fuchsia-arm64-debug\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-arm64-release\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-x64-debug\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-x64-release\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.clang_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"clang_toolchain\": {\"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}}, \"tags\": [\"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
+    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"clang_toolchain.fuchsia-arm64-debug\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-arm64-release\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-x64-debug\", \"project\": \"fuchsia\"}, {\"job\": \"clang_toolchain.fuchsia-x64-release\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.clang_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"clang_toolchain\": {\"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}}, \"tags\": [\"buildset:commit/gitiles/fuchsia.googlesource.com/third_party/llvm-project/+/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@input@{@@@",
       "@@@STEP_LOG_LINE@input@    \"batches\": [@@@",
@@ -1748,13 +1748,14 @@
       "@@@STEP_LOG_LINE@input@                            \"instance\": \"[dummy hash]\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"type\": \"isolated\"@@@",
       "@@@STEP_LOG_LINE@input@                        }, @@@",
+      "@@@STEP_LOG_LINE@input@                        \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"clang_toolchain\": {@@@",
       "@@@STEP_LOG_LINE@input@                            \"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"@@@",
       "@@@STEP_LOG_LINE@input@                        }@@@",
       "@@@STEP_LOG_LINE@input@                    }, @@@",
       "@@@STEP_LOG_LINE@input@                    \"tags\": [@@@",
-      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
+      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/fuchsia.googlesource.com/third_party/llvm-project/+/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"gitiles_ref:refs/heads/master\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"parent_buildername:builder\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"user_agent:recipe\"@@@",
diff --git a/recipes/clang_toolchain.expected/prod-mac-x64.json b/recipes/clang_toolchain.expected/prod-mac-x64.json
index 5ae79ea..130a1e9 100644
--- a/recipes/clang_toolchain.expected/prod-mac-x64.json
+++ b/recipes/clang_toolchain.expected/prod-mac-x64.json
@@ -1778,7 +1778,7 @@
     ],
     "infra_step": true,
     "name": "luci-scheduler.EmitTriggers",
-    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"clang_toolchain.fuchsia-host-mac\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.clang_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"clang_toolchain\": {\"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}}, \"tags\": [\"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
+    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"clang_toolchain.fuchsia-host-mac\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.clang_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"clang_toolchain\": {\"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}}, \"tags\": [\"buildset:commit/gitiles/fuchsia.googlesource.com/third_party/llvm-project/+/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@input@{@@@",
       "@@@STEP_LOG_LINE@input@    \"batches\": [@@@",
@@ -1796,13 +1796,14 @@
       "@@@STEP_LOG_LINE@input@                            \"instance\": \"[dummy hash]\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"type\": \"isolated\"@@@",
       "@@@STEP_LOG_LINE@input@                        }, @@@",
+      "@@@STEP_LOG_LINE@input@                        \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"clang_toolchain\": {@@@",
       "@@@STEP_LOG_LINE@input@                            \"git_repository\": \"https://fuchsia.googlesource.com/third_party/llvm-project\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"git_revision\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"@@@",
       "@@@STEP_LOG_LINE@input@                        }@@@",
       "@@@STEP_LOG_LINE@input@                    }, @@@",
       "@@@STEP_LOG_LINE@input@                    \"tags\": [@@@",
-      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
+      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/fuchsia.googlesource.com/third_party/llvm-project/+/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"gitiles_ref:refs/heads/master\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"parent_buildername:builder\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"user_agent:recipe\"@@@",
diff --git a/recipes/clang_toolchain.py b/recipes/clang_toolchain.py
index 85582e7..e3b16e2 100644
--- a/recipes/clang_toolchain.py
+++ b/recipes/clang_toolchain.py
@@ -515,11 +515,14 @@
                       'type': 'isolated',
                       'instance': isolated,
                   },
+                  'checkout.buildset':
+                      'commit/gitiles/%s/%s/+/%s' %
+                      (host, project, fuchsia_rev),
               },
               tags={
                   'buildset':
-                      'commit/gitiles/%s/%s/+/%s' %
-                      (host, project, fuchsia_rev),
+                      'commit/gitiles/%s/+/%s' %
+                      (repository.split('://')[1], revision),
                   'gitiles_ref':
                       ref,
               }),
diff --git a/recipes/gcc_toolchain.expected/ci_linux_intel.json b/recipes/gcc_toolchain.expected/ci_linux_intel.json
index 39ee614..8ad585a 100644
--- a/recipes/gcc_toolchain.expected/ci_linux_intel.json
+++ b/recipes/gcc_toolchain.expected/ci_linux_intel.json
@@ -1601,7 +1601,7 @@
     ],
     "infra_step": true,
     "name": "luci-scheduler.EmitTriggers",
-    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"gcc.bringup.arm64-gcc-qemu_kvm\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.bringup.x64-gcc-qemu_kvm\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.zbi_tests-arm64-gcc\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.zbi_tests-x64-gcc\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.gcc_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"gcc_toolchain\": {\"git_repository\": \"https://gnu.googlesource.com/gcc,https://gnu.googlesource.com/binutils-gdb\", \"git_revision\": \"4b5e15daff8b54440e3fda451c318ad31e532fab,3d861fdb826c2f5cf270dd5f585d0e6057e1bf4f\"}}, \"tags\": [\"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
+    "stdin": "{\"batches\": [{\"jobs\": [{\"job\": \"gcc.bringup.arm64-gcc-qemu_kvm\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.bringup.x64-gcc-qemu_kvm\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.zbi_tests-arm64-gcc\", \"project\": \"fuchsia\"}, {\"job\": \"gcc.zbi_tests-x64-gcc\", \"project\": \"fuchsia\"}], \"trigger\": {\"buildbucket\": {\"properties\": {\"build.gcc_toolchain\": {\"instance\": \"[dummy hash]\", \"type\": \"isolated\"}, \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"gcc_toolchain\": {\"git_repository\": \"https://gnu.googlesource.com/gcc,https://gnu.googlesource.com/binutils-gdb\", \"git_revision\": \"4b5e15daff8b54440e3fda451c318ad31e532fab,3d861fdb826c2f5cf270dd5f585d0e6057e1bf4f\"}}, \"tags\": [\"buildset:commit/gitiles/gnu.googlesource.com/gcc/+/4b5e15daff8b54440e3fda451c318ad31e532fab\", \"gitiles_ref:refs/heads/master\", \"parent_buildername:builder\", \"user_agent:recipe\"]}, \"id\": \"6a0a73b0-070b-492b-9135-9f26a2a00001\", \"title\": \"builder/0\"}}], \"timestamp\": 1337000004500000}",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@input@{@@@",
       "@@@STEP_LOG_LINE@input@    \"batches\": [@@@",
@@ -1631,13 +1631,14 @@
       "@@@STEP_LOG_LINE@input@                            \"instance\": \"[dummy hash]\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"type\": \"isolated\"@@@",
       "@@@STEP_LOG_LINE@input@                        }, @@@",
+      "@@@STEP_LOG_LINE@input@                        \"checkout.buildset\": \"commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"gcc_toolchain\": {@@@",
       "@@@STEP_LOG_LINE@input@                            \"git_repository\": \"https://gnu.googlesource.com/gcc,https://gnu.googlesource.com/binutils-gdb\", @@@",
       "@@@STEP_LOG_LINE@input@                            \"git_revision\": \"4b5e15daff8b54440e3fda451c318ad31e532fab,3d861fdb826c2f5cf270dd5f585d0e6057e1bf4f\"@@@",
       "@@@STEP_LOG_LINE@input@                        }@@@",
       "@@@STEP_LOG_LINE@input@                    }, @@@",
       "@@@STEP_LOG_LINE@input@                    \"tags\": [@@@",
-      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/fuchsia.googlesource.com/fuchsia/+/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", @@@",
+      "@@@STEP_LOG_LINE@input@                        \"buildset:commit/gitiles/gnu.googlesource.com/gcc/+/4b5e15daff8b54440e3fda451c318ad31e532fab\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"gitiles_ref:refs/heads/master\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"parent_buildername:builder\", @@@",
       "@@@STEP_LOG_LINE@input@                        \"user_agent:recipe\"@@@",
diff --git a/recipes/gcc_toolchain.py b/recipes/gcc_toolchain.py
index af33230..1c9667a 100644
--- a/recipes/gcc_toolchain.py
+++ b/recipes/gcc_toolchain.py
@@ -382,10 +382,13 @@
                     'type': 'isolated',
                     'instance': isolated,
                 },
+                'checkout.buildset':
+                    'commit/gitiles/%s/%s/+/%s' % (host, project, revision),
             },
             tags={
                 'buildset':
-                    'commit/gitiles/%s/%s/+/%s' % (host, project, revision),
+                    'commit/gitiles/%s/+/%s' %
+                    (GCC_GIT.split('://')[1], gcc_revision),
                 'gitiles_ref':
                     ref,
             }),