github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/tools/makebbmain/main.go (about) 1 // Copyright 2015-2018 the u-root 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 // makebbmain creates a bb main.go source file. 6 package main 7 8 import ( 9 "flag" 10 "log" 11 12 "github.com/u-root/u-root/pkg/bb" 13 "github.com/u-root/u-root/pkg/golang" 14 ) 15 16 var ( 17 template = flag.String("template", "github.com/u-root/u-root/pkg/bb/cmd", "bb main.go template package") 18 outputDir = flag.String("o", "", "output directory") 19 ) 20 21 func main() { 22 flag.Parse() 23 if flag.NArg() == 0 { 24 log.Fatalf("must list bb packages as arguments") 25 } 26 27 env := golang.Default() 28 p, err := env.Package(*template) 29 if err != nil { 30 log.Fatal(err) 31 } 32 33 fset, astp, err := bb.ParseAST(bb.SrcFiles(p)) 34 if err != nil { 35 log.Fatal(err) 36 } 37 if err := bb.CreateBBMainSource(fset, astp, flag.Args(), *outputDir); err != nil { 38 log.Fatalf("failed to create bb source file: %v", err) 39 } 40 }