github.com/jlowellwofford/u-root@v1.0.0/tools/rewriteast/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  // rewriteast rewrites a Go command to be bb-compatible.
     6  package main
     7  
     8  import (
     9  	"flag"
    10  	"go/importer"
    11  	"log"
    12  
    13  	"github.com/u-root/u-root/pkg/golang"
    14  	"github.com/u-root/u-root/pkg/uroot"
    15  )
    16  
    17  var (
    18  	pkg    = flag.String("pkg", "", "Go package path to rewrite")
    19  	dest   = flag.String("dest", "", "Destination directory for rewritten package files")
    20  	bbPath = flag.String("bbpath", "", "bb package Go import path")
    21  )
    22  
    23  func main() {
    24  	flag.Parse()
    25  
    26  	env := golang.Default()
    27  	importer := importer.For("source", nil)
    28  
    29  	if err := uroot.RewritePackage(env, *pkg, *dest, *bbPath, importer); err != nil {
    30  		log.Fatalf("failed to rewrite package %v: %v", *pkg, err)
    31  	}
    32  }