Skip to content

Commit

Permalink
don't overwrie python shims during install
Browse files Browse the repository at this point in the history
  • Loading branch information
g-arjones committed Dec 5, 2021
1 parent c0d6f40 commit b061405
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bin/autoproj_bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ module Autoproj
bin_shim = File.join(shim_path, bin_name)
bin_script_lines = File.readlines(bin_script)
next if has_autoproj_preamble?(bin_script_lines)
next unless ruby_script?(bin_script_lines)

File.open(bin_shim, "w") do |io|
if bin_name == "bundler" || bin_name == "bundle"
Expand All @@ -515,6 +516,10 @@ module Autoproj
end
end

def self.ruby_script?(script_lines)
script_lines.first =~ /\#\s*!(.*ruby.*)/
end

def self.new_style_bundler_binstub?(script_lines)
script_lines.any? { |l| l =~ /This file was generated by Bundler/ }
end
Expand Down
5 changes: 5 additions & 0 deletions bin/autoproj_install
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ module Autoproj
bin_shim = File.join(shim_path, bin_name)
bin_script_lines = File.readlines(bin_script)
next if has_autoproj_preamble?(bin_script_lines)
next unless ruby_script?(bin_script_lines)

File.open(bin_shim, "w") do |io|
if bin_name == "bundler" || bin_name == "bundle"
Expand All @@ -515,6 +516,10 @@ module Autoproj
end
end

def self.ruby_script?(script_lines)
script_lines.first =~ /\#\s*!(.*ruby.*)/
end

def self.new_style_bundler_binstub?(script_lines)
script_lines.any? { |l| l =~ /This file was generated by Bundler/ }
end
Expand Down
5 changes: 5 additions & 0 deletions lib/autoproj/ops/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def self.rewrite_shims(shim_path, ruby_executable,
bin_shim = File.join(shim_path, bin_name)
bin_script_lines = File.readlines(bin_script)
next if has_autoproj_preamble?(bin_script_lines)
next unless ruby_script?(bin_script_lines)

File.open(bin_shim, "w") do |io|
if bin_name == "bundler" || bin_name == "bundle"
Expand All @@ -505,6 +506,10 @@ def self.rewrite_shims(shim_path, ruby_executable,
end
end

def self.ruby_script?(script_lines)
script_lines.first =~ /\#\s*!(.*ruby.*)/
end

def self.new_style_bundler_binstub?(script_lines)
script_lines.any? { |l| l =~ /This file was generated by Bundler/ }
end
Expand Down
25 changes: 25 additions & 0 deletions test/ops/test_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ module Ops
end
end

describe "npython shims" do
attr_reader :install_dir, :shared_dir, :python_shim, :pip_shim

before do
@install_dir = make_tmpdir
@shared_dir = make_tmpdir

FileUtils.mkdir_p File.join(install_dir, ".autoproj", "bin")
@python_shim = File.join(install_dir, ".autoproj", "bin", "python")
@pip_shim = File.join(install_dir, ".autoproj", "bin", "pip")

File.open(python_shim, "w") { |f| f.write("foobar") }
File.open(pip_shim, "w") { |f| f.write("foobar") }

@install_dir, = invoke_test_script(
"install.sh", dir: install_dir, env: { "HOME" => shared_dir }
)
end

it "does not overwrite python shims" do
assert_equal "foobar", File.open(python_shim).read
assert_equal "foobar", File.open(pip_shim).read
end
end

describe "default shared gems location" do
attr_reader :shared_gem_home, :shared_dir, :install_dir

Expand Down

0 comments on commit b061405

Please sign in to comment.