Closed kvii closed 10 months ago
🤖
Hello @kvii!
I'm Dosu, a bot here to assist you with your coding needs while we wait for a human maintainer. I'm equipped with a dash of sarcasm and humor, and I aim to make your experience as smooth as possible. Feel free to ask me anything about bug fixes, questions, or how to become a contributor. Let's navigate the tech world together!
Unfortunately, you cannot directly replace the find
command with "api/*/.proto" in the Makefile. The shell command substitution $(shell ...)
in Makefile does not support globbing (wildcards) in the same way as a regular shell does.
However, you can achieve the same result by using a different approach. You can use the shell
function with find
command in Makefile to get all the '.proto' files in all subdirectories. Here is how you can do it:
ifeq ($(GOHOSTOS), windows)
Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name '*.proto'")
API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name '*.proto'")
else
INTERNAL_PROTO_FILES=$(shell find internal -name '*.proto')
API_PROTO_FILES=$(shell find api -name '*.proto')
endif
In this code, find internal -name '*.proto'
and find api -name '*.proto'
will find all '.proto' files in 'internal' and 'api' directories respectively, including subdirectories. The results are stored in INTERNAL_PROTO_FILES
and API_PROTO_FILES
variables, which can be used later in the Makefile.
The 'find' command was chosen for use in the Makefile because it is a powerful and flexible command-line utility that allows you to search for files and directories in a directory hierarchy based on a user-given expression. In this case, it is used to find all the '.proto' files in the 'internal' and 'api' directories.
The 'find' command is widely available on Unix-like operating systems, making it a good choice for cross-platform scripts. However, the 'find' command in Windows is different from the Unix-like 'find' command. To handle this, the Makefile uses 'git-bash.exe' to run the 'find' command on Windows, as it is expected that every developer has Git installed.
I hope this helps! If you have any other questions, feel free to ask.
Best regards, Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Expanding paths, such as "**" or "~", is supported by shell. The received filenames are expanded by shell, not by the application. For example, if the command line argument is ".proto", the application will receive "a.proto" and "b.proto". And the syntax "**/\.proto" is only supported by zsh. It can be used in Makefile. Here is a screenshot for this behavior.
I can execute this command to compile all '.proto' files.
Note I've used "api/*/.proto" to match proto fille in all subdirectories. It's more elegant than use find command in Makefile. Can we use it in Makefile?
Code "it's hard to use
find
on windows":https://github.com/go-kratos/kratos-layout/blob/ba85299c79673dd1c13ca06bcc15e3b2e2b265f7/Makefile#L5-L16