lib/appbundler/app.rb in appbundler-0.12.3 vs lib/appbundler/app.rb in appbundler-0.12.4

- old
+ new

@@ -84,11 +84,11 @@ # This is a blatant ChefDK 2.0 hack. We need to audit all of our Gemfiles, make sure # that github_changelog_generator is in its own group and exclude that group from all # of our appbundle calls. But to ship ChefDK 2.0 we just do this. SHITLIST = [ "github_changelog_generator", - ] + ].freeze # This is a check which is equivalent to asking if we are running 2-arg or 3-arg. If # we have an "external_lockfile" that means the chef-dk omnibus Gemfile.lock, e.g.: # /var/cache/omnibus/src/chef-dk/chef-dk-3.8.14/Gemfile.lock is being merged with the # Gemfile in e.g. /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/berkshelf-7.0.7/Gemfile. @@ -109,15 +109,15 @@ # called the "local" gemfile.lock here. In either case it is something like: # /var/cache/omnibus/src/chef-dk/chef-dk-3.8.14/Gemfile.lock # def local_gemfile_lock_specs gemfile_lock_specs.map do |s| - #if SHITLIST.include?(s.name) + # if SHITLIST.include?(s.name) # nil - #else - safe_resolve_local_gem(s) - #end + # else + safe_resolve_local_gem(s) + # end end.compact end # Copy over any .bundler and Gemfile.lock files to the target gem # directory. This will let us run tests from under that directory. @@ -127,17 +127,27 @@ # def copy_bundler_env gem_path = installed_spec.gem_dir # If we're already using that directory, don't copy (it won't work anyway) return if gem_path == File.dirname(gemfile_lock) - FileUtils.install(gemfile_lock, gem_path, :mode => 0644) + FileUtils.install(gemfile_lock, gem_path, mode: 0644) if File.exist?(dot_bundle_dir) && File.directory?(dot_bundle_dir) FileUtils.cp_r(dot_bundle_dir, gem_path) FileUtils.chmod_R("ugo+rX", File.join(gem_path, ".bundle")) end end + # This is used to copy the binstubs from the binstub source directory to the actual + # binstub location. + # + def copy_binstubs(binstubs_source) + gem_path = installed_spec.gem_dir + dst = "#{gem_path}/bin" + src = "#{gem_path}/#{binstubs_source}/*" + FileUtils.cp_r(Dir.glob(src), dst) + end + # This is the implementation of the 3-arg version of writing the merged lockfiles, # when called with the 2-arg version it short-circuits, however, to the copy_bundler_env # version above. # # This code does not affect the generated binstubs at all. @@ -153,11 +163,11 @@ t.puts "source 'https://rubygems.org'" locked_gems = {} gemfile_lock_specs.each do |s| - #next if SHITLIST.include?(s.name) + # next if SHITLIST.include?(s.name) spec = safe_resolve_local_gem(s) next if spec.nil? case s.source when Bundler::Source::Path @@ -195,22 +205,22 @@ next if seen_gems[name] t.puts line end t.close - puts IO.read(t.path) # debugging + puts IO.read(t.path) # debugging Dir.chdir(app_dir) do FileUtils.rm_f "#{app_dir}/Gemfile.lock" Bundler.with_clean_env do so = Mixlib::ShellOut.new("bundle lock", env: { "BUNDLE_GEMFILE" => t.path }) so.run_command so.error! end FileUtils.mv t.path, "#{app_dir}/Gemfile" end end - return "#{app_dir}/Gemfile" + "#{app_dir}/Gemfile" end def write_executable_stubs executables_to_create = executables.map do |real_executable_path| basename = File.basename(real_executable_path) @@ -245,14 +255,14 @@ Gem.ruby end def batchfile_stub ruby_relpath_windows = ruby_relative_path.tr("/", '\\') - <<-E -@ECHO OFF -"%~dp0\\#{ruby_relpath_windows}" "%~dpn0" %* -E + <<~E + @ECHO OFF + "%~dp0\\#{ruby_relpath_windows}" "%~dpn0" %* + E end # Relative path from #target_bin_dir to #ruby. This is used to # generate batch files for windows in a way that the package can be # installed in a custom location. On Unix we don't support custom @@ -286,28 +296,28 @@ # # Environment sanitization can be skipped by setting the # APPBUNDLER_ALLOW_RVM environment variable to "true". This feature # exists to make tests run correctly on travis.ci (which uses rvm). def env_sanitizer - <<-EOS -require "rubygems" + <<~EOS + require "rubygems" -begin - # this works around rubygems/rubygems#2196 and can be removed in rubygems > 2.7.6 - require "rubygems/bundler_version_finder" -rescue LoadError - # probably means rubygems is too old or too new to have this class, and we don't care -end + begin + # this works around rubygems/rubygems#2196 and can be removed in rubygems > 2.7.6 + require "rubygems/bundler_version_finder" + rescue LoadError + # probably means rubygems is too old or too new to have this class, and we don't care + end -# avoid appbundling if we are definitely running within a Bundler bundle. -# most likely the check for defined?(Bundler) is enough since we don't require -# bundler above, but just for paranoia's sake also we test to see if Bundler is -# really doing its thing or not. -unless defined?(Bundler) && Bundler.instance_variable_defined?("@load") - ENV["GEM_HOME"] = ENV["GEM_PATH"] = nil unless ENV["APPBUNDLER_ALLOW_RVM"] == "true" - ::Gem.clear_paths -EOS + # avoid appbundling if we are definitely running within a Bundler bundle. + # most likely the check for defined?(Bundler) is enough since we don't require + # bundler above, but just for paranoia's sake also we test to see if Bundler is + # really doing its thing or not. + unless defined?(Bundler) && Bundler.instance_variable_defined?("@load") + ENV["GEM_HOME"] = ENV["GEM_PATH"] = nil unless ENV["APPBUNDLER_ALLOW_RVM"] == "true" + ::Gem.clear_paths + EOS end def runtime_activate @runtime_activate ||= begin statements = runtime_dep_specs.map { |s| %Q{ gem "#{s.name}", "= #{s.version}"} } @@ -323,21 +333,21 @@ end def load_statement_for(bin_file) name, version = app_spec.name, app_spec.version bin_basename = File.basename(bin_file) - <<-E - gem "#{name}", "= #{version}" - spec = Gem::Specification.find_by_name("#{name}", "= #{version}") -else - spec = Gem::Specification.find_by_name("#{name}") -end + <<~E + gem "#{name}", "= #{version}" + spec = Gem::Specification.find_by_name("#{name}", "= #{version}") + else + spec = Gem::Specification.find_by_name("#{name}") + end -bin_file = spec.bin_file("#{bin_basename}") + bin_file = spec.bin_file("#{bin_basename}") -Kernel.load(bin_file) -E + Kernel.load(bin_file) + E end def executables installed_spec.executables.map { |e| installed_spec.bin_file(e) } + extra_bin_files end @@ -411,15 +421,15 @@ # the InaccessibleGemsInLockfile error is raised. def verify_deps_are_accessible! inaccessable_gems = inaccessable_git_sourced_gems return true if inaccessable_gems.empty? - message = <<-MESSAGE -Application '#{name}' contains gems in the lockfile which are -not accessible by rubygems. This usually occurs when you fetch gems from git in -your Gemfile and do not install the same version of the gems beforehand. + message = <<~MESSAGE + Application '#{name}' contains gems in the lockfile which are + not accessible by rubygems. This usually occurs when you fetch gems from git in + your Gemfile and do not install the same version of the gems beforehand. -MESSAGE + MESSAGE message << "The Gemfile.lock is located here:\n- #{gemfile_lock}\n\n" message << "The offending gems are:\n" inaccessable_gems.each do |gemspec|