Skip to content

Commit

Permalink
More CR
Browse files Browse the repository at this point in the history
Signed-off-by: Roger Standridge <[email protected]>
  • Loading branch information
archie2x committed Sep 19, 2024
1 parent 81f0c36 commit 38a92a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/cmd/makebb/makebb.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func main() {
l.Fatal(err)
}

l.Printf("Build environment: %s", env)
l.Printf("Compiler: %s", env.Compiler.VersionOutput)
l.Printf("Build environment: %s\n", env)
l.Printf("Compiler: %s\n", env.Compiler.VersionOutput)

tmpDir := *genDir
remove := false
Expand Down
26 changes: 12 additions & 14 deletions src/pkg/golang/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func (c Environ) compilerCmd(gocmd string, args ...string) *exec.Cmd {
return cmd
}

// if go-compiler specified, resolve absolute-path from PATH,
// otherwise return 'nil'.
// if go-compiler specified, return its absolute-path, otherwise return 'nil'
func (c *Environ) compilerAbs() error {
if c.Compiler.Path != "" {
fname, err := exec.LookPath(string(c.Compiler.Path))
Expand All @@ -86,29 +85,29 @@ func (c *Environ) compilerAbs() error {
return nil
}

// runs compilerCmd("version") and parse/caches output, to environ.Compiler
// runs compilerCmd("version") and parse/caches output to environ.Compiler
func (c *Environ) CompilerInit() error {

if c.Compiler.IsInit {
return nil
}

c.compilerAbs()

cmd := c.compilerCmd("version")
v, err := cmd.CombinedOutput()
vb, err := cmd.CombinedOutput()
if err != nil {
return err
}
v := string(vb)

efmt := "go-compiler 'version' output unrecognized: %v"
s := strings.Fields(string(v))
s := strings.Fields(v)
if len(s) < 1 {
return fmt.Errorf(efmt, string(v))
return fmt.Errorf(efmt, v)
}

compiler := c.Compiler
compiler.VersionOutput = string(v)
compiler.VersionOutput = strings.TrimSpace(v)
compiler.Identifier = s[0]
compiler.Type = CompilerTypeFromString(compiler.Identifier)
compiler.IsInit = true
Expand All @@ -117,15 +116,15 @@ func (c *Environ) CompilerInit() error {

case CompilerGo:
if len(s) < 3 {
return fmt.Errorf(efmt, string(v))
return fmt.Errorf(efmt, v)
}
compiler.Version = s[2]
compiler.VersionGo = s[2]

case CompilerTinygo:
// e.g. "tinygo version 0.33.0 darwin/arm64 (using go version go1.22.2 and LLVM version 18.1.2)"
if len(s) < 8 {
return fmt.Errorf(efmt, string(v))
return fmt.Errorf(efmt, v)
}
compiler.Version = s[2]
compiler.VersionGo = s[7]
Expand Down Expand Up @@ -156,14 +155,14 @@ func (c *Environ) CompilerInit() error {
}

case CompilerUnkown:
return fmt.Errorf(efmt, string(v))
return fmt.Errorf(efmt, v)
}
c.Compiler = compiler
return nil
}

// Version returns the Go version string that runtime.Version would return for
// the Go compiler in this environ.
// returns the Go version string that runtime.Version would return for the Go
// compiler in this environ.
func (c *Environ) Version() (string, error) {
if err := c.CompilerInit(); err != nil {
return "", err
Expand All @@ -172,7 +171,6 @@ func (c *Environ) Version() (string, error) {
}

func (c Environ) build(dirPath string, binaryPath string, pattern []string, opts *BuildOpts) error {

if err := c.CompilerInit(); err != nil {
return err
}
Expand Down

0 comments on commit 38a92a0

Please sign in to comment.