github.com/ajguerrer/rules_go@v0.20.3/go/tools/builders/info.go (about)

     1  // Copyright 2017 The Bazel Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // info prints debugging information about the go environment.
    16  // It is used to help examine the execution environment of rules_go
    17  package main
    18  
    19  import (
    20  	"flag"
    21  	"fmt"
    22  	"log"
    23  	"os"
    24  )
    25  
    26  func run(args []string) error {
    27  	args, err := readParamsFiles(args)
    28  	if err != nil {
    29  		return err
    30  	}
    31  	filename := ""
    32  	flags := flag.NewFlagSet("info", flag.ExitOnError)
    33  	flags.StringVar(&filename, "out", filename, "The file to write the report to")
    34  	goenv := envFlags(flags)
    35  	if err := flags.Parse(args); err != nil {
    36  		return err
    37  	}
    38  	if err := goenv.checkFlags(); err != nil {
    39  		return err
    40  	}
    41  	f := os.Stderr
    42  	if filename != "" {
    43  		var err error
    44  		f, err = os.Create(filename)
    45  		if err != nil {
    46  			return fmt.Errorf("Could not create report file: %v", err)
    47  		}
    48  		defer f.Close()
    49  	}
    50  	if err := goenv.runCommandToFile(f, goenv.goCmd("version")); err != nil {
    51  		return err
    52  	}
    53  	if err := goenv.runCommandToFile(f, goenv.goCmd("env")); err != nil {
    54  		return err
    55  	}
    56  	return nil
    57  }
    58  
    59  func main() {
    60  	if err := run(os.Args[1:]); err != nil {
    61  		log.Fatal(err)
    62  	}
    63  }