Skip to content
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

Makefile: refactor 'woke', wrap longer lines #86

Merged
merged 2 commits into from
Sep 5, 2023
Merged

Conversation

akcano
Copy link
Contributor

@akcano akcano commented Aug 30, 2023

This aims to extract the installation logic of the 'make woke' target into other targets while making the process more explicit for the user with echo commands.

Some of the longer recipe lines affected by this could benefit from wrapping, so a related change is added as a follow-up.

@akcano akcano requested review from ru-fu and lblythen August 30, 2023 17:07
@akcano akcano self-assigned this Aug 30, 2023
Copy link
Contributor

@lblythen lblythen left a comment

Choose a reason for hiding this comment

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

Haven't tested, but LGTM. .PHONY after the target not before it isn't a style I've seen. Can't see any problem with it but I'm intrigued: what's the reason?

@akcano
Copy link
Contributor Author

akcano commented Aug 31, 2023

@lblythen adding a .PHONY directive per each target localises the context, avoiding extra scrolling and potential discrepancies; placing the directive after the target is a style preference, nothing else.

Makefile Outdated
rm -rf $(VENVDIR)
@{ echo "Removing \"woke\" snap... \n"; sudo snap remove woke; }
Copy link
Contributor

Choose a reason for hiding this comment

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

No, we can't do that - I have woke already installed on my system, clean shouldn't remove it.

There's probably no way to install woke locally somehow in case it's not installed globally, or is there? That would be cleaner, and then it could of course also be removed afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I believe this is the answer:
https://snapcraft.io/docs/parallel-installs
Do you like this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general yes - but we can't reconfigure snapd and reboot the machine. :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe @degville has some suggestion here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ru-fu Perhaps we can drop the remove part for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure - the other changes all look good to me. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@pmatulis
Copy link

I'd like to see use improve the initial descriptions in some of these PRs.

@akcano
Copy link
Contributor Author

akcano commented Aug 31, 2023

@pmatulis can you please elaborate?

@pmatulis
Copy link

@akcano In the initial PR's description field we should describe the PR.

@akcano akcano changed the title Makefile: final improvement series (for now) Makefile: refactor 'woke', wrap longer lines Aug 31, 2023
@akcano
Copy link
Contributor Author

akcano commented Aug 31, 2023

@pmatulis I added some details; looks better now?

Makefile Outdated
Comment on lines 83 to 85
@test ! -e "$(VENVDIR)" -o -d "$(VENVDIR)" \
-a "$(abspath $(VENVDIR))" != "$(VENVDIR)"
rm -rf $(VENVDIR)
Copy link
Contributor

@lblythen lblythen Sep 4, 2023

Choose a reason for hiding this comment

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

If "$(VENVDIR)" doesn't exist, ! -e "$(VENVDIR)" will be TRUE. Short-circuit evaluation will yield TRUE for the whole @test statement, so make will continue instead of quitting: rm -rf $(VENVDIR) will be performed on a non-existent $VENVDIR.

Otherwise make clean's working because:

  • VENVDIR's set to .sphinx/venv which generally exists when make clean is run
  • Therefore ! -e "$(VENVDIR)" is FALSE, but there's a -o expression which @test therefore must evaluate
  • -d "$(VENVDIR" is TRUE (.sphinx/venv is a directory), but there's a -a expression which must also be evaluated
  • "$(abspath $(VENVDIR))" generally isn't identical to "$(VENVDIR)", so the -a expression is TRUE.
  • FALSE OR TRUE AND TRUE yields TRUE, so make continues: rm -rf $(VENVDIR) is performed.

It's good practice to wrap lines in a way that emphasises operator precedence rather than disguising it - it makes errors easier to spot. At present:

@test ! -e "$(VENVDIR)" -o -d "$(VENVDIR)" \
-a ...

keeps two expressions together with -o between them and splits the line between two expressions associated through -a, as if -o has higher precedence than -a. Ignoring problems with the logic, a representation less prone to being misinterpreted would be:

@test ! -e "$(VENVDIR)" -o \
-d "$(VENVDIR)" -a "$(abspath $(VENVDIR))" != "$(VENVDIR)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally, I think trying to delete a non-existent directory is not an issue at this moment. Technically, it's a no-op; we could stop to report instead of silently falling through, yes, but that goes beyond the scope of Makefile's current state. After all, this simply preserves current behaviour but adds safeguards.

Regarding the line wrapping: you're right, this reads better.

Copy link
Contributor

@ru-fu ru-fu left a comment

Choose a reason for hiding this comment

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

LGTM!

@akcano akcano merged commit 3214ed7 into canonical:main Sep 5, 2023
3 checks passed
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.

4 participants