github.com/bir3/gocompiler@v0.9.2202/src/cmd/gocmd/internal/base/tool.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package base
     6  
     7  import (
     8  	"fmt"
     9  	"github.com/bir3/gocompiler/src/go/build"
    10  	"os"
    11  	"path/filepath"
    12  
    13  	"github.com/bir3/gocompiler/src/cmd/gocmd/internal/cfg"
    14  	"github.com/bir3/gocompiler/src/cmd/gocmd/internal/par"
    15  )
    16  
    17  // Tool returns the path to the named tool (for example, "vet").
    18  // If the tool cannot be found, Tool exits the process.
    19  func Tool(toolName string) string {
    20  	toolPath, err := ToolPath(toolName)
    21  	if err != nil && len(cfg.BuildToolexec) == 0 {
    22  		// Give a nice message if there is no tool with that name.
    23  		fmt.Fprintf(os.Stderr, "go: no such tool %q\n", toolName)
    24  		SetExitStatus(2)
    25  		Exit()
    26  	}
    27  	return toolPath
    28  }
    29  
    30  // Tool returns the path at which we expect to find the named tool
    31  // (for example, "vet"), and the error (if any) from statting that path.
    32  func ToolPath(toolName string) (string, error) { return filepath.Join(build.ToolDir, toolName) + cfg.ToolExeSuffix(), nil}
    33  var toolStatCache par.Cache[string, error]