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
|
errout *outputValue
|
||||||
allerrors bool
|
allerrors bool
|
||||||
cpuprof *outputValue
|
cpuprof *outputValue
|
||||||
|
pkg string
|
||||||
printers []*printerValue
|
printers []*printerValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +70,8 @@ func NewFlags(fs *flag.FlagSet) *Flags {
|
|||||||
f.cpuprof = newOutputValue(nil)
|
f.cpuprof = newOutputValue(nil)
|
||||||
fs.Var(f.cpuprof, "cpuprofile", "write cpu profile to `file`")
|
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)
|
goasm := newPrinterValue(printer.NewGoAsm, os.Stdout)
|
||||||
fs.Var(goasm, "out", "assembly output")
|
fs.Var(goasm, "out", "assembly output")
|
||||||
f.printers = append(f.printers, goasm)
|
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.
|
// Config builds a configuration object based on flag values.
|
||||||
func (f *Flags) Config() *Config {
|
func (f *Flags) Config() *Config {
|
||||||
pc := printer.NewGoRunConfig()
|
pc := printer.NewGoRunConfig()
|
||||||
|
if f.pkg != "" {
|
||||||
|
pc.Pkg = f.pkg
|
||||||
|
}
|
||||||
passes := []pass.Interface{pass.Compile}
|
passes := []pass.Interface{pass.Compile}
|
||||||
for _, pv := range f.printers {
|
for _, pv := range f.printers {
|
||||||
p := pv.Build(pc)
|
p := pv.Build(pc)
|
||||||
|
|||||||
18
tests/fixedbugs/issue68/asm.go
Normal file
18
tests/fixedbugs/issue68/asm.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/mmcloughlin/avo/build"
|
||||||
|
. "github.com/mmcloughlin/avo/operand"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
TEXT("Issue68", NOSPLIT, "func() uint64")
|
||||||
|
Doc("Issue68 tests custom package names.")
|
||||||
|
x := GP64()
|
||||||
|
MOVQ(U32(68), x)
|
||||||
|
Store(x, ReturnIndex(0))
|
||||||
|
RET()
|
||||||
|
Generate()
|
||||||
|
}
|
||||||
2
tests/fixedbugs/issue68/doc.go
Normal file
2
tests/fixedbugs/issue68/doc.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Package custom tests overriding package name with the CLI.
|
||||||
|
package custom
|
||||||
13
tests/fixedbugs/issue68/issue68_test.go
Normal file
13
tests/fixedbugs/issue68/issue68_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package custom
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run asm.go -pkg custom -out issue69.s -stubs stub.go
|
||||||
|
|
||||||
|
func TestIssue68(t *testing.T) {
|
||||||
|
if got := Issue68(); got != 68 {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
9
tests/fixedbugs/issue68/issue69.s
Normal file
9
tests/fixedbugs/issue68/issue69.s
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by command: go run asm.go -pkg custom -out issue69.s -stubs stub.go. DO NOT EDIT.
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// func Issue68() uint64
|
||||||
|
TEXT ·Issue68(SB), NOSPLIT, $0-8
|
||||||
|
MOVQ $0x00000044, AX
|
||||||
|
MOVQ AX, ret+0(FP)
|
||||||
|
RET
|
||||||
6
tests/fixedbugs/issue68/stub.go
Normal file
6
tests/fixedbugs/issue68/stub.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Code generated by command: go run asm.go -pkg custom -out issue69.s -stubs stub.go. DO NOT EDIT.
|
||||||
|
|
||||||
|
package custom
|
||||||
|
|
||||||
|
// Issue68 tests custom package names.
|
||||||
|
func Issue68() uint64
|
||||||
Reference in New Issue
Block a user