From 4439b6b2c061e9165cbf684bfad25e1f1d028393 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sat, 23 May 2020 12:07:32 -0700 Subject: [PATCH] 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 --- build/cli.go | 6 ++++++ tests/fixedbugs/issue68/asm.go | 18 ++++++++++++++++++ tests/fixedbugs/issue68/doc.go | 2 ++ tests/fixedbugs/issue68/issue68_test.go | 13 +++++++++++++ tests/fixedbugs/issue68/issue69.s | 9 +++++++++ tests/fixedbugs/issue68/stub.go | 6 ++++++ 6 files changed, 54 insertions(+) create mode 100644 tests/fixedbugs/issue68/asm.go create mode 100644 tests/fixedbugs/issue68/doc.go create mode 100644 tests/fixedbugs/issue68/issue68_test.go create mode 100644 tests/fixedbugs/issue68/issue69.s create mode 100644 tests/fixedbugs/issue68/stub.go diff --git a/build/cli.go b/build/cli.go index 7474cbc..8a4a379 100644 --- a/build/cli.go +++ b/build/cli.go @@ -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) diff --git a/tests/fixedbugs/issue68/asm.go b/tests/fixedbugs/issue68/asm.go new file mode 100644 index 0000000..e9c60d8 --- /dev/null +++ b/tests/fixedbugs/issue68/asm.go @@ -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() +} diff --git a/tests/fixedbugs/issue68/doc.go b/tests/fixedbugs/issue68/doc.go new file mode 100644 index 0000000..357d1f6 --- /dev/null +++ b/tests/fixedbugs/issue68/doc.go @@ -0,0 +1,2 @@ +// Package custom tests overriding package name with the CLI. +package custom diff --git a/tests/fixedbugs/issue68/issue68_test.go b/tests/fixedbugs/issue68/issue68_test.go new file mode 100644 index 0000000..dfde453 --- /dev/null +++ b/tests/fixedbugs/issue68/issue68_test.go @@ -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() + } +} diff --git a/tests/fixedbugs/issue68/issue69.s b/tests/fixedbugs/issue68/issue69.s new file mode 100644 index 0000000..a74313b --- /dev/null +++ b/tests/fixedbugs/issue68/issue69.s @@ -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 diff --git a/tests/fixedbugs/issue68/stub.go b/tests/fixedbugs/issue68/stub.go new file mode 100644 index 0000000..8f3fcb2 --- /dev/null +++ b/tests/fixedbugs/issue68/stub.go @@ -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