github.com/0xKiwi/rules_go@v0.24.3/go/tools/builders/builder.go (about)

     1  // Copyright 2018 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  // builder implements most of the actions for Bazel to compile and link
    16  // go code. We use a single binary for most actions, since this reduces
    17  // the number of inputs needed for each action and allows us to build
    18  // multiple related files in a single action.
    19  
    20  package main
    21  
    22  import (
    23  	"log"
    24  	"os"
    25  )
    26  
    27  func main() {
    28  	log.SetFlags(0)
    29  	log.SetPrefix("builder: ")
    30  
    31  	args, err := expandParamsFiles(os.Args[1:])
    32  	if err != nil {
    33  		log.Fatal(err)
    34  	}
    35  	if len(args) == 0 {
    36  		log.Fatalf("usage: %s verb options...", os.Args[0])
    37  	}
    38  	verb, rest := args[0], args[1:]
    39  
    40  	var action func(args []string) error
    41  	switch verb {
    42  	case "asm":
    43  		action = asm
    44  	case "compile":
    45  		action = compile
    46  	case "compilepkg":
    47  		action = compilePkg
    48  	case "cover":
    49  		action = cover
    50  	case "filterbuildid":
    51  		action = filterBuildID
    52  	case "gentestmain":
    53  		action = genTestMain
    54  	case "link":
    55  		action = link
    56  	case "gennogomain":
    57  		action = genNogoMain
    58  	case "pack":
    59  		action = pack
    60  	case "stdlib":
    61  		action = stdlib
    62  	default:
    63  		log.Fatalf("unknown action: %s", verb)
    64  	}
    65  	log.SetPrefix(verb + ": ")
    66  
    67  	if err := action(rest); err != nil {
    68  		log.Fatal(err)
    69  	}
    70  }