Fix linker flags inclusion in build comamnd

This commit is contained in:
Laurin
2020-02-10 10:35:43 +01:00
parent 531aa1e209
commit 424474a035

View File

@@ -136,10 +136,14 @@ func Build(c *model.CommandConfig, paths *model.RevelContainer) (_ *App, err err
} }
for { for {
appVersion := getAppVersion(paths) appVersion := getAppVersion(paths)
if appVersion == "" {
appVersion = "noVersionProvided"
}
buildTime := time.Now().UTC().Format(time.RFC3339) buildTime := time.Now().UTC().Format(time.RFC3339)
versionLinkerFlags := fmt.Sprintf("-X %s/app.AppVersion=%s -X %s/app.BuildTime=%s", versionLinkerFlags := fmt.Sprintf("-X '%s/app.AppVersion=%s' -X '%s/app.BuildTime=%s'",
paths.ImportPath, appVersion, paths.ImportPath, buildTime) paths.ImportPath, appVersion, paths.ImportPath, buildTime)
// Append any build flags specified, they will override existing flags // Append any build flags specified, they will override existing flags
@@ -155,9 +159,13 @@ func Build(c *model.CommandConfig, paths *model.RevelContainer) (_ *App, err err
if !contains(c.BuildFlags, "build") { if !contains(c.BuildFlags, "build") {
flags = []string{"build"} flags = []string{"build"}
} }
flags = append(flags, c.BuildFlags...)
if !contains(flags, "-ldflags") { if !contains(flags, "-ldflags") {
flags = append(flags, "-ldflags", versionLinkerFlags) ldflags := "-ldflags= " + versionLinkerFlags
// Add in build flags
for i := range c.BuildFlags {
ldflags += "-X '" + c.BuildFlags[i] + "'"
}
flags = append(flags, ldflags)
} }
if !contains(flags, "-tags") { if !contains(flags, "-tags") {
flags = append(flags, "-tags", buildTags) flags = append(flags, "-tags", buildTags)
@@ -167,9 +175,6 @@ func Build(c *model.CommandConfig, paths *model.RevelContainer) (_ *App, err err
} }
} }
// Add in build flags
flags = append(flags, c.BuildFlags...)
// This is Go main path // This is Go main path
gopath := c.GoPath gopath := c.GoPath
for _, o := range paths.ModulePathMap { for _, o := range paths.ModulePathMap {
@@ -400,7 +405,7 @@ func newCompileError(paths *model.RevelContainer, output []byte) *utils.Error {
// Extract the paths from the gopaths, and search for file there first // Extract the paths from the gopaths, and search for file there first
gopaths := filepath.SplitList(build.Default.GOPATH) gopaths := filepath.SplitList(build.Default.GOPATH)
for _, gp := range gopaths { for _, gp := range gopaths {
newPath := filepath.Join(gp,"src", paths.ImportPath, relFilename) newPath := filepath.Join(gp, "src", paths.ImportPath, relFilename)
println(newPath) println(newPath)
if utils.Exists(newPath) { if utils.Exists(newPath) {
return newPath return newPath
@@ -411,7 +416,6 @@ func newCompileError(paths *model.RevelContainer, output []byte) *utils.Error {
return newPath return newPath
} }
// Read the source for the offending file. // Read the source for the offending file.
var ( var (
relFilename = string(errorMatch[1]) // e.g. "src/revel/sample/app/controllers/app.go" relFilename = string(errorMatch[1]) // e.g. "src/revel/sample/app/controllers/app.go"