commit 8402d724a9b632cbf359a44444cdb069392ab9c6 Author: Vincent Batts Date: Wed Jun 27 11:39:46 2018 -0400 basic generation Signed-off-by: Vincent Batts diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bbb6ae8 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ + +run: farts + ./farts + +farts: $(wildcard *.go) farts.go + go build -o $@ . + +farts.go: + go generate + +clean: + rm -rf *~ farts.go farts diff --git a/g.go b/g.go new file mode 100644 index 0000000..313df8a --- /dev/null +++ b/g.go @@ -0,0 +1,5 @@ +//go:generate go run gen.go -o farts.go + +package main + +// this file is _just_ here to snag the `go generate` command. Logic is in gen.go diff --git a/gen.go b/gen.go new file mode 100644 index 0000000..ae15f9c --- /dev/null +++ b/gen.go @@ -0,0 +1,30 @@ +// +build ignore + +package main + +import ( + "flag" + "io/ioutil" + "log" + "os" +) + +var flOutput = flag.String("o", "", "output file to write") + +func main() { + flag.Parse() + err := ioutil.WriteFile(*flOutput, []byte(source), os.FileMode(0644)) + if err != nil { + log.Fatal(err) + } +} + +var source = ` +package main + +import "fmt" + +func foo() { + fmt.Println("brrnnt") +} +` diff --git a/run.go b/run.go new file mode 100644 index 0000000..72543d9 --- /dev/null +++ b/run.go @@ -0,0 +1,5 @@ +package main + +func main() { + foo() +}