build: -pkg flag to specify package name (#150)
Allows override in the case where package name is incorrectly deduced from directory name. Fixes #68 Fixes #147
This commit is contained in:
committed by
GitHub
parent
fa88270b07
commit
4439b6b2c0
@@ -54,6 +54,7 @@ type Flags struct {
|
||||
errout *outputValue
|
||||
allerrors bool
|
||||
cpuprof *outputValue
|
||||
pkg string
|
||||
printers []*printerValue
|
||||
}
|
||||
|
||||
@@ -69,6 +70,8 @@ func NewFlags(fs *flag.FlagSet) *Flags {
|
||||
f.cpuprof = newOutputValue(nil)
|
||||
fs.Var(f.cpuprof, "cpuprofile", "write cpu profile to `file`")
|
||||
|
||||
fs.StringVar(&f.pkg, "pkg", "", "package name (defaults to current directory name)")
|
||||
|
||||
goasm := newPrinterValue(printer.NewGoAsm, os.Stdout)
|
||||
fs.Var(goasm, "out", "assembly output")
|
||||
f.printers = append(f.printers, goasm)
|
||||
@@ -83,6 +86,9 @@ func NewFlags(fs *flag.FlagSet) *Flags {
|
||||
// Config builds a configuration object based on flag values.
|
||||
func (f *Flags) Config() *Config {
|
||||
pc := printer.NewGoRunConfig()
|
||||
if f.pkg != "" {
|
||||
pc.Pkg = f.pkg
|
||||
}
|
||||
passes := []pass.Interface{pass.Compile}
|
||||
for _, pv := range f.printers {
|
||||
p := pv.Build(pc)
|
||||
|
||||
Reference in New Issue
Block a user