[bbagent] Set environment variable when python2 is omitted from build.

Environment variable is:

    LUCI_OMIT_PYTHON2=true

This will be set when the 'luci.buildbucket.omit_python2' is set for
the build.

This environment variable will be used by e.g. depot_tools to determine
when it absolutely should not use python2, even if it would otherwise
find one in PATH (e.g. from leaked system installs of python).

This also makes the python2 omission experiment imply usage of python3 for the recipes.

R=chanli, randymaldonado, sokcevic, tikuta, yuanjunh

Bug: 942720, 1359438
Change-Id: I0fb4f731d41801e9611fd4df199a359f85aaa902
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/4087937
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Chan Li <chanli@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Randy Maldonado <randymaldonado@google.com>
diff --git a/buildbucket/cmd/bbagent/main.go b/buildbucket/cmd/bbagent/main.go
index 8f6e33a..03b2fe4 100644
--- a/buildbucket/cmd/bbagent/main.go
+++ b/buildbucket/cmd/bbagent/main.go
@@ -637,7 +637,12 @@
 			CacheDir: bbclientInput.input.CacheDir,
 			Env:      environ.System(),
 		}
-		if stringset.NewFromSlice(bbclientInput.input.Build.Input.Experiments...).Has("luci.recipes.use_python3") {
+		experiments := stringset.NewFromSlice(bbclientInput.input.Build.Input.Experiments...)
+		nopy2 := experiments.Has(buildbucket.ExperimentOmitPython2)
+		if nopy2 {
+			invokeOpts.Env.Set("LUCI_OMIT_PYTHON2", "true")
+		}
+		if nopy2 || experiments.Has(buildbucket.ExperimentRecipePY3) {
 			invokeOpts.Env.Set("RECIPES_USE_PY3", "true")
 		}
 		// Buildbucket assigns some grace period to the surrounding task which is
diff --git a/buildbucket/proto.go b/buildbucket/proto.go
index 74e9c86..83bac2a 100644
--- a/buildbucket/proto.go
+++ b/buildbucket/proto.go
@@ -63,6 +63,7 @@
 	ExperimentBBCanarySoftware    = "luci.buildbucket.canary_software"
 	ExperimentBqExporterGo        = "luci.buildbucket.bq_exporter_go"
 	ExperimentNonProduction       = "luci.non_production"
+	ExperimentOmitPython2         = "luci.buildbucket.omit_python2"
 	ExperimentParentTracking      = "luci.buildbucket.parent_tracking"
 	ExperimentRecipePY3           = "luci.recipes.use_python3"
 	ExperimentWaitForCapacity     = "luci.buildbucket.wait_for_capacity_in_slices"