Skip to content

Commit ebc60e8

Browse files
committed
Remove regenerateBundlerBinStub workaround for bundler 2.7+
Bundler 2.7+ philosophy: 'Bundler itself does not use binstubs because its version is selected by RubyGems' The regenerateBundlerBinStub() function was added in 2017 (commit fe6e899) to work around bundler 1.16.0 incompatibility with Rails-generated binstubs. This workaround is no longer necessary because: 1. The original Rails binstub bug was fixed years ago 2. Bundler 2.7+ explicitly refuses to create its own binstub by design 3. The buildpack doesn't use deps/0/bin/bundle anyway - it uses the system bundle command from deps/0/bundler (configured via GEM_PATH) 4. Modern bundler philosophy is to use the system bundle, not a binstub Changes: - Removed regenerateBundlerBinStub() function - Removed call to regenerateBundlerBinStub() from InstallGems() - Removed related unit tests (setupBundlerBin, itRegeneratesBundleBinstub) - All 76 unit tests pass This aligns the buildpack with bundler 2.7+ architectural decisions.
1 parent 6be9c1a commit ebc60e8

2 files changed

Lines changed: 1 addition & 51 deletions

File tree

src/ruby/supply/supply.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,6 @@ func (s *Supplier) InstallGems() error {
768768
return err
769769
}
770770

771-
if err := s.regenerateBundlerBinStub(tempDir); err != nil {
772-
return err
773-
}
774-
775771
s.Log.Info("Cleaning up the bundler cache.")
776772
cmd = exec.Command("bundle", "clean")
777773
cmd.Dir = tempDir
@@ -845,18 +841,6 @@ func (s *Supplier) removeIncompatibleBundledWithVersion(bundledWithVersion strin
845841
return os.WriteFile(gemfileLockPath, output, 0666)
846842
}
847843

848-
func (s *Supplier) regenerateBundlerBinStub(appDir string) error {
849-
s.Log.BeginStep("Regenerating bundler binstubs...")
850-
cmd := exec.Command("bundle", "binstubs", "bundler", "--force", "--path", filepath.Join(s.Stager.DepDir(), "binstubs"))
851-
cmd.Dir = appDir
852-
cmd.Stdout = text.NewIndentWriter(os.Stdout, []byte(" "))
853-
cmd.Stderr = text.NewIndentWriter(os.Stderr, []byte(" "))
854-
if err := s.Command.Run(cmd); err != nil {
855-
return err
856-
}
857-
return libbuildpack.CopyFile(filepath.Join(s.Stager.DepDir(), "binstubs", "bundle"), filepath.Join(s.Stager.DepDir(), "bin", "bundle"))
858-
}
859-
860844
func (s *Supplier) EnableLDLibraryPathEnv() error {
861845
if exists, err := libbuildpack.FileExists(filepath.Join(s.Stager.BuildDir(), "ld_library_path")); err != nil {
862846
return err

src/ruby/supply/supply_test.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"os/exec"
99
"path/filepath"
1010

11-
"reflect"
12-
1311
"github.com/cloudfoundry/ruby-buildpack/src/ruby/cache"
1412
"github.com/cloudfoundry/ruby-buildpack/src/ruby/supply"
1513

@@ -481,32 +479,13 @@ var _ = Describe("Supply", func() {
481479

482480
const windowsWarning = "**WARNING** Windows line endings detected in Gemfile. Your app may fail to stage. Please use UNIX line endings."
483481

484-
handleBundleBinstubRegeneration := func(cmd *exec.Cmd) error {
485-
if len(cmd.Args) > 5 && reflect.DeepEqual(cmd.Args[0:5], []string{"bundle", "binstubs", "bundler", "--force", "--path"}) {
486-
Expect(cmd.Args[5]).To(HavePrefix(filepath.Join(depsDir, depsIdx)))
487-
Expect(os.MkdirAll(cmd.Args[5], 0755)).To(Succeed())
488-
Expect(os.WriteFile(filepath.Join(cmd.Args[5], "bundle"), []byte("new bundle binstub"), 0644)).To(Succeed())
489-
}
490-
return nil
491-
}
492-
493-
itRegeneratesBundleBinstub := func() {
494-
It("Re-generates the bundler binstub to replace older, rails-generated ones that are incompatible with bundler > 1.16.0", func() {
495-
Expect(supplier.InstallGems()).To(Succeed())
496-
Expect(os.ReadFile(filepath.Join(depsDir, depsIdx, "binstubs", "bundle"))).To(Equal([]byte("new bundle binstub")))
497-
Expect(os.ReadFile(filepath.Join(depsDir, depsIdx, "bin", "bundle"))).To(Equal([]byte("new bundle binstub")))
498-
})
499-
}
500-
501482
Context("Windows Gemfile", func() {
502483
BeforeEach(func() {
503484
mockVersions.EXPECT().HasWindowsGemfileLock().Return(false, nil)
504-
mockCommand.EXPECT().Run(gomock.Any()).AnyTimes().Do(handleBundleBinstubRegeneration)
485+
mockCommand.EXPECT().Run(gomock.Any()).AnyTimes()
505486
Expect(os.WriteFile(filepath.Join(buildDir, "Gemfile"), []byte("source \"https://rubygems.org\"\r\ngem \"rack\"\r\n"), 0644)).To(Succeed())
506487
})
507488

508-
itRegeneratesBundleBinstub()
509-
510489
It("Warns the user", func() {
511490
Expect(supplier.InstallGems()).To(Succeed())
512491
Expect(buffer.String()).To(ContainSubstring(windowsWarning))
@@ -521,10 +500,7 @@ var _ = Describe("Supply", func() {
521500
if len(cmd.Args) > 2 && cmd.Args[1] == "install" {
522501
Expect(os.MkdirAll(filepath.Join(cmd.Dir, ".bundle"), 0755)).To(Succeed())
523502
Expect(os.WriteFile(filepath.Join(cmd.Dir, ".bundle", "config"), []byte("new bundle config"), 0644)).To(Succeed())
524-
} else {
525-
return handleBundleBinstubRegeneration(cmd)
526503
}
527-
528504
return nil
529505
})
530506
Expect(os.WriteFile(filepath.Join(buildDir, "Gemfile"), []byte("source \"https://rubygems.org\"\ngem \"rack\"\n"), 0644)).To(Succeed())
@@ -534,8 +510,6 @@ var _ = Describe("Supply", func() {
534510
os.Unsetenv("BUNDLE_CONFIG")
535511
})
536512

537-
itRegeneratesBundleBinstub()
538-
539513
It("Does not warn the user", func() {
540514
Expect(supplier.InstallGems()).To(Succeed())
541515
Expect(buffer.String()).ToNot(ContainSubstring(windowsWarning))
@@ -572,8 +546,6 @@ var _ = Describe("Supply", func() {
572546
if cmd.Args[1] == "install" {
573547
Expect(filepath.Join(cmd.Dir, "Gemfile")).To(BeAnExistingFile())
574548
Expect(filepath.Join(cmd.Dir, "Gemfile.lock")).To(BeAnExistingFile())
575-
} else {
576-
handleBundleBinstubRegeneration(cmd)
577549
}
578550
})
579551
Expect(supplier.InstallGems()).To(Succeed())
@@ -588,8 +560,6 @@ var _ = Describe("Supply", func() {
588560
if cmd.Args[1] == "install" {
589561
Expect(cmd.Dir).ToNot(Equal(buildDir))
590562
installCalled = true
591-
} else {
592-
handleBundleBinstubRegeneration(cmd)
593563
}
594564
})
595565
Expect(supplier.InstallGems()).To(Succeed())
@@ -614,8 +584,6 @@ var _ = Describe("Supply", func() {
614584
Expect(filepath.Join(cmd.Dir, "Gemfile")).To(BeAnExistingFile())
615585
Expect(filepath.Join(cmd.Dir, "Gemfile.lock")).ToNot(BeAnExistingFile())
616586
Expect(os.WriteFile(filepath.Join(cmd.Dir, "Gemfile.lock"), []byte(newGemfileLock), 0644)).To(Succeed())
617-
} else {
618-
handleBundleBinstubRegeneration(cmd)
619587
}
620588
})
621589
Expect(supplier.InstallGems()).To(Succeed())
@@ -630,8 +598,6 @@ var _ = Describe("Supply", func() {
630598
if cmd.Args[1] == "install" {
631599
Expect(cmd.Dir).ToNot(Equal(buildDir))
632600
installCalled = true
633-
} else {
634-
handleBundleBinstubRegeneration(cmd)
635601
}
636602
})
637603
Expect(supplier.InstallGems()).To(Succeed())

0 commit comments

Comments
 (0)