// handleDevBuild renders a canned build for development.
// TODO(hinoka): Use a mock buildbucket rpc client instead.
183001
func handleDevBuild(c *router.Context) error {
	name := c.Params.ByName("name")
	b, err := buildbucket.GetTestBuild(c.Context, "../../buildsource/buildbucket", name)
	if err != nil {
		return err
	}
	bp := ui.NewBuildPage(c.Context, b)
	bp.BuildbucketHost = "example.com"
	return renderBuild(c, bp, nil)
}
397734
func SaveBuild(c context.Context, b *buildbot.Build) (replaced bool, err error) {
	bs, err := summarizeBuild(c, b)
	if err != nil {
		err = errors.Annotate(err, "summarizing build").Err()
		return
	}

	err = datastore.RunInTransaction(c, func(c context.Context) error {
		existingBS := &model.BuildSummary{
			BuildKey: bs.BuildKey,
		}
		existing := &buildEntity{
			Master:      b.Master,
			Buildername: b.Buildername,
			Number:      b.Number,
		}

		if err := datastore.Get(c, existing, existingBS); err == nil {
			// they both exist
			replaced = true

			if bs.Version < existingBS.Version {
				return errors.Reason("Imported version older than existing (%d < %d)", bs.Version, existingBS.Version).Tag(ImportRejectedTag).Err()
			} else if bs.Version == existingBS.Version {
				return nil // idempotency
			}
		} else {
			me := err.(errors.MultiError)
			// one of the errors was NSE; bail.
			for _, ierr := range me {
				if ierr != nil && ierr != datastore.ErrNoSuchEntity {
					return errors.Annotate(ierr, "getting existing build summary").Err()
				}
			}

			// One or the other was NES; don't care, just record both entries to get
			// up to date.
		}

		if err := datastore.Put(c, (*buildEntity)(b), bs); err != nil {
			return err
		}

		return model.UpdateBuilderForBuild(c, bs)
	}, &datastore.TransactionOptions{XG: true})
	return
}
944076
func (client *Client) GetBuild(guid string) (Build, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetBuildRequest,
		URIParams:   internal.Params{"build_guid": guid},
	})
	if err != nil {
		return Build{}, nil, err
	}

	var responseBuild Build
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &responseBuild,
	}
	err = client.connection.Make(request, &response)

	return responseBuild, response.Warnings, err
}
629923
func (s *BatchDeleteBuildsOutput) SetBuildsDeleted(v []*string) *BatchDeleteBuildsOutput {
	s.BuildsDeleted = v
	return s
}
64444
func (h CommandHandlerFunc) HandleCommand(ctx context.Context, cmd Command) error {
	return h(ctx, cmd)
}
84650
func (c *Client) WriteBuild(build *pb.Build) error {
	c.assertInitialized()
	buf, err := proto.Marshal(build)
	if err != nil {
		return err
	}
	return c.buildStream.WriteDatagram(buf)
}
821506
func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error) {
	err = jenkins.get(fmt.Sprintf("/job/%s/%d", job.Name, number), nil, &build)
	return
}
308052
func (t *Table) initBuild() error {
	if t.Oid == "" {
		return nil
	}

	_, _, oidText, fields, err := snmpTable(t.Oid)
	if err != nil {
		return err
	}

	if t.Name == "" {
		t.Name = oidText
	}

	knownOIDs := map[string]bool{}
	for _, f := range t.Fields {
		knownOIDs[f.Oid] = true
	}
	for _, f := range fields {
		if !knownOIDs[f.Oid] {
			t.Fields = append(t.Fields, f)
		}
	}

	return nil
}
865092
func handleLUCIBuildLegacy(c *router.Context, bucket, builder, numberOrId string) error {
	var address string
	if strings.HasPrefix(numberOrId, "b") {
		address = numberOrId[1:]
	} else {
		address = fmt.Sprintf("%s/%s/%s", bucket, builder, numberOrId)
	}

	build, err := buildbucket.GetBuildLegacy(c.Context, address, true)
	return renderBuildLegacy(c, build, true, err)
}
958596
func AutoBuild(files []string, isgenerate bool) {
	state.Lock()
	defer state.Unlock()

	os.Chdir(currpath)

	cmdName := "go"

	var (
		err    error
		stderr bytes.Buffer
	)
	// For applications use full import path like "github.com/.../.."
	// are able to use "go install" to reduce build time.
	if config.Conf.GoInstall {
		icmd := exec.Command(cmdName, "install", "-v")
		icmd.Stdout = os.Stdout
		icmd.Stderr = os.Stderr
		icmd.Env = append(os.Environ(), "GOGC=off")
		icmd.Run()
	}

	if isgenerate {
		beeLogger.Log.Info("Generating the docs...")
		icmd := exec.Command("bee", "generate", "docs")
		icmd.Env = append(os.Environ(), "GOGC=off")
		err = icmd.Run()
		if err != nil {
			utils.Notify("", "Failed to generate the docs.")
			beeLogger.Log.Errorf("Failed to generate the docs.")
			return
		}
		beeLogger.Log.Success("Docs generated!")
	}
	appName := appname
	if err == nil {

		if runtime.GOOS == "windows" {
			appName += ".exe"
		}

		args := []string{"build"}
		args = append(args, "-o", appName)
		if buildTags != "" {
			args = append(args, "-tags", buildTags)
		}
		args = append(args, files...)

		bcmd := exec.Command(cmdName, args...)
		bcmd.Env = append(os.Environ(), "GOGC=off")
		bcmd.Stderr = &stderr
		err = bcmd.Run()
		if err != nil {
			utils.Notify(stderr.String(), "Build Failed")
			beeLogger.Log.Errorf("Failed to build the application: %s", stderr.String())
			return
		}
	}

	beeLogger.Log.Success("Built Successfully!")
	Restart(appName)
}
952459
func (h *binaryInstantiateHandler) cancelBuild(build *buildapi.Build) {
	var versionedBuild = &buildv1.Build{}
	if err := legacyscheme.Scheme.Convert(build, versionedBuild, nil); err != nil {
		klog.Errorf("Unable to convert build to versioned build: %v", err)
		return
	}
	versionedBuild.Status.Cancelled = true
	h.r.Generator.Client.UpdateBuild(h.ctx, versionedBuild)
	wait.Poll(cancelPollInterval, cancelPollDuration, func() (bool, error) {
		versionedBuild.Status.Cancelled = true
		err := h.r.Generator.Client.UpdateBuild(h.ctx, versionedBuild)
		switch {
		case err != nil && errors.IsConflict(err):
			versionedBuild, err = h.r.Generator.Client.GetBuild(h.ctx, versionedBuild.Name, &metav1.GetOptions{})
			return false, err
		default:
			return true, err
		}
	})
}
1039050
func BuildInfoHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(contentType, applicationJSON)
	if methodSupported(w, r) {
		if err := json.NewEncoder(w).Encode(buildinfo.GetBuildInfo()); err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			w.Write(error(err.Error()))
		}
	}
}
1286938
func handleBuildbotBuild(c *router.Context) error {
	buildNum, err := strconv.Atoi(c.Params.ByName("number"))
	if err != nil {
		return errors.Annotate(err, "build number is not a number").
			Tag(grpcutil.InvalidArgumentTag).
			Err()
	}
	id := buildbotapi.BuildID{
		Master:  c.Params.ByName("master"),
		Builder: c.Params.ByName("builder"),
		Number:  buildNum,
	}
	if err := id.Validate(); err != nil {
		return err
	}

	// If this build is emulated, redirect to LUCI.
	b, err := buildstore.EmulationOf(c.Context, id)
	switch {
	case err != nil:
		return err
	case b != nil && b.Number != nil:
		u := *c.Request.URL
		u.Path = fmt.Sprintf("/p/%s/builders/%s/%s/%d", b.Project, b.Bucket, b.Builder, *b.Number)
		http.Redirect(c.Writer, c.Request, u.String(), http.StatusFound)
		return nil
	default:
		build, err := buildbot.GetBuild(c.Context, id)
		return renderBuildLegacy(c, build, false, err)
	}
}
516412
func MustBuild(grammar interface{}, options ...Option) *Parser {
	parser, err := Build(grammar, options...)
	if err != nil {
		panic(err)
	}
	return parser
}
40138
func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
	query, err := cli.imageBuildOptionsToQuery(options)
	if err != nil {
		return types.ImageBuildResponse{}, err
	}

	headers := http.Header(make(map[string][]string))
	buf, err := json.Marshal(options.AuthConfigs)
	if err != nil {
		return types.ImageBuildResponse{}, err
	}
	headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))

	headers.Set("Content-Type", "application/x-tar")

	serverResp, err := cli.postRaw(ctx, "/build", query, buildContext, headers)
	if err != nil {
		return types.ImageBuildResponse{}, err
	}

	osType := getDockerOS(serverResp.header.Get("Server"))

	return types.ImageBuildResponse{
		Body:   serverResp.body,
		OSType: osType,
	}, nil
}
725970
func (c *BuildConfigController) buildConfigUpdated(old, cur interface{}) {
	bc := cur.(*buildv1.BuildConfig)
	c.enqueueBuildConfig(bc)
}
778119
func (s *UpdateBuildOutput) SetBuild(v *Build) *UpdateBuildOutput {
	s.Build = v
	return s
}