From bc8bcf88c42796d4edf081bb3c38ce22094c6677 Mon Sep 17 00:00:00 2001 From: Patrick Gaskin Date: Sat, 10 Oct 2020 10:34:04 -0400 Subject: [PATCH] Require Go Modules to build (#902) * Add module info to version * Add warning if built without Go modules * Updated source installation instructions for Go modules --- README.md | 2 +- main.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba7a5cb64..92c207e87 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ To install, simply run To download the source - go get -d github.com/StackExchange/dnscontrol + git clone github.com/StackExchange/dnscontrol If these don't work, more info is in [#805](https://github.com/StackExchange/dnscontrol/issues/805). diff --git a/main.go b/main.go index a5f0c4e17..dfd151548 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "runtime/debug" "strconv" "time" @@ -15,6 +16,9 @@ import ( func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) + if info, ok := debug.ReadBuildInfo(); !ok && info == nil { + fmt.Fprint(os.Stderr, "Warning: dnscontrol was built without Go modules. See https://github.com/StackExchange/dnscontrol#from-source for more information on how to build dnscontrol correctly.\n\n") + } os.Exit(commands.Run(versionString())) } @@ -36,6 +40,9 @@ func versionString() string { } else { version = fmt.Sprintf("%s-dev", Version) // no SHA. '0.x.y-dev' indicates it is run from source without build script. } + if info, ok := debug.ReadBuildInfo(); !ok && info == nil { + version += " (non-modules)" + } if BuildTime != "" { i, err := strconv.ParseInt(BuildTime, 10, 64) if err == nil {