From 8402d724a9b632cbf359a44444cdb069392ab9c6 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 27 Jun 2018 11:39:46 -0400 Subject: [PATCH] basic generation Signed-off-by: Vincent Batts --- Makefile | 12 ++++++++++++ g.go | 5 +++++ gen.go | 30 ++++++++++++++++++++++++++++++ run.go | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 Makefile create mode 100644 g.go create mode 100644 gen.go create mode 100644 run.go 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() +}