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:
Michael McLoughlin
2020-05-23 12:07:32 -07:00
committed by GitHub
parent fa88270b07
commit 4439b6b2c0
6 changed files with 54 additions and 0 deletions

View File

@@ -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)