blob: 8bf45c04a681e52d488cdd650a2b17a5e045e11b [file] [log] [blame]
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import functools
from recipe_engine import recipe_api
GO_CIPD_PACKAGE = "infra/3pp/tools/go/${platform}"
GO_CIPD_VERSION = "version:2@1.18"
class GoApi(recipe_api.RecipeApi):
"""GoApi provides support for Go."""
def __call__(self, *args, **kwargs):
"""Return a Go command step."""
name = kwargs.pop("name", "go " + args[0])
new_env = self.m.context.env
new_env.setdefault("GOROOT", self.go_root)
with self.m.context(env=new_env):
go_cmd = [self.m.path.join(self.go_root, "bin", "go")]
return self.m.step(name, go_cmd + list(args or []), **kwargs)
@functools.cached_property
def go_root(self):
"""Ensure that Go is installed and return the path to the Go dir."""
with self.m.step.nest("ensure go"), self.m.context(infra_steps=True):
pkgs = self.m.cipd.EnsureFile()
pkgs.add_package(GO_CIPD_PACKAGE, GO_CIPD_VERSION)
dest = self.m.path["start_dir"].join("cipd", "go")
self.m.cipd.ensure(dest, pkgs)
return dest