Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Please add a pre_build_example.go to inject a custom version #118

Open
robertranjan opened this issue Apr 23, 2023 · 3 comments
Open

Please add a pre_build_example.go to inject a custom version #118

robertranjan opened this issue Apr 23, 2023 · 3 comments
Assignees
Labels

Comments

@robertranjan
Copy link
Contributor

I found this tool from awesome-go and liked as it has the pre_build, post_build hooks. I couldn't figure out how to inject some build vars or update existing ones. It'd appreciated if you add a pre_build_example.go to inject some build parameters.

Looked at the code but not sure how it works...

By the time you call the preHook all set(everything read into memory) for the build. Not sure, how to inject build params/variables.

-- snip from ./internal/builder/builder.go ---

if err := builder.RunProjectHook(project, common.ScriptPreBuild, buildArgs); err != nil {
	return err
}

if err := builder.RunToStdout(
	buildCmd,
	project.Path,
	map[string]string{
		"GO111MODULE": "on",
		"GOOS":        builder.GOOS,
		"GOARCH":      builder.GOARCH,
	},
); err != nil {
	return err
}

return builder.RunProjectHook(project, common.ScriptPostBuild, buildArgs)

pre_build_example.go for below would be nice:

  • how to add an additional -X flag to --ldflag?
  • how to update version to add some .xyz suffix?
@pieterclaerhout
Copy link
Owner

Hi Robert,

currently, what you are trying to achieve won't be possible.

I'll see if I can move the call of the project hook earlier in the process and expose the --ldflags options so that you can add something to it.

@robertranjan
Copy link
Contributor Author

@pieterclaerhout, is below a good idea?

  • update builder.go to write the buildCmd to a local file
  • pre_build.go read the file and update as needed
  • builder.go re-read the file and proceed with builder.RunToStdout

@pieterclaerhout
Copy link
Owner

@robertranjan that might actually be a good idea. The tricky part is that the pre and post build scripts can also be shell scripts.

I'll try to make some time next week to look into this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants