Skip to content

Commit e85e574

Browse files
Merge pull request rails#50183 from jonathanhefner/app_generator-separate-lock-from-install
Separate `bundle lock` from `bundle install`
2 parents 1b67822 + 5cfff97 commit e85e574

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

railties/lib/rails/generators/app_base.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -680,19 +680,7 @@ def target_rails_prerelease(self_command = "new")
680680
end
681681

682682
def run_bundle
683-
if bundle_install?
684-
bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1")
685-
686-
# The vast majority of Rails apps will be deployed on `x86_64-linux`.
687-
platforms = ["--add-platform=x86_64-linux"]
688-
689-
# Users that develop on M1 mac may use docker and would need `aarch64-linux` as well.
690-
platforms << "--add-platform=aarch64-linux" if RUBY_PLATFORM.start_with?("arm64")
691-
692-
platforms.each do |platform|
693-
bundle_command("lock #{platform}", "BUNDLE_IGNORE_MESSAGES" => "1")
694-
end
695-
end
683+
bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
696684
end
697685

698686
def run_javascript
@@ -722,6 +710,16 @@ def run_css
722710
end
723711
end
724712

713+
def add_bundler_platforms
714+
if bundle_install?
715+
# The vast majority of Rails apps will be deployed on `x86_64-linux`.
716+
bundle_command("lock --add-platform=x86_64-linux")
717+
718+
# Users that develop on M1 mac may use docker and would need `aarch64-linux` as well.
719+
bundle_command("lock --add-platform=aarch64-linux") if RUBY_PLATFORM.start_with?("arm64")
720+
end
721+
end
722+
725723
def generate_bundler_binstub
726724
if bundle_install?
727725
bundle_command("binstubs bundler")

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def finish_template
539539

540540
public_task :apply_rails_template
541541
public_task :run_bundle
542+
public_task :add_bundler_platforms
542543
public_task :generate_bundler_binstub
543544
public_task :run_javascript
544545
public_task :run_hotwire

railties/test/generators/app_generator_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,24 @@ def test_apply_rails_template_class_method_runs_bundle_and_after_bundle_callback
10851085
end
10861086
end
10871087

1088+
def test_apply_rails_template_class_method_does_not_add_bundler_platforms
1089+
run_generator
1090+
1091+
FileUtils.cd(destination_root) do
1092+
FileUtils.touch("lib/template.rb")
1093+
1094+
generator_class.no_commands do
1095+
# There isn't an easy way to access the generator instance in order to
1096+
# assert that we don't run `bundle lock --add-platform`, so the
1097+
# following assertion assumes that the sole call to `bundle_command` is
1098+
# for `bundle install`.
1099+
assert_called_on_instance_of(generator_class, :bundle_command, times: 1) do
1100+
quietly { generator_class.apply_rails_template("lib/template.rb", destination_root) }
1101+
end
1102+
end
1103+
end
1104+
end
1105+
10881106
def test_gitignore
10891107
run_generator
10901108

0 commit comments

Comments
 (0)