#!/usr/bin/env ruby $VERBOSE = nil # Don't care about world writable dir warnings and the like if $_fix_my_workspace_version_check $_fix_my_workspace_version = '0.3.0' else require 'origen' if !Origen.site_config.gem_manage_bundler puts 'Sorry but you have opted to manage Bundler yourself via your Origen site config, and this means' puts 'that I cannot make certain assumptions about how your workspace is configured.' puts 'You will need to either resolve this problem yourself, or else change the value of' puts 'gem_mange_bundler to true.' puts 'See here for more details on how to do that: http://origen-sdk.org/origen/guides/starting/company/' else ENV['BUNDLE_GEMFILE'] = File.join(Origen.root, 'Gemfile') ENV['BUNDLE_PATH'] = File.expand_path(Origen.site_config.gem_install_dir) ENV['BUNDLE_BIN'] = File.join(Origen.root, 'lbin') # Force copy system gems to local gems if Origen.site_config.gem_use_from_system local_gem_dir = "#{ENV['BUNDLE_PATH']}/ruby/#{Pathname.new(Gem.dir).basename}" gem_dir = Pathname.new(Gem.dir) Origen.site_config.gem_use_from_system.each do |gem, version| begin # This will raise an error if the system doesn't have this gem installed, that # will be rescued below spec = Gem::Specification.find_by_name(gem, version) local_dir = File.join(local_gem_dir, Pathname.new(spec.gem_dir).relative_path_from(gem_dir)) FileUtils.mkdir_p local_dir FileUtils.cp_r(spec.gem_dir, local_dir) local_file = Pathname.new(File.join(local_gem_dir, Pathname.new(spec.cache_file).relative_path_from(gem_dir))) FileUtils.mkdir_p local_file.dirname FileUtils.cp(spec.cache_file, local_file) if spec.extension_dir && File.exist?(spec.extension_dir) local_dir = File.join(local_gem_dir, Pathname.new(spec.extension_dir).relative_path_from(gem_dir)) FileUtils.mkdir_p local_dir FileUtils.cp_r(spec.extension_dir, local_dir) end local_file = Pathname.new(File.join(local_gem_dir, Pathname.new(spec.spec_file).relative_path_from(gem_dir))) FileUtils.mkdir_p local_file.dirname FileUtils.cp(spec.spec_file, local_file) rescue Gem::LoadError # This just means that one of the gems that should be copied from the system # was not actually installed in the system, so nothing we can do about that here end end end # Delete lbin FileUtils.rm_rf(ENV['BUNDLE_BIN']) if File.exist?(ENV['BUNDLE_BIN']) # Run bundler with correct switches cmd = "bundle install --gemfile #{ENV['BUNDLE_GEMFILE']} --binstubs #{ENV['BUNDLE_BIN']} --path #{ENV['BUNDLE_PATH']}" `chmod o-w #{Origen.root}` # Stops some annoying world writable warnings during install `chmod o-w #{Origen.root}/bin` if File.exist?("#{Origen.root}/bin") `chmod o-w #{Origen.root}/.bin` if File.exist?("#{Origen.root}/.bin") # Try again, this time updating the bundle if system(cmd) fixed = true elsif system 'bundle update' fixed = true end `chmod o-w #{ENV['BUNDLE_BIN']}` if File.exist?(ENV['BUNDLE_BIN']) system 'origen -v' if fixed end end