From bc0ae93dc6cac79b817811367783289ef4cae9a5 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 24 Mar 2020 13:51:10 -0400 Subject: [PATCH 1/3] Added -t for specifying conditional build tags --- cmd/pkger/cmds/pack.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/pkger/cmds/pack.go b/cmd/pkger/cmds/pack.go index 7973e54..adf917e 100644 --- a/cmd/pkger/cmds/pack.go +++ b/cmd/pkger/cmds/pack.go @@ -30,6 +30,7 @@ const outName = "pkged.go" type packCmd struct { *flag.FlagSet out string + tags string help bool include slice subs []command @@ -53,7 +54,7 @@ func (e *packCmd) Exec(args []string) error { return err } - if err := Package(info, fp, decls); err != nil { + if err := Package(info, fp, decls, e.tags); err != nil { return err } @@ -104,6 +105,7 @@ func New() (*packCmd, error) { c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError) c.BoolVar(&c.help, "h", false, "prints help information") c.StringVar(&c.out, "o", "", "output directory for pkged.go") + c.StringVar(&c.tags, "t", "", "conditional build tag(s) for pkged.go") c.Var(&c.include, "include", "packages the specified file or directory") c.Usage = func() { fmt.Fprintf(os.Stderr, "Usage:\n\n") @@ -123,7 +125,7 @@ func (e *packCmd) Flags() *flag.FlagSet { return e.FlagSet } -func Package(info here.Info, out string, decls parser.Decls) error { +func Package(info here.Info, out string, decls parser.Decls, tags string) error { c, err := here.Dir(filepath.Dir(out)) if err != nil { return err @@ -142,6 +144,9 @@ func Package(info here.Info, out string, decls parser.Decls) error { } defer f.Close() + if len(tags) > 0 { + fmt.Fprintf(f, "// +build %s\n\n", tags) + } fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n") fmt.Fprintf(f, "package %s\n\n", c.Name) fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t") From 331c57067b5d51fb8c01b82debc4612b9e575ff2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 24 Mar 2020 14:02:20 -0400 Subject: [PATCH 2/3] Moved build tags below code generation warning --- cmd/pkger/cmds/pack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/pkger/cmds/pack.go b/cmd/pkger/cmds/pack.go index adf917e..51af2ec 100644 --- a/cmd/pkger/cmds/pack.go +++ b/cmd/pkger/cmds/pack.go @@ -144,10 +144,10 @@ func Package(info here.Info, out string, decls parser.Decls, tags string) error } defer f.Close() + fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n") if len(tags) > 0 { fmt.Fprintf(f, "// +build %s\n\n", tags) } - fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n") fmt.Fprintf(f, "package %s\n\n", c.Name) fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t") fmt.Fprintf(f, "\"github.com/markbates/pkger/pkging/mem\"\n)\n\n") From 3c88c54d65b03877afe439d6a73d51112bf5db2a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 24 Mar 2020 14:14:21 -0400 Subject: [PATCH 3/3] Removed optional tags with one tag, !skippkger --- cmd/pkger/cmds/pack.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmd/pkger/cmds/pack.go b/cmd/pkger/cmds/pack.go index 51af2ec..5b5f226 100644 --- a/cmd/pkger/cmds/pack.go +++ b/cmd/pkger/cmds/pack.go @@ -30,7 +30,6 @@ const outName = "pkged.go" type packCmd struct { *flag.FlagSet out string - tags string help bool include slice subs []command @@ -54,7 +53,7 @@ func (e *packCmd) Exec(args []string) error { return err } - if err := Package(info, fp, decls, e.tags); err != nil { + if err := Package(info, fp, decls); err != nil { return err } @@ -105,7 +104,6 @@ func New() (*packCmd, error) { c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError) c.BoolVar(&c.help, "h", false, "prints help information") c.StringVar(&c.out, "o", "", "output directory for pkged.go") - c.StringVar(&c.tags, "t", "", "conditional build tag(s) for pkged.go") c.Var(&c.include, "include", "packages the specified file or directory") c.Usage = func() { fmt.Fprintf(os.Stderr, "Usage:\n\n") @@ -125,7 +123,7 @@ func (e *packCmd) Flags() *flag.FlagSet { return e.FlagSet } -func Package(info here.Info, out string, decls parser.Decls, tags string) error { +func Package(info here.Info, out string, decls parser.Decls) error { c, err := here.Dir(filepath.Dir(out)) if err != nil { return err @@ -145,9 +143,7 @@ func Package(info here.Info, out string, decls parser.Decls, tags string) error defer f.Close() fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n") - if len(tags) > 0 { - fmt.Fprintf(f, "// +build %s\n\n", tags) - } + fmt.Fprintf(f, "// +build !skippkger\n\n") fmt.Fprintf(f, "package %s\n\n", c.Name) fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t") fmt.Fprintf(f, "\"github.com/markbates/pkger/pkging/mem\"\n)\n\n")