Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/perfectcommerce/buildconstants
Generate a Go file with the output of compile time shell commands
https://github.com/perfectcommerce/buildconstants
Last synced: 21 days ago
JSON representation
Generate a Go file with the output of compile time shell commands
- Host: GitHub
- URL: https://github.com/perfectcommerce/buildconstants
- Owner: perfectcommerce
- License: mit
- Created: 2016-05-17T17:19:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T19:18:43.000Z (over 3 years ago)
- Last Synced: 2024-08-05T15:05:09.869Z (4 months ago)
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 19
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
- awesome - buildconstants - Generate a Go file with the output of compile time shell commands (Go)
README
## buildconstants
### for putting build info (and other compile-time values) in Go constantsSometimes it can be useful to include constants that were available at compile-time, the build number, git branch, etc.
This utility will generate a go file with constants that are the output of various commands.
While you could do something similar with linker flags, this is intended for constants (and doesn't add args to your build command).The goal is to be able to include this in a go generate comment so the file will be automatically created as necessary.
It does include a constant `MustRunBuildConstants` so that the file with the go generate statement can be used to force a useful compiler error
## Example of using with go generate
example.go:
//go:generate buildconstants
// this will generate a compiler error to remind you to run it
var _ = MustRunBuildConstants
## Example:
Given a text file with shell commands, like so:
GOVERSION = go version
BUILD_NUMBER = ${BUILD_NUMBER}
Running `go generate` before building will evaluate the commands and variables in the shell.
This will be used to generate something like:
package currentPackage
const (
GOVERSION = "go version go1.6.2 linux/amd64"
)
Which then allows you to use `currentPackage.GOVERSION` in your code.## Arguments
-o output file name (writes to stdout if not specified)
-package the package the file will be in (defaults to current package)
-i input file of commands## Note:
Don't use this to put date or time related data in constants, your builds should still be [reproducible](https://reproducible-builds.org/), which is necessary for using tools like [bazel](http://bazel.io).## TODO:
Check against newer versions
## LicenseMIT