Skip to content

Commit

Permalink
Remove the explicit 'sudo' in favour of environment variable which de…
Browse files Browse the repository at this point in the history
…faults to 'sudo' on non windows platforms. For a trial install this allows for the fol lowing at the

    export MERB_SUDO=echo
    rake install_gems

    But, the intent of this changes is to allow for local gem installs.  E.g. ones that don't require root access.

This version introduces a helper file: merb_rake_helper.rb to reuse the same check in the subproject Rakefiles.

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
  • Loading branch information
ericdwhite authored and michaelklishin committed May 20, 2008
1 parent 7ab8e4a commit c61341a
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 44 deletions.
10 changes: 4 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end

require "rake/clean"
require "rake/gempackagetask"
require "merb_rake_helper"
require 'fileutils'
include FileUtils

Expand Down Expand Up @@ -50,9 +51,6 @@ end

CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "*.gem", "doc/rdoc", ".config", "coverage", "cache", "lib/merb-more.rb"]

windows = (PLATFORM =~ /win32|cygwin/) rescue nil

SUDO = windows ? "" : "sudo"

Rake::GemPackageTask.new(merb_more_spec) do |package|
package.gem_spec = merb_more_spec
Expand All @@ -67,8 +65,8 @@ install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

desc "Install it all"
task :install => [:install_gems, :package] do
sh %{#{SUDO} gem install #{install_home} --local pkg/merb-more-#{Merb::MORE_VERSION}.gem --no-update-sources}
sh %{#{SUDO} gem install #{install_home} --local pkg/merb-#{Merb::MORE_VERSION}.gem --no-update-sources}
sh %{#{sudo} gem install #{install_home} --local pkg/merb-more-#{Merb::MORE_VERSION}.gem --no-update-sources}
sh %{#{sudo} gem install #{install_home} --local pkg/merb-#{Merb::MORE_VERSION}.gem --no-update-sources}
end

desc "Build the merb-more gems"
Expand All @@ -88,7 +86,7 @@ end
desc "Uninstall the merb-more sub-gems"
task :uninstall_gems do
gems.each do |sub_gem|
sh %{#{SUDO} gem uninstall #{sub_gem}}
sh %{#{sudo} gem uninstall #{sub_gem}}
end
end

Expand Down
5 changes: 3 additions & 2 deletions merb-action-args/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

PLUGIN = "merb-action-args"
NAME = "merb-action-args"
Expand Down Expand Up @@ -34,14 +35,14 @@ end
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
5 changes: 3 additions & 2 deletions merb-assets/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

PLUGIN = "merb-assets"
NAME = "merb-assets"
Expand Down Expand Up @@ -31,14 +32,14 @@ Rake::GemPackageTask.new(spec) do |pkg|
end

task :install => [:package] do
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
Expand Down
5 changes: 3 additions & 2 deletions merb-builder/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

PLUGIN = "merb-builder"
NAME = "merb-builder"
Expand Down Expand Up @@ -34,14 +35,14 @@ end
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
5 changes: 3 additions & 2 deletions merb-cache/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require 'rubygems'
require "rake/rdoctask"
require 'rake/gempackagetask'
require "spec/rake/spectask"
require '../merb_rake_helper'

PLUGIN = "merb-cache"
NAME = "merb-cache"
Expand Down Expand Up @@ -66,14 +67,14 @@ end
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{MERB_CACHE_VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{MERB_CACHE_VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
6 changes: 4 additions & 2 deletions merb-freezer/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

PLUGIN = "merb-freezer"
NAME = "merb-freezer"
Expand Down Expand Up @@ -31,16 +32,17 @@ Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end


desc "install merb-freezer"
task :install => [:package] do
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
28 changes: 12 additions & 16 deletions merb-freezer/lib/merb-freezer/freezer_mode.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require 'find'
require '../../../merb_rake_helper'
module FreezerMode

def sudo
windows = (PLATFORM =~ /win32|cygwin/) rescue nil
sudo = windows ? "" : "sudo"
end


def gitmodules
File.join(Dir.pwd, ".gitmodules")
end
end

# Uses the Git submodules to freeze a component
#
def submodules_freeze
Expand All @@ -34,9 +30,9 @@ def submodules_freeze
else
puts "Creating submodule for #{@component} ..."
if framework_component?
`cd #{Dir.pwd} & git-submodule --quiet add #{Freezer.components[@component.gsub("merb-", '')]} #{File.basename(freezer_dir)}/#{@component}`
`cd #{Dir.pwd} & git-submodule --quiet add #{Freezer.components[@component.gsub("merb-", '')]} #{File.basename(freezer_dir)}/#{@component}`
else
`cd #{Dir.pwd} & git-submodule --quiet add #{@component} gems/submodules/#{@component.match(/.*\/(.*)\..{3}$/)[1]}`
`cd #{Dir.pwd} & git-submodule --quiet add #{@component} gems/submodules/#{@component.match(/.*\/(.*)\..{3}$/)[1]}`
end
if $?.success?
`git-submodule init`
Expand All @@ -46,7 +42,7 @@ def submodules_freeze
end
end
end

# Uses rubygems to freeze the components locally
#
def rubygems_freeze
Expand All @@ -55,14 +51,14 @@ def rubygems_freeze
puts "#{action} #{@component} and dependencies from rubygems"
`#{sudo} gem #{action} #{@component} --no-rdoc --no-ri -i #{framework_component? ? 'framework' : 'gems'}`
end

def create_freezer_dir(path)
unless File.directory?(path)
puts "Creating freezer directory ..."
FileUtils.mkdir_p(path)
end
end

protected

# returns true if submodules are used
Expand All @@ -76,10 +72,10 @@ def in_submodule?(component)
def managed?(component)
File.directory?(File.join(freezer_dir, component)) || in_submodule?(component)
end

def in_path?(bin)
`which #{bin}`
!$?.nil? && $?.success?
end
end

end
6 changes: 4 additions & 2 deletions merb-gen/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

GEM = "merb-gen"
VERSION = "0.9.4"
Expand Down Expand Up @@ -36,14 +37,15 @@ Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end


install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

namespace :jruby do
task :install do
sh %{sudo jruby -S gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
end
end

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
end
9 changes: 5 additions & 4 deletions merb-gen/app_generators/merb_plugin/templates/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require 'rubygems'
require 'rake/gempackagetask'
require 'rubygems/specification'
require 'date'
require '../merb_rake_helper'

PLUGIN = "<%= base_name %>"
NAME = "<%= base_name %>"
Expand Down Expand Up @@ -34,7 +35,7 @@ end

desc "install the plugin locally"
task :install => [:package] do
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
end

desc "create a gemspec file"
Expand All @@ -48,7 +49,7 @@ namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end
end

end
5 changes: 3 additions & 2 deletions merb-haml/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake/gempackagetask'
require '../merb_rake_helper'

PLUGIN = "merb-haml"
NAME = "merb-haml"
Expand Down Expand Up @@ -34,14 +35,14 @@ end
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
5 changes: 3 additions & 2 deletions merb-mailer/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rubygems'
require 'rake/gempackagetask'
require "spec/rake/spectask"
require '../merb_rake_helper'

PLUGIN = "merb-mailer"
NAME = "merb-mailer"
Expand Down Expand Up @@ -35,14 +36,14 @@ end
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
Expand Down
6 changes: 4 additions & 2 deletions merb-parts/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rubygems'
require 'rake/gempackagetask'
require "spec/rake/spectask"
require '../merb_rake_helper'

PLUGIN = "merb-parts"
NAME = "merb-parts"
Expand Down Expand Up @@ -31,17 +32,18 @@ Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end


install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""

task :install => [:package] do
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
end

namespace :jruby do

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end

end
Expand Down
5 changes: 5 additions & 0 deletions merb_rake_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def sudo
windows = (PLATFORM =~ /win32|cygwin/) rescue nil
ENV['MERB_SUDO'] ||= "sudo"
sudo = windows ? "" : ENV['MERB_SUDO']
end

0 comments on commit c61341a

Please sign in to comment.