Skip to content

Commit

Permalink
Cleaned up use of FileUtils and Dir.chdir
Browse files Browse the repository at this point in the history
  • Loading branch information
larsch committed Aug 3, 2008
1 parent 7a9dc27 commit b6cc9ea
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 131 deletions.
7 changes: 3 additions & 4 deletions recipes/compiler/msys.rake
@@ -1,6 +1,5 @@
require 'rake'
require 'rake/clean'
require 'fileutils'

namespace(:compiler) do
namespace(:msys) do
Expand Down Expand Up @@ -38,12 +37,12 @@ namespace(:compiler) do
# msys is hardcoded to mount /usr and cannot be overwriten
from_folder = File.join(package.target, "usr")
Dir.glob("#{from_folder}/*").reject { |f| f =~ /local$/ }.each do |f|
FileUtils.cp_r(f, package.target)
cp_r f, package.target
end
Dir.glob("#{from_folder}/local/*").each do |f|
FileUtils.cp_r(f, package.target)
cp_r f, package.target
end
FileUtils.rm_rf(from_folder)
rm_rf from_folder

# create the fstab file, mount /mingw to sandbox/mingw
# mount also /usr/local to sandbox/msys/usr
Expand Down
8 changes: 4 additions & 4 deletions recipes/dependencies/iconv.rake
Expand Up @@ -36,10 +36,10 @@ namespace(:dependencies) do
# remove *.txt
# remove src folder
# leave zlib1.dll inside bin ;-)
Dir.chdir(File.join(RubyInstaller::ROOT, package.target)) do
FileUtils.rm_rf("src")
Dir.glob("*.txt").each do |f|
FileUtils.rm_f(f)
cd File.join(RubyInstaller::ROOT, package.target) do
rm_rf "src"
Dir.glob("*.txt").each do |path|
rm_f path
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions recipes/dependencies/zlib.rake
Expand Up @@ -36,12 +36,12 @@ namespace(:dependencies) do
# remove test/*.exe
# remove *.txt
# move zlib1.dll to bin
Dir.chdir(File.join(RubyInstaller::ROOT, package.target)) do
FileUtils.rm_rf("test")
Dir.glob("*.txt").each do |f|
FileUtils.rm_f(f)
cd File.join(RubyInstaller::ROOT, package.target) do
rm_rf "test"
Dir.glob("*.txt").each do |path|
rm_f path
end
FileUtils.mv("zlib1.dll", "bin")
mv "zlib1.dll", "bin"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions recipes/interpreter/patch.rake
Expand Up @@ -31,7 +31,7 @@ namespace(:interpreter) do

task :prepare => [package.prepare_target] do
glob = File.join(RubyInstaller::ROOT, package.target, '*.patch')
Dir.chdir(package.prepare_target) do
cd package.prepare_target do
Dir[glob].sort.each do |patch|
msys_sh "patch -p1 -t < #{patch}"
end
Expand All @@ -45,4 +45,4 @@ unless ENV['CHECKOUT']
task :download => ['interpreter:patch:download']
task :extract => ['interpreter:patch:extract']
task :prepare => ['interpreter:patch:prepare']
end
end
32 changes: 16 additions & 16 deletions recipes/interpreter/ruby18.rake
Expand Up @@ -25,7 +25,7 @@ namespace(:interpreter) do
end

task :checkout => "downloads" do
Dir.chdir(RubyInstaller::ROOT) do
cd RubyInstaller::ROOT do
# If is there already a checkout, update instead of checkout"
if File.exist?(File.join(RubyInstaller::ROOT, package.checkout_target, '.svn'))
sh "svn update #{package.checkout_target}"
Expand All @@ -45,19 +45,19 @@ namespace(:interpreter) do
extract(File.join(RubyInstaller::ROOT, f), package.target)
}
else
FileUtils.cp_r(package.checkout_target, File.join(RubyInstaller::ROOT, 'sandbox'), :verbose => true, :remove_destination => true)
cp_r(package.checkout_target, File.join(RubyInstaller::ROOT, 'sandbox'), :verbose => true, :remove_destination => true)
end
end
ENV['CHECKOUT'] ? task(:extract => :checkout) : task(:extract => :download)

task :prepare => [package.build_target] do
Dir.chdir(RubyInstaller::ROOT) do
FileUtils.cp_r(Dir.glob('resources/icons/*.ico'), package.build_target, :verbose => true)
cd RubyInstaller::ROOT do
cp_r(Dir.glob('resources/icons/*.ico'), package.build_target, :verbose => true)
end

# FIXME: Readline is not working, remove it for now.
Dir.chdir package.target do
FileUtils.rm_f 'test/readline/test_readline.rb'
cd package.target do
rm_f 'test/readline/test_readline.rb'
end
end

Expand All @@ -71,15 +71,15 @@ namespace(:interpreter) do
end

file makefile => [ package.build_target, configurescript ] do
Dir.chdir(package.build_target) do
cd package.build_target do
msys_sh "../ruby_1_8/configure #{package.configure_options.join(' ')} --prefix=#{File.join(RubyInstaller::ROOT, package.install_target)}"
end
end

task :configure => makefile

task :compile => makefile do
Dir.chdir(package.build_target) do
cd package.build_target do
msys_sh "make"
end
end
Expand All @@ -88,20 +88,20 @@ namespace(:interpreter) do
full_install_target = File.expand_path(File.join(RubyInstaller::ROOT, package.install_target))

# perform make install
Dir.chdir(package.build_target) do
cd package.build_target do
msys_sh "make install"
end

# verbatim copy the binaries listed in package.dependencies
package.dependencies.each do |dep|
Dir.glob("#{RubyInstaller::MinGW.target}/**/#{dep}").each do |f|
FileUtils.cp(f, File.join(package.install_target, "bin"))
Dir.glob("#{RubyInstaller::MinGW.target}/**/#{dep}").each do |path|
cp path, File.join(package.install_target, "bin")
end
end

# copy original scripts from ruby_1_8 to install_target
Dir.glob("#{package.target}/bin/*").each do |f|
FileUtils.cp(f, File.join(package.install_target,"bin"))
Dir.glob("#{package.target}/bin/*").each do |path|
cp path, File.join(package.install_target, "bin")
end

# remove path reference to sandbox (after install!!!)
Expand All @@ -114,14 +114,14 @@ namespace(:interpreter) do
task :check do
new_ruby = File.join(RubyInstaller::ROOT, package.install_target, "bin").gsub(File::SEPARATOR, File::ALT_SEPARATOR)
ENV['PATH'] = "#{new_ruby};#{ENV['PATH']}"
Dir.chdir(package.build_target) do
cd package.build_target do
msys_sh "make check"
end
end

task :manifest do
manifest = File.open(File.join(package.build_target, "manifest"), 'w')
Dir.chdir(package.install_target) do
cd package.install_target do
Dir.glob("**/*").each do |f|
manifest.puts(f) unless File.directory?(f)
end
Expand All @@ -130,7 +130,7 @@ namespace(:interpreter) do
end

task :irb do
Dir.chdir(File.join(package.install_target, 'bin')) do
cd File.join(package.install_target, 'bin') do
sh "irb"
end
end
Expand Down
192 changes: 96 additions & 96 deletions recipes/packager/msi.rake
@@ -1,96 +1,96 @@
require 'rake'
require 'rake/clean'
require 'erb'

def ruby_version(file)
return nil unless File.exist?(file)
h = {}
version_file = File.read(file)
h[:version] = /RUBY_VERSION "(.+)"$/.match(version_file)[1]
h[:version_code] = /RUBY_VERSION_CODE (.+)$/.match(version_file)[1]
h[:patchlevel] = /RUBY_PATCHLEVEL (.+)$/.match(version_file)[1]
h
end

def rubygems_version(target)
Dir.chdir(target) do
@ret = `ruby -Ilib bin/gem environment packageversion`.chomp
end
@ret
end

packages = [RubyInstaller::Runtime, RubyInstaller::DevKit]

packages.each do |pkg|

version_file = File.join(RubyInstaller::ROOT, pkg.ruby_version_source, 'version.h')
pkg.info = ruby_version(version_file)
pkg.version = pkg.info.nil? ? pkg.version : "#{pkg.info[:version_code]}-p#{pkg.info[:patchlevel]}"
pkg.file = "#{pkg.package_name}-#{pkg.version}.msi"
pkg.target = "pkg\\#{pkg.file}"

namespace(pkg.namespace) do

task :env do
ENV['PACKAGE'] = pkg.namespace.upcase
end

desc "install the product #{pkg.target}"
task :install => pkg.target do
sh "msiexec /i #{pkg.target}"
end

desc "uninstall the #{pkg.namespace} "
task :uninstall => pkg.target do
sh "msiexec /x #{pkg.target}"
end

desc "run #{pkg.namespace} installer without installing the product"
task :test_run => pkg.target do
sh "msiexec /i #{pkg.target} EXECUTEMODE=None"
end

task :configure => :env do
pkg.wix_config['RubyVersion'] = "#{pkg.info[:version] } patchlevel #{pkg.info[:patchlevel] }"
gems = File.join(RubyInstaller::ROOT, pkg.rubygems_version_source)
pkg.wix_config['RubyGemsVersion'] = rubygems_version(gems)
config_file = File.join(RubyInstaller::ROOT, pkg.source, pkg.config_file)
template = ERB.new(File.read(config_file))
output = File.join(File.dirname(config_file), File.basename(config_file, '.erb'))
File.open(output, 'w+'){|f| f.write template.result }
end

task :compile => :configure do
Dir.chdir(pkg.source) do
candle *FileList[ '*.wxs' ]
end
end

directory 'pkg'

file pkg.target => ['pkg', *FileList[ File.join(pkg.source, '*.wxs') ] ] do
Rake::Task["#{pkg.namespace}:compile"].invoke
Dir.chdir(pkg.source) do
wixobj = FileList[ '*.wixobj']
light wixobj, File.join(RubyInstaller::ROOT, pkg.target).gsub('/','\\')
end
end

desc "compile #{pkg.file}"
task :package => pkg.target

task :clobber do
rm_f pkg.target
end

end

desc "compile #{pkg.namespace} msi"
task :package => "#{pkg.namespace}:package"
desc "remove #{pkg.namespace} msi"
task :clobber_package => "#{pkg.namespace}:clobber"

end

desc "remove and rebuild msi"
task :repackage => [:clobber_package, :package]
require 'rake'
require 'rake/clean'
require 'erb'

def ruby_version(file)
return nil unless File.exist?(file)
h = {}
version_file = File.read(file)
h[:version] = /RUBY_VERSION "(.+)"$/.match(version_file)[1]
h[:version_code] = /RUBY_VERSION_CODE (.+)$/.match(version_file)[1]
h[:patchlevel] = /RUBY_PATCHLEVEL (.+)$/.match(version_file)[1]
h
end

def rubygems_version(target)
cd target do
@ret = `ruby -Ilib bin/gem environment packageversion`.chomp
end
@ret
end

packages = [RubyInstaller::Runtime, RubyInstaller::DevKit]

packages.each do |pkg|

version_file = File.join(RubyInstaller::ROOT, pkg.ruby_version_source, 'version.h')
pkg.info = ruby_version(version_file)
pkg.version = pkg.info.nil? ? pkg.version : "#{pkg.info[:version_code]}-p#{pkg.info[:patchlevel]}"
pkg.file = "#{pkg.package_name}-#{pkg.version}.msi"
pkg.target = "pkg\\#{pkg.file}"

namespace(pkg.namespace) do

task :env do
ENV['PACKAGE'] = pkg.namespace.upcase
end

desc "install the product #{pkg.target}"
task :install => pkg.target do
sh "msiexec /i #{pkg.target}"
end

desc "uninstall the #{pkg.namespace} "
task :uninstall => pkg.target do
sh "msiexec /x #{pkg.target}"
end

desc "run #{pkg.namespace} installer without installing the product"
task :test_run => pkg.target do
sh "msiexec /i #{pkg.target} EXECUTEMODE=None"
end

task :configure => :env do
pkg.wix_config['RubyVersion'] = "#{pkg.info[:version] } patchlevel #{pkg.info[:patchlevel] }"
gems = File.join(RubyInstaller::ROOT, pkg.rubygems_version_source)
pkg.wix_config['RubyGemsVersion'] = rubygems_version(gems)
config_file = File.join(RubyInstaller::ROOT, pkg.source, pkg.config_file)
template = ERB.new(File.read(config_file))
output = File.join(File.dirname(config_file), File.basename(config_file, '.erb'))
File.open(output, 'w+'){|f| f.write template.result }
end

task :compile => :configure do
cd pkg.source do
candle *FileList[ '*.wxs' ]
end
end

directory 'pkg'

file pkg.target => ['pkg', *FileList[ File.join(pkg.source, '*.wxs') ] ] do
Rake::Task["#{pkg.namespace}:compile"].invoke
cd pkg.source do
wixobj = FileList[ '*.wixobj']
light wixobj, File.join(RubyInstaller::ROOT, pkg.target).gsub('/','\\')
end
end

desc "compile #{pkg.file}"
task :package => pkg.target

task :clobber do
rm_f pkg.target
end

end

desc "compile #{pkg.namespace} msi"
task :package => "#{pkg.namespace}:package"
desc "remove #{pkg.namespace} msi"
task :clobber_package => "#{pkg.namespace}:clobber"

end

desc "remove and rebuild msi"
task :repackage => [:clobber_package, :package]
2 changes: 1 addition & 1 deletion recipes/packager/wix.rake
Expand Up @@ -104,7 +104,7 @@ namespace(:packager) do
end

task :diff do
Dir.chdir('resources/installer') do
cd 'resources/installer' do
wxs_files = FileList.new('*.wxs'){|fl| fl.exclude('main.wxs') }

diffs = wxs_files.reject do |file|
Expand Down

0 comments on commit b6cc9ea

Please sign in to comment.