Skip to content

Conversation

@per1234
Copy link
Contributor

@per1234 per1234 commented Aug 27, 2021

The go:build task has an LDFLAGS taskfile template variable, which is currently used by some projects (example) to inject the versioning information while building via an -ldflags flag.

go test has undocumented support for an -ldflags flag as well. Projects might find it useful to be able to set the value of string variables in the code while running the tests (example). To provide support by the template task for this use case, a TEST_LDFLAGS taskfile template variable is added to the go test command in the go:test task, as well as empty definition of the variable. This can be left empty if the project doesn't have any need for the capability.

This variable has a specific usage in the release-go-task template for injecting versioning information during the
builds. The `go:build` task is intended for use by all Go application projects, even if the release system is not
applicable. For this reason, the "go-task" template taskfile contains an empty `LDFLAGS` taskfile variable definition,
which may be defined with any `-ldflags` flag the project might need for its build, or left empty if the project does
not have any need for such a flag.

The usage of this variable might not be clear to the template user, so a "TODO" comment is added, which will be removed
during the installation of the "template" in a project. In the event the variable it is left empty, its presence in the
taskfile might be the source of confusion, and so a permanent explanatory comment is also provided.
The `go:build` task has an `LDFLAGS` taskfile template variable, which is currently used by some projects to inject the
versioning information while building via an `-ldflags` flag.

`go test` has undocumented support for an `-ldflags` flag as well. Projects might find it useful to be able to set the
value of string variables in the code while running the tests. To provide support by the template task for this use case,
a `TEST_LDFLAGS` taskfile template variable is added to the `go test` command in the `go:test` task, as well as empty
definition of the variable. This can be left empty if the project doesn't have any need for the capability.
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Aug 27, 2021
@per1234 per1234 requested review from rsora and silvanocerza August 27, 2021 10:54
@per1234 per1234 merged commit 56f8ae6 into arduino:main Aug 27, 2021
@per1234 per1234 deleted the test-ldflags branch August 27, 2021 12:20
@per1234 per1234 self-assigned this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: code Related to content of the project itself type: enhancement Proposed improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants