8000 Makefile: Ensure goyacc is installed before calling it by zhengkezhou1 · Pull Request #16202 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Makefile: Ensure goyacc is installed before calling it #16202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conve 10000 rsation

zhengkezhou1
Copy link
Contributor

Why is this change needed?

When following the steps to contribute and running make test for the first time, we encounter:

>> cleaning generated parser
>> running goyacc to generate the .go file.
make: /go/bin/goyacc: Command not found
make: *** [Makefile:123: promql/parser/generated_parser.y.go] Error 127

However, there are no instructions indicating that goyacc should be installed before running the tests. Additionally, we can automate the installation of goyacc to simplify the setup process and reduce manual steps.

Copy link
Member
@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Makefile Outdated
@@ -120,6 +120,9 @@ endif

promql/parser/generated_parser.y.go: promql/parser/generated_parser.y
@echo ">> running goyacc to generate the .go file."
ifeq (,$(shell command -v goyacc 2> /dev/null))
$(MAKE) install-goyacc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind doing the same for 115 line while we are here? For consistency, I think it's ok to auto-install on parser command too, no?

Also I don't know why don't rely on Makefile dependency logic (e.g. promql/parser/generated_parser.y.go: promql/parser/generated_parser.y $(goyacc), but it's fine to fix later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have improved.

Signed-off-by: zhengkezhou1 <madzhou1@gmail.com>
Copy link
Member
@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, one more suggestion!

Comment on lines +112 to +123
parser: promql/parser/generated_parser.y.go

promql/parser/generated_parser.y.go: promql/parser/generated_parser.y
@$(MAKE) install-goyacc
@echo ">> running goyacc to generate the .go file."
@$(FIRST_GOPATH)/bin/goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y

.PHONY: install-goyacc
install-goyacc:
@echo ">> installing goyacc $(GOYACC_VERSION)"
@go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not ideal as it always reinstall. This might work (and it's safer as we pin binary version)

Suggested change
8000
parser: promql/parser/generated_parser.y.go
promql/parser/generated_parser.y.go: promql/parser/generated_parser.y
@$(MAKE) install-goyacc
@echo ">> running goyacc to generate the .go file."
@$(FIRST_GOPATH)/bin/goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y
.PHONY: install-goyacc
install-goyacc:
@echo ">> installing goyacc $(GOYACC_VERSION)"
@go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)
parser: promql/parser/generated_parser.y.go
GOYACC = $(FIRST_GOPATH)/bin/goyacc-$(GOYACC_VERSION)
$(GOYACC):
@echo ">> installing goyacc $(GOYACC_VERSION)"
@go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)
@cp $(FIRST_GOPATH)/bin/goyacc $(GOYACC)
@rm $(FIRST_GOPATH)/bin/goyacc
promql/parser/generated_parser.y.go: promql/parser/generated_parser.y $(GOYACC)
@echo ">> running goyacc to generate the .go file."
@$(FIRST_GOPATH)/bin/goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't rm the goyacc binary as this is a shared directory and someone could have manually installed it for another use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, here is my idea:

  1. If goyacc is already installed locally, rename the existing goyacc executable to goyacc<old-version>, install the desired version of goyacc and rename it to goyacc<old-version>, then restore the original goyacc by renaming goyacc<old-version> back to goyacc.

  2. If goyacc is not installed locally, simply install the desired version and rename the executable to goyacc<version>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to check that the version match what we expect instead of modifying other binaries/directories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found a new solution: After upgrading to Go 1.24, the go get command has introduced a new flag -tool, which makes managing tools much more convenient now.

Please Take a look: 🚀✨

go get -tool golang.org/x/tools/cmd/goyacc@v0.6.0
go: added golang.org/x/tools v0.6.0

image

@github-actions github-actions bot added the stale label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0