Showing
4 changed files
with
138 additions
and
0 deletions
.gitignore
0 → 100644
Makefile
0 → 100644
| 1 | +PACKAGE = gitlab.weird-web-workers.org/golang/version | ||
| 2 | + | ||
| 3 | +SOURCES = version.go \ | ||
| 4 | + tools.go | ||
| 5 | + | ||
| 6 | +VERSION = 0.0.1 | ||
| 7 | +REVISION = $(shell git rev-parse HEAD) | ||
| 8 | +BUILDTIME= "$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" | ||
| 9 | + | ||
| 10 | +GOOS = $(shell go env GOOS) | ||
| 11 | +GOARCH = $(shell go env GOARCH) | ||
| 12 | + | ||
| 13 | +LIBRARY = $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(PACKAGE).a | ||
| 14 | + | ||
| 15 | +.PHONY: all clean .version | ||
| 16 | + | ||
| 17 | +all: $(LIBRARY) | ||
| 18 | + | ||
| 19 | +$(LIBRARY): $(SOURCES) | ||
| 20 | + go install $(PACKAGE) | ||
| 21 | + | ||
| 22 | +.version: | ||
| 23 | + -@printf "%s\n%s\n%s" \ | ||
| 24 | + "$(VERSION)" "$(REVISION)" "$(BUILDTIME)" >$@.new | ||
| 25 | + -@diff $@ $@.new >/dev/null 2>&1 && rm $@.new || mv $@.new $@ | ||
| 26 | + | ||
| 27 | +version.go: version.go.m4 .version | ||
| 28 | + -@m4 -Dm4_version=$(VERSION) \ | ||
| 29 | + -Dm4_revision=$(REVISION) \ | ||
| 30 | + -Dm4_build_time=$(BUILDTIME) \ | ||
| 31 | + -Dm4_package=$(PACKAGE) \ | ||
| 32 | + $< >$@ | ||
| 33 | + | ||
| 34 | +clean: | ||
| 35 | + -@rm -f version.go 2>/dev/null | ||
| 36 | + -@rm -f .version 2>/dev/null | ||
| 37 | + -@rm -f $(LIBRARY) 2>/dev/null |
tools.go
0 → 100644
| 1 | +/* | ||
| 2 | +Version management tools. | ||
| 3 | + | ||
| 4 | +Authors: | ||
| 5 | +Georg Hopp <georg@steffers.org> | ||
| 6 | + | ||
| 7 | +Changes: | ||
| 8 | +2018-10-02 [Georg Hopp] File created. | ||
| 9 | + | ||
| 10 | +Copyright © 2018 Georg Hopp | ||
| 11 | + | ||
| 12 | +This program is free software: you can redistribute it and/or modify | ||
| 13 | +it under the terms of the GNU General Public License as published by | ||
| 14 | +the Free Software Foundation, either version 3 of the License, or | ||
| 15 | +(at your option) any later version. | ||
| 16 | + | ||
| 17 | +This program is distributed in the hope that it will be useful, | ||
| 18 | +but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | +GNU General Public License for more details. | ||
| 21 | + | ||
| 22 | +You should have received a copy of the GNU General Public License | ||
| 23 | +along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 24 | +*/ | ||
| 25 | +package version | ||
| 26 | + | ||
| 27 | +import ( | ||
| 28 | + "encoding/json" | ||
| 29 | +) | ||
| 30 | + | ||
| 31 | +type Version struct { | ||
| 32 | + Package string `json:"Package"` | ||
| 33 | + Version string `json:"Version"` | ||
| 34 | + Revision string `json:"Revision"` | ||
| 35 | + BuildTime string `json:"BuildTime"` | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +type versionSlice map[string]Version | ||
| 39 | + | ||
| 40 | +var ( | ||
| 41 | + versions = make(versionSlice) | ||
| 42 | +) | ||
| 43 | + | ||
| 44 | +func (v Version) Register() { | ||
| 45 | + versions[v.Package] = v | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func (vs versionSlice)Json() string { | ||
| 49 | + vSlice := make([]Version, len(vs)) | ||
| 50 | + for v := range vs { | ||
| 51 | + vSlice = append(vSlice, v) | ||
| 52 | + } | ||
| 53 | + vJson, err := json.Marshal(vSlice) | ||
| 54 | + logger.Default.FailOnError(err, "Unable to marshal versions") | ||
| 55 | + return vJson | ||
| 56 | +) | ||
| 57 | + | ||
| 58 | +// vim: ts=4 sts=4 sw=4 noet tw=72: |
version.go.m4
0 → 100644
| 1 | +/* | ||
| 2 | +Package version information. | ||
| 3 | + | ||
| 4 | +Authors: | ||
| 5 | +Georg Hopp <georg@steffers.org> | ||
| 6 | + | ||
| 7 | +Changes: | ||
| 8 | +2018-09-30 [Georg Hopp] File created. | ||
| 9 | + | ||
| 10 | +Copyright © 2018 Georg Hopp | ||
| 11 | + | ||
| 12 | +This program is free software: you can redistribute it and/or modify | ||
| 13 | +it under the terms of the GNU General Public License as published by | ||
| 14 | +the Free Software Foundation, either version 3 of the License, or | ||
| 15 | +(at your option) any later version. | ||
| 16 | + | ||
| 17 | +This program is distributed in the hope that it will be useful, | ||
| 18 | +but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | +GNU General Public License for more details. | ||
| 21 | + | ||
| 22 | +You should have received a copy of the GNU General Public License | ||
| 23 | +along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 24 | +*/ | ||
| 25 | +package version | ||
| 26 | + | ||
| 27 | +import ( | ||
| 28 | + "gitlab.weird-web-workers.org/golang/version" | ||
| 29 | +) | ||
| 30 | + | ||
| 31 | +const ( | ||
| 32 | + VERSION = Version{ | ||
| 33 | + Package: "m4_package", | ||
| 34 | + Version: "m4_version", | ||
| 35 | + Revision: "m4_revision", | ||
| 36 | + BuildTime: "m4_build_time", | ||
| 37 | + } | ||
| 38 | +) | ||
| 39 | + | ||
| 40 | +// vim: ts=4 sts=4 sw=4 noet tw=72: |
Please
register
or
login
to post a comment