-
-
Notifications
You must be signed in to change notification settings - Fork 496
[FrameworkBundle] improve Makefile serve target #54
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
[FrameworkBundle] improve Makefile serve target #54
Conversation
php -S 127.0.0.1:8000 -t web | ||
@if [ -a bin/console ] && [[ `bin/console list server | grep server:start` ]]; then \ | ||
bin/console server:start; \ | ||
echo -e "Quit the server with \033[32;49mbin/console server:stop.\033[39m"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it already displayed by the server:start command itself ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, [OK] Server listening on http://127.0.0.1:8000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, it is only explained in the command help indeed, not when running the command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, if we want to be consistent with the alternate case, which is blocking, this case may need to run server:run
instead. Not sure whether consistency is the key here though. What do you think @fabpot ?
php -S 127.0.0.1:8000 -t web | ||
|
||
serve: | ||
@${MAKE} serve_as_sf || ${MAKE} serve_as_php | ||
.PHONY: serve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have 2 .PHONY declarations now :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For serve? Note that multiple .PHONY's is perfectly valid, and this was already used. The Makefiles are combined together so you don't have one absolute header section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL. But you should add serve_as_sf
and serve_as_php
there too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, also found a way to suppress the make error when the command doesn't exist 😄
I made a different version with suggestions from @greg0ire 👍 I really need to learn how to fully utilize Makefile. |
php -S 127.0.0.1:8000 -t web | ||
@if [ -a bin/console ] && [[ `bin/console list server | grep server:start` ]]; then \ | ||
bin/console server:start; \ | ||
echo -e "Quit the server with \033[32;49mbin/console server:stop.\033[39m"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, if we want to be consistent with the alternate case, which is blocking, this case may need to run server:run
instead. Not sure whether consistency is the key here though. What do you think @fabpot ?
|
||
serve_as_sf: $(CONSOLE) | ||
@$(CONSOLE)|grep server:start > /dev/null | ||
@$(CONSOLE) server:start || exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks wrong to me. If there is a failure in the command, we want to report it in the main exit code, to let the external system know that it failed
@echo "Quit the server with CTRL-C." | ||
@echo -e "Run \033[32mcomposer require symfony/web-server-bundle\033[39m for a better web server" | ||
@echo "Run \033[32mcomposer require symfony/web-server-bundle\033[39m for a better web server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing -e
breaks the support of colors AFAIK (you are reverting #48)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because when I use this is shows -e Run composer require symfony/web-server-bundle for a better web server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange but true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My colleague @L-P :
use
printf
, it's more portable, you don't know what echo really is here (shell built-in, make built-in, whatever)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(no flag is required for printf
, BTW)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's back that up with a very solid source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for printf also, that's really the portable way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
644b80a
to
4c9590e
Compare
4c9590e
to
b8fb6d3
Compare
@echo "Quit the server with CTRL-C." | ||
@echo -e "Run \033[32mcomposer require symfony/web-server-bundle\033[39m for a better web server" | ||
CONSOLE=bin/console | ||
$(CONSOLE): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe : @printf "%s could not be found. You may use an alternate binary by specifying it like this : make CONSOLE=path/to/console some_target" "$(CONSOLE)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b8fb6d3
to
50107f4
Compare
CONSOLE=bin/console | ||
$(CONSOLE): | ||
@printf "\033[31;49m%s could not be found.\033[39m Run \033[32mcomposer require console\033[39m to install the console.\n" "$(CONSOLE)" | ||
@printf "You may use an alternate binary by using: make CONSOLE=path/to/console some_target\n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this second line as I don't see when one would need this.
I've just tested and it works quite well. Well done! Here is the output when console and the web server are not installed:
Is it possible to remove the I think we should also use shortcuts when possible:
|
Forgot to mention something: the |
I'm away for today, so feel free to push new commits ;) |
No idea 😐 it's possible suppress errors in a rule but not when the rule itself itself it a target or something. I can make the console a rule but then you still need to check if console exists in each rule, is this acceptable? CONSOLE=bin/console
sf_console:
@test -f $(CONSOLE) || printf "Run \033[32mcomposer require cli\033[39m to install the Symfony console.\n"
@exit
serve_as_sf: sf_console
@test -f $(CONSOLE) && $(CONSOLE)|grep server:start > /dev/null || ${MAKE} serve_as_php
@$(CONSOLE) server:start || exit 0
@printf "Quit the server with \033[32;49mbin/console server:stop.\033[39m\n"
serve_as_php:
@printf "\033[32;49mServer listening on http://127.0.0.1:8000\033[39m\n";
@printf "Quit the server with CTRL-C.\n"
@printf "Run \033[32mcomposer require symfony/web-server-bundle\033[39m for a better web server\n"
php -S 127.0.0.1:8000 -t web
serve:
@${MAKE} serve_as_sf
.PHONY: sf_console serve serve_as_sf serve_as_php
|
@sstok your proposer changes look good to me. |
50107f4
to
7a7de4b
Compare
OK, all should be good now. |
OK, should be good now 👍 |
Thank you @sstok. |
This PR was merged into the master branch. Discussion ---------- [FrameworkBundle] improve Makefile serve target Related to #49, I don't know if this the best way to do it. But as the Makefile is composed I don't think it's possible to use advanced Makefile features 😟 @greg0ire suggested something like this: ```makefile .PHONY: serve CONSOLE=bin/console $(CONSOLE): @echo 'Woops! The console does not exist' @EXIT serve: bin/console bin/console list server|grep server:start bin/console server:start ``` But don't know if you can have multiple targets with the same name but different conditions? Commits ------- 7a7de4b [FrameworkBundle] improve Makefile serve target
|
||
serve_as_sf: sf_console | ||
@test -f $(CONSOLE) && $(CONSOLE)|grep server:start > /dev/null || ${MAKE} serve_as_php | ||
@$(CONSOLE) server:start || exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit with 1 when the server fails to start looks wrong to me
This PR was merged into the master branch. Discussion ---------- fix error exit code In case that the server could not start we should indicate the failure with a non-zero exit code. This addresses @stof's comment in #54 (comment). Commits ------- 9acb162 fix error exit code
This PR was merged into the master branch. Discussion ---------- fix error exit code In case that the server could not start we should indicate the failure with a non-zero exit code. This addresses @stof's comment in symfony/recipes#54 (comment). Commits ------- 9acb162 fix error exit code
This PR was merged into the master branch. Discussion ---------- fix error exit code In case that the server could not start we should indicate the failure with a non-zero exit code. This addresses @stof's comment in symfony/recipes#54 (comment). Commits ------- 9acb162 fix error exit code
Related to #49, I don't know if this the best way to do it. But as the Makefile is composed I don't think it's possible to use advanced Makefile features 😟
@greg0ire suggested something like this:
But don't know if you can have multiple targets with the same name but different conditions?