tasks/setup.rb in emdrb-0.3.1 vs tasks/setup.rb in emdrb-0.4.0

- old
+ new

@@ -1,15 +1,18 @@ -# $Id: setup.rb 59 2009-01-23 09:10:01Z dido $ require 'rubygems' require 'rake' require 'rake/clean' require 'fileutils' require 'ostruct' +require 'find' -class OpenStruct; undef :gem; end +class OpenStruct; undef :gem if defined? :gem; end +# TODO: make my own openstruct type object that includes descriptions +# TODO: use the descriptions to output help on the available bones options + PROJ = OpenStruct.new( # Project Defaults :name => nil, :summary => nil, :description => nil, @@ -23,12 +26,12 @@ # System Defaults :ruby_opts => %w(-w), :libs => [], :history_file => 'History.txt', - :manifest_file => 'Manifest.txt', :readme_file => 'README.txt', + :ignore_file => '.bnsignore', # Announce :ann => OpenStruct.new( :file => 'announcement.txt', :text => nil, @@ -46,10 +49,11 @@ ), # Gem Packaging :gem => OpenStruct.new( :dependencies => [], + :development_dependencies => [], :executables => nil, :extensions => FileList['ext/**/extconf.rb'], :files => nil, :need_tar => true, :need_zip => false, @@ -57,11 +61,11 @@ ), # File Annotations :notes => OpenStruct.new( :exclude => %w(^tasks/setup\.rb$), - :extensions => %w(.txt .rb .erb) << '', + :extensions => %w(.txt .rb .erb .rdoc) << '', :tags => %w(FIXME OPTIMIZE TODO) ), # Rcov :rcov => OpenStruct.new( @@ -72,11 +76,11 @@ ), # Rdoc :rdoc => OpenStruct.new( :opts => [], - :include => %w(^lib/ ^bin/ ^ext/ \.txt$), + :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$), :exclude => %w(extconf\.rb$), :main => nil, :dir => 'doc', :remote_dir => nil ), @@ -108,22 +112,22 @@ :opts => [] ) ) # Load the other rake files in the tasks folder -rakefiles = Dir.glob('tasks/*.rake').sort -rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact! +tasks_dir = File.expand_path(File.dirname(__FILE__)) +post_load_fn = File.join(tasks_dir, 'post_load.rake') +rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort +rakefiles.unshift(rakefiles.delete(post_load_fn)).compact! import(*rakefiles) # Setup the project libraries %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir} # Setup some constants -WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32 +DEV_NULL = File.exist?('/dev/null') ? '/dev/null' : 'NUL:' -DEV_NULL = WIN32 ? 'NUL:' : '/dev/null' - def quiet( &block ) io = [STDOUT.dup, STDERR.dup] STDOUT.reopen DEV_NULL STDERR.reopen DEV_NULL block.call @@ -131,25 +135,19 @@ STDOUT.reopen io.first STDERR.reopen io.last $stdout, $stderr = STDOUT, STDERR end -DIFF = if WIN32 then 'diff.exe' - else - if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff' - else 'diff' end - end unless defined? DIFF +DIFF = if system("gdiff '#{__FILE__}' '#{__FILE__}' > #{DEV_NULL} 2>&1") then 'gdiff' + else 'diff' end unless defined? DIFF -SUDO = if WIN32 then '' - else - if quiet {system 'which sudo'} then 'sudo' - else '' end - end +SUDO = if system("which sudo > #{DEV_NULL} 2>&1") then 'sudo' + else '' end unless defined? SUDO -RCOV = WIN32 ? 'rcov.bat' : 'rcov' -RDOC = WIN32 ? 'rdoc.bat' : 'rdoc' -GEM = WIN32 ? 'gem.bat' : 'gem' +RCOV = "#{RUBY} -S rcov" +RDOC = "#{RUBY} -S rdoc" +GEM = "#{RUBY} -S gem" %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib| begin require lib Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true} @@ -160,10 +158,16 @@ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and system("svn --version 2>&1 > #{DEV_NULL}")) HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and system("git --version 2>&1 > #{DEV_NULL}")) +# Add bones as a development dependency +# +if HAVE_BONES + PROJ.gem.development_dependencies << ['bones', ">= #{Bones::VERSION}"] +end + # Reads a file at +path+ and spits out an array of the +paragraphs+ # specified. # # changes = paragraphs_of('History.txt', 0..1).join("\n\n") # summary, *description = paragraphs_of('README.txt', 3, 3..8) @@ -241,12 +245,32 @@ end # Scans the current working directory and creates a list of files that are # candidates to be in the manifest. # -def manifest_files +def manifest files = [] - exclude = Regexp.new(PROJ.exclude.join('|')) + exclude = PROJ.exclude.dup + comment = %r/^\s*#/ + + # process the ignore file and add the items there to the exclude list + if test(?f, PROJ.ignore_file) + ary = [] + File.readlines(PROJ.ignore_file).each do |line| + next if line =~ comment + line.chomp! + line.strip! + next if line.nil? or line.empty? + + glob = line =~ %r/\*\./ ? File.join('**', line) : line + Dir.glob(glob).each {|fn| ary << "^#{Regexp.escape(fn)}"} + end + exclude.concat ary + end + + # generate a regular expression from the exclude list + exclude = Regexp.new(exclude.join('|')) + Find.find '.' do |path| path.sub! %r/^(\.\/|\/)/o, '' next unless test ?f, path next if path =~ exclude files << path