From 3f4e13f6e7844f2a25a953a6dd4689847c5cdba4 Mon Sep 17 00:00:00 2001 From: Jade Guiton Date: Tue, 19 Nov 2024 21:53:41 +0100 Subject: [PATCH] [chore] `make generate` uses `.tools/mdatagen` (#36416) #### Description This PR is in the context of [this PR on the core Collector modifying `make check-contrib` to use the latest version of `mdatagen`](https://github.com/open-telemetry/opentelemetry-collector/pull/11670). The `make generate` commands currently starts by compiling build tools in the `.tools` folder, then it `go install`s mdatagen globally for use in `go:generate`. Unfortunately, `go install` does not take into account the version of `mdatagen` referenced in `internal/tools/go.mod`. This means it isn't possible to generate using the local version of `mdatagen` for testing, even with `replace` statements. This PR fixes this by prepending `.tools` to the `$PATH` before running the generate command, which makes `go:generate` use the version of `mdatagen` in that folder instead of a global one. (Originally, this PR also added a new `modgenerate` target in `Makefile.Common`, to allow running generate commands on a specific group of modules instead of all of them for efficiency reasons. After discussing it with @mx-psi, we decided to hold off on that change for a later PR, as it warrants further discussion.) --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 86ecba3a3276..40f4df619c81 100644 --- a/Makefile +++ b/Makefile @@ -307,8 +307,7 @@ docker-telemetrygen: .PHONY: generate generate: install-tools - cd ./internal/tools && go install go.opentelemetry.io/collector/cmd/mdatagen - $(MAKE) for-all CMD="$(GOCMD) generate ./..." + PATH="$$PWD/.tools:$$PATH" $(MAKE) for-all CMD="$(GOCMD) generate ./..." $(MAKE) gofmt .PHONY: githubgen-install