diff --git a/Makefile b/Makefile index 36c9272..d10b548 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ ifneq ($(origin TRAVIS_TAG), undefined) endif # Build -LDFLAGS = -X main.version=$(VERSION) -X main.build="$(BUILD)" +LDFLAGS = -X main.version=$(VERSION) -X main.build=$(BUILD) # Docker DOCKER_CMD = docker @@ -176,7 +176,7 @@ $(COMMANDS): echo ; \ echo "$${os} - $@"; \ GOOS=$${os} GOARCH=$${arch} $(GO_BUILD) $$([ $${os} = "linux" ] && echo -tags ostree) \ - --ldflags '$(LDFLAGS)' \ + --ldflags "$(LDFLAGS)" \ -o "$(BUILD_PATH)/$@_$${os}_$${arch}/$@" \ $(CMD_PATH)/$@/main.go; \ cd $(BUILD_PATH); \ diff --git a/cmd/bblfshd/main.go b/cmd/bblfshd/main.go index 11d9e46..288fd53 100644 --- a/cmd/bblfshd/main.go +++ b/cmd/bblfshd/main.go @@ -22,9 +22,14 @@ import ( "gopkg.in/bblfsh/sdk.v2/driver/manifest/discovery" ) +const ( + defaultBuild = "undefined" + buildDateFormat = "2006-01-02T15:04:05-0700" +) + var ( version = "undefined" - build = "undefined" + build = defaultBuild network *string address *string @@ -115,10 +120,16 @@ func main() { os.Exit(1) } - parsedBuild, err := time.Parse("2006-01-02T15:04:05-0700", build) + parsedBuild, err := time.Parse(buildDateFormat, build) if err != nil { - logrus.Errorf("wrong date format for build: %s", err) - os.Exit(1) + if build == defaultBuild { + parsedBuild = time.Now() + logrus.Infof("using start time instead in this dev build: %s", + parsedBuild.Format(buildDateFormat)) + } else { + logrus.Errorf("wrong date format for this build: %s", err) + os.Exit(1) + } } d := daemon.NewDaemon(version, parsedBuild, r, grpcOpts...) if args := cmd.Args(); len(args) == 2 && args[0] == "install" && args[1] == "recommended" { diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index 138bae8..ef489ca 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -18,6 +18,9 @@ import ( "github.com/bblfsh/bblfshd/runtime" ) +// actual date format used in bblfshd is different +const testBuildDate = "2019-01-28T16:49:06+01:00" + func TestDaemonState(t *testing.T) { require := require.New(t) @@ -121,9 +124,8 @@ func buildMockedDaemon(t *testing.T, images ...runtime.DriverImage) (*Daemon, st } } - bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00") - require.NoError(err) - d := NewDaemon("foo", bdate, r) + parsedBuild, err := time.Parse(time.RFC3339, testBuildDate) + d := NewDaemon("foo", parsedBuild, r) dp := NewDriverPool(func() (Driver, error) { return newEchoDriver(), nil diff --git a/daemon/service_test.go b/daemon/service_test.go index 1963556..01a03ec 100644 --- a/daemon/service_test.go +++ b/daemon/service_test.go @@ -48,7 +48,7 @@ func TestServiceVersion(t *testing.T) { require.Len(resp.Errors, 0) require.Equal(resp.Version, "foo") - bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00") + bdate, err := time.Parse(time.RFC3339, testBuildDate) require.NoError(err) require.Equal(resp.Build, bdate) }