github.com/bazelbuild/rules_go@v0.47.2-0.20240515105122-e7ddb9ea474e/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 "compilepkg": 43 action = compilePkg 44 case "filterbuildid": 45 action = filterBuildID 46 case "gentestmain": 47 action = genTestMain 48 case "link": 49 action = link 50 case "gennogomain": 51 action = genNogoMain 52 case "stdlib": 53 action = stdlib 54 case "stdliblist": 55 action = stdliblist 56 default: 57 log.Fatalf("unknown action: %s", verb) 58 } 59 log.SetPrefix(verb + ": ") 60 61 if err := action(rest); err != nil { 62 log.Fatal(err) 63 } 64 }