Skip to content

Commit

Permalink
Add qpid_proton stubs for macs so we can run zeitwek:check
Browse files Browse the repository at this point in the history
We need to tell Rails autoloaders to ignore them on other platforms
because they won't define the expected constants.

Before this, macs had to prevent zeitwerk from testing eager loading
the caller file expecting the Qpid constant to be known.

Now, we can run it:
DEBUG_MANAGEIQ_ZEITWERK=true bin/rails zeitwerk:check --trace
  • Loading branch information
jrafanie committed Oct 25, 2023
1 parent 883525a commit 443d219
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
Rails.autoloaders.main.collapse(Rails.root.join("lib/ansible/runner/credential"))
Rails.autoloaders.main.collapse(Rails.root.join("lib/pdf_generator"))

# requires qpid, which is an optional dependency because LOL mac
if RUBY_PLATFORM.include?("darwin")
message_handler_path = Pathname.new(Vmdb::Plugins.paths[ManageIQ::Providers::Nuage::Engine]).join("app/models/manageiq/providers/nuage/network_manager/event_catcher/messaging_handler.rb")
Rails.autoloaders.main.ignore(message_handler_path)
# These stub classes are only for macos to workaround qpid_proton not being installable on mac.
# These stubs won't define constants elsewhere, so we need to tell zeitwerk to ignore them.
unless RUBY_PLATFORM.include?("darwin")
Rails.autoloaders.main.ignore(Rails.root.join("lib/qpid/proton/container.rb"))
Rails.autoloaders.main.ignore(Rails.root.join("lib/qpid/proton/messaging_handler.rb"))
end
end
9 changes: 9 additions & 0 deletions lib/qpid/proton/container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fake qpid_proton stub so zeitwerk can autoload on platforms that can't build the gem, such as macos.
if RUBY_PLATFORM.include?("darwin")
module Qpid
module Proton
class Container
end
end
end
end
9 changes: 9 additions & 0 deletions lib/qpid/proton/messaging_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fake qpid_proton stub so zeitwerk can autoload on platforms that can't build the gem, such as macos.
if RUBY_PLATFORM.include?("darwin")
module Qpid
module Proton
class MessagingHandler
end
end
end
end

0 comments on commit 443d219

Please sign in to comment.