-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Verify more constants are not loaded at startup #18012
Merged
apainintheneck
merged 1 commit into
Homebrew:master
from
apainintheneck:verify-more-constants-not-loaded-at-startup
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
Library/Homebrew/test/support/helper/cmd/brew-verify-formula-undefined.rb
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "cli/parser" | ||
|
||
UNDEFINED_CONSTANTS = %w[ | ||
Cask::Cask | ||
Formula | ||
Formulary | ||
Homebrew::API | ||
Tap | ||
].freeze | ||
|
||
module Homebrew | ||
module Cmd | ||
class VerifyUndefined < AbstractCommand | ||
end | ||
end | ||
end | ||
|
||
parser = Homebrew::CLI::Parser.new(Homebrew::Cmd::VerifyUndefined) do | ||
usage_banner <<~EOS | ||
`verify-undefined` | ||
|
||
Verifies that the following constants have not been defined | ||
at startup to make sure that startup times stay consistent. | ||
|
||
Contants: | ||
#{UNDEFINED_CONSTANTS.join("\n")} | ||
EOS | ||
end | ||
|
||
parser.parse | ||
|
||
UNDEFINED_CONSTANTS.each do |constant_name| | ||
Object.const_get(constant_name) | ||
ofail "#{constant_name} should not be defined at startup" | ||
rescue NameError | ||
# We expect this to error as it should not be defined. | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice work @apainintheneck! Any other big constants you think we could add in here? I'm happy to take a look and suggest some if that's be helpful. My thinking would just be to add various
require
toglobal.rb
and usebrew prof
to see which ones have the biggest impact on abrew ruby -e 'puts :foo'
(or similar quick command that goes through Ruby-land) output.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.
There are a few more that we don't want to be loaded at start up but they are required by some of the existing files in this list so it's not strictly necessary to add them here. I'm thinking of
FormulaInstaller
andKeg
in this case. That being said the check here is really simple so there is essentially no cost to us expanding this list. Feel free to take a look and add any that seem mildly suspicious to the list.Homebrew::API
is an example of a borderline one that I decided to add on a whim.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.
Thanks @apainintheneck. Inspired by your great work here: I've opened #18065 as a follow-up.
I feel pretty confident after this that I can stop asking people to not add them to
global.rb
as CI will now catch this instead. Couldn't have done it without your idea here, wonderful stuff 👏🏻 😍