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

Rubocop binstubs issue causes failures on Windows #51618

Closed
mohits opened this issue Apr 20, 2024 · 8 comments
Closed

Rubocop binstubs issue causes failures on Windows #51618

mohits opened this issue Apr 20, 2024 · 8 comments

Comments

@mohits
Copy link
Contributor

mohits commented Apr 20, 2024

Steps to reproduce

After setting up a new application with Rails main, create a controller in the empty application.

$ ruby bin\rails g controller home welcome

Expected behavior

The generate command should complete successfully without any errors from Rubocop.

$ ruby bin\rails g controller home welcome --force
   identical  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
       exist    app/views/home
   identical    app/views/home/welcome.html.erb
      invoke  helper
   identical    app/helpers/home_helper.rb
Inspecting 2 files
..

Actual behavior

The command completes but ends with an error from Rubocop.

$ ruby bin\rails g controller home welcome
      create  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
      create    app/views/home
      create    app/views/home/welcome.html.erb
      invoke  helper
      create    app/helpers/home_helper.rb
D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/configuration.rb:138:in `system': Exec format error - bin/rubocop -A --fail-level=E app/controllers/home_controller.rb app/helpers/home_helper.rb (Errno::ENOEXEC)
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/configuration.rb:138:in `block in apply_rubocop_autocorrect_after_generate!'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:317:in `block in run_after_generate_callback'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:316:in `each'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:316:in `run_after_generate_callback'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:263:in `invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/commands/generate/generate_command.rb:26:in `perform'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command/base.rb:178:in `invoke_command'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command/base.rb:73:in `perform'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:71:in `block in invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:149:in `with_argv'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:69:in `invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/commands.rb:18:in `<main>'
        from D:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
        from D:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:4:in `<main>'

System configuration

Rails version: 7.2.0-alpha

  remote: https://github.com/rails/rails.git
  revision: 284baa18c2c62abec170b61e285aefbd9604f675
  branch: main

Ruby version: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt]

Fix

The issue is fixed by installing binstubs for rubocop (unfortunately, right now, I do not know where the fix would be applied in the Rails codebase).

$ bundle binstubs rubocop --force

If you point me to where it should go, I am happy to open a PR. Else, I'm happy for someone to do this at the correct place. Thanks!

Other Information

Detailed links:

@mohits mohits changed the title Rubocop binstubs issues causes failures on Windows Rubocop binstubs issue causesfailures on Windows Apr 20, 2024
@mohits mohits changed the title Rubocop binstubs issue causesfailures on Windows Rubocop binstubs issue causes failures on Windows Apr 20, 2024
@andyw8
Copy link
Contributor

andyw8 commented May 1, 2024

I believe the correct fix is just to change Rails to run ruby bin/rubocop instead of bin/rubocop.

@andyw8
Copy link
Contributor

andyw8 commented May 1, 2024

system("bin/rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)

@zzak
Copy link
Member

zzak commented May 19, 2024

I believe this was fixed by #51779, @mohits can you verify?

If someone can reproduce, please feel free to re-open.

@zzak zzak closed this as completed May 19, 2024
@mohits
Copy link
Contributor Author

mohits commented May 19, 2024

Hi @zzak, I think this looks like it is completed but I'm not sure.

[1] I created a new app on main and then ran the usual generate controller home welcome and I got this:

$ ruby bin\rails g controller home welcome
      create  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
      create    app/views/home
      create    app/views/home/welcome.html.erb
      invoke  helper
      create    app/helpers/home_helper.rb

No error! That's great.

[2] However, I think the earlier versions would run rubocop and show that no offenses were found. So, I'm not sure it's fully fixed. This is what I had on my post from before (after fixing binstubs):

$ ruby bin\rails g controller home welcome --force
   identical  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
       exist    app/views/home
   identical    app/views/home/welcome.html.erb
      invoke  helper
   identical    app/helpers/home_helper.rb
Inspecting 2 files
..

2 files inspected, no offenses detected

Could it be that rubocop doesn't run on Windows any more?

@andyw8
Copy link
Contributor

andyw8 commented May 19, 2024

@mohits try making a change in .rubocop.yml, e.g. set the styling to use single quotes, and run the generator again.

I'm not sure if the behaviour has changed, but when testing on Mac I see RuboCop output only if there are corrections made, otherwise it's silent.

@andyw8
Copy link
Contributor

andyw8 commented May 19, 2024

Ah, it was change here: #51808

@mohits
Copy link
Contributor Author

mohits commented May 19, 2024

Thanks @andyw8 - I just switched off, but will try this later. This what I tried above was on a pristine main branch app and used to work fine (after the bundle fix) without changing rubocop.yml earlier.

Rubocop used to run every time something new was generated.

@andyw8
Copy link
Contributor

andyw8 commented May 19, 2024

Also note that option is now off by default: #51782

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

No branches or pull requests

3 participants