Skip to content

[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

Conversation

sstok
Copy link
Contributor

@sstok sstok commented May 4, 2017

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:

.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?

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"; \
Copy link
Member

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 ?

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 😄

@sstok
Copy link
Contributor Author

sstok commented May 4, 2017

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"; \
Copy link
Member

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
Copy link
Member

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"
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Contributor

@greg0ire greg0ire May 4, 2017

Choose a reason for hiding this comment

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

Strange but true.

Copy link
Contributor

@greg0ire greg0ire May 4, 2017

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)

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sstok sstok force-pushed the 49-framework-bundle-dont-advice-to-install-web-server-bundle-when-already-installed branch from 644b80a to 4c9590e Compare May 4, 2017 10:12
@sstok sstok force-pushed the 49-framework-bundle-dont-advice-to-install-web-server-bundle-when-already-installed branch from 4c9590e to b8fb6d3 Compare May 4, 2017 13:34
@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):
Copy link
Contributor

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)"

Copy link
Contributor Author

@sstok sstok May 5, 2017

Choose a reason for hiding this comment

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

Done. Slightly different.

schermafbeelding 2017-05-05 om 09 27 04

@sstok sstok force-pushed the 49-framework-bundle-dont-advice-to-install-web-server-bundle-when-already-installed branch from b8fb6d3 to 50107f4 Compare May 5, 2017 07:27
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"
Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented May 5, 2017

I've just tested and it works quite well. Well done!

Here is the output when console and the web server are not installed:

bin/console could not be found. Run composer require console to install the console.
You may use an alternate binary by using: make CONSOLE=path/to/console some_target

/bin/sh: bin/console: No such file or directory
Server listening on http://127.0.0.1:8000
Quit the server with CTRL-C.
Run composer require symfony/web-server-bundle for a better web server
php -S 127.0.0.1:8000 -t web
PHP 7.1.2 Development Server started at Fri May  5 09:17:46 2017
Listening on http://127.0.0.1:8000
Document root is /private/tmp/foobar/web
Press Ctrl-C to quit.

Is it possible to remove the /bin/sh: bin/console: No such file or directory part?

I think we should also use shortcuts when possible:

Run composer req cli to install the Symfony console.
Run composer req webserver for a better web server

@fabpot
Copy link
Member

fabpot commented May 5, 2017

Forgot to mention something: the bin/console could not be found. message should probably not be in red as the command works without it; so this is not an error to not have the console installed.

@sstok
Copy link
Contributor Author

sstok commented May 5, 2017

I'm away for today, so feel free to push new commits ;)

@sstok
Copy link
Contributor Author

sstok commented May 6, 2017

Is it possible to remove the /bin/sh: bin/console: No such file or directory part?

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
$ make serve
Run composer require cli to install the Symfony console.
Server listening on http://127.0.0.1:8000
Quit the server with CTRL-C.
Run composer require symfony/web-server-bundle for a better web server
php -S 127.0.0.1:8000 -t web
PHP 7.1.3 Development Server started at Sat May  6 11:45:52 2017
Listening on http://127.0.0.1:8000

@fabpot
Copy link
Member

fabpot commented May 11, 2017

@sstok your proposer changes look good to me.

@sstok sstok force-pushed the 49-framework-bundle-dont-advice-to-install-web-server-bundle-when-already-installed branch from 50107f4 to 7a7de4b Compare May 12, 2017 15:03
@sstok
Copy link
Contributor Author

sstok commented May 12, 2017

OK, all should be good now.

@sstok
Copy link
Contributor Author

sstok commented May 12, 2017

OK, should be good now 👍

@fabpot
Copy link
Member

fabpot commented May 12, 2017

Thank you @sstok.

@fabpot fabpot merged commit 7a7de4b into symfony:master May 12, 2017
fabpot added a commit that referenced this pull request May 12, 2017
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
Copy link
Member

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

@xabbuh xabbuh mentioned this pull request May 16, 2017
fabpot added a commit that referenced this pull request May 16, 2017
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
@sstok sstok deleted the 49-framework-bundle-dont-advice-to-install-web-server-bundle-when-already-installed branch August 29, 2017 16:49
markovlatkovic pushed a commit to markovlatkovic/recipes that referenced this pull request May 24, 2024
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
mo-melvin77 added a commit to mo-melvin77/recipes that referenced this pull request Jun 9, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants