Skip to content

Commit

Permalink
Avoid circular require in generated Ruby code (sigstore#243)
Browse files Browse the repository at this point in the history
By only loading the generated protobuf ruby files and
not the "sigstore_protobuf_specs" file

Before:

```sh
$ chruby-exec ruby-2.7 -- ruby -w -rbundler/inline -e 'gemfile { source "https://rubygems.org"; gemspec }; require "sigstore_protobuf_specs"'
/Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:38: warning: /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:38: warning: loading in progress, circular require considered harmful - /Users/segiddins/Development/github.com/sigstore/protobuf-specs/gen/pb-ruby/lib/sigstore_protobuf_specs.rb
        from -e:1:in  `<main>'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/inline.rb:42:in  `gemfile'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler.rb:411:in  `with_unbundled_env'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler.rb:657:in  `with_env'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler.rb:411:in  `block in with_unbundled_env'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/inline.rb:51:in  `block in gemfile'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/settings.rb:130:in  `temporary'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/inline.rb:66:in  `block (2 levels) in gemfile'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:44:in  `require'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:44:in  `each'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:55:in  `block in require'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:55:in  `each'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:60:in  `block (2 levels) in require'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:60:in  `require'
        from /Users/segiddins/Development/github.com/sigstore/protobuf-specs/gen/pb-ruby/lib/sigstore_protobuf_specs.rb:18:in  `<top (required)>'
        from /Users/segiddins/Development/github.com/sigstore/protobuf-specs/gen/pb-ruby/lib/sigstore_protobuf_specs.rb:18:in  `each'
        from /Users/segiddins/Development/github.com/sigstore/protobuf-specs/gen/pb-ruby/lib/sigstore_protobuf_specs.rb:18:in  `block in <top (required)>'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:38:in  `require'
        from /Users/segiddins/.rubies/ruby-2.7.5/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:38:in  `require'
```

Signed-off-by: Samuel Giddins <[email protected]>
  • Loading branch information
segiddins authored Mar 4, 2024
1 parent d8d7827 commit f40ffbf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gen/pb-ruby/lib/sigstore_protobuf_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'sigstore_protobuf_specs/version'
Dir[File.join(__dir__, '*.rb')].each { |file| require file }
require_relative 'sigstore_protobuf_specs/version'
Dir['*_pb.rb', base: __dir__].each { |file| require_relative file }

0 comments on commit f40ffbf

Please sign in to comment.