lib/reap/class/package.rb in reap-6.0.0 vs lib/reap/class/package.rb in reap-6.0.1

- old
+ new

@@ -52,28 +52,21 @@ class Package include TaskUtils + KINDS = [ 'bin', 'lib', 'ext', 'data', 'conf', 'doc' ] + LOCATIONS = [ 'dist', 'pkg', 'release', 'package', 'distribution' ] MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~', 'dist', 'pkg', 'release' ] - LOCATIONS = [ 'dist', 'pkg', 'release', 'package', 'distribution' ] attr :pkg # Setup package task settings. def initialize( pkg ) @pkg = pkg - #pkg.name ||= master.name - #pkg.title ||= master.title - #pkg.version ||= master.version - #pkg.project ||= master.project || master.rubyforge.project - #pkg.homepage ||= master.homepage || master.rubyforge.homepage - - pkg.trunk ||= '.' # '.' probably will become the mater default. - pkg.status ||= 'development' pkg.series ||= '1' pkg.author ||= "Anonymous" pkg.maintainer ||= pkg.author pkg.email ||= '' @@ -132,12 +125,58 @@ else pkg.gem.platform = ::Gem::Platform::RUBY end #@autorequire end + + # for a mirror image (but no rules does this too) + # pkg.rules ||= %{ + # bin bin * + # ext ext **/* + # lib lib **/* + # data data **/* + # conf conf **/* + # } + + # for a typical Rolls versioned package + # pkg.rules ||= %{ + # bin bin * + # ext ext/$name **/* $name/$version + # lib lib/$name **/* $name/$version + # data data/$name **/* $name/$version + # conf conf/$name **/* $name/$version + # } + + @transfer = parse_rules( pkg.rules ) end + private + + #-- + # TODO use shellwords + #++ + def parse_rules( spec ) + return [] unless spec + rules = [] #Hash.new { |h,k| h[k] = [] } + lines = spec.strip.split("\n") + lines.each { |line| + words = line.strip.split(/\s+/) + kind, from, glob, to = *words + rules << [ kind, vsub(from), vsub(glob), vsub(to) ] + } + rules + end + + def vsub( str ) + return nil if str.nil? + str = str.gsub( '$version', pkg.version.to_s ) #@version.to_s ) + str = str.gsub( '$name', pkg.name.to_s ) + str + end + + public + # Generate packages. def generate_packages release_folder = File.join( pkg.dir, pkg.package_name ) @@ -147,43 +186,59 @@ @mirror_path = File.expand_path( mirror_folder ) if FileTest.directory?(release_folder) if $FORCE puts "Removing old directory '#{File.expand_path(release_folder)}'..." - FileUtils.rm_r(release_folder) + FileUtils.rm_r(release_folder) unless $PRETEND else puts "Package directory '#{pkg.package_name}' already exists. Use -f option to overwrite." return nil end end puts "Creating #{pkg.distribute.join(',')} packages..." # First we make a copy of the files to be distributed. - FileUtils.mkdir_p( mirror_folder ) #pkg.dir #rescue nil - @package_files = nil - Dir.chdir( pkg.trunk ) do - @package_files = ::FileList.new(*pkg.include) - #package_files.include(*pkg.include) - @package_files.exclude(*pkg.exclude) if pkg.exclude #and not pkg.exclude.empty? - @package_files.resolve # reslove FileList here to be sure we get the right files! + if $PRETEND + puts "mkdir_p #{mirror_folder}" + else + FileUtils.mkdir_p( mirror_folder ) + end - @package_files.each do |f| - from = f #pkg.trunk ? File.join( pkg.trunk, f ) : f - to = File.join( @mirror_path, f ) - to_dir = File.dirname( to ) - FileUtils.mkdir_p( to_dir ) if not File.exist?(to_dir) + @package_files = ::FileList.new + @package_files.include(*pkg.include) + @package_files.exclude(*pkg.exclude) if pkg.exclude #and not pkg.exclude.empty? + #@package_files.resolve # reslove FileList here to be sure we get the right files! + @package_files.each do |from| + to = apply_rules( from ) + to = File.join( mirror_folder, to ) + + if $PRETEND if File.directory?( from ) - FileUtils.mkdir_p( to ) + puts "mkdir_p #{to}" if not File.exist?( to ) else + to_dir = File.dirname( to ) + puts "mkdir_p #{to_dir}" if not File.exist?( to_dir ) + puts "rm_f #{to}" #if File.exist?( to ) + puts "safe_ln #{from}, #{to}" + end + else + if File.directory?( from ) + FileUtils.mkdir_p( to ) if not File.exist?( to ) + else + to_dir = File.dirname( to ) + FileUtils.mkdir_p( to_dir ) if not File.exist?( to_dir ) FileUtils.rm_f( to ) FileUtils.safe_ln( from, to ) end end end + # TODO Finish pretend mode for the distribution types. + return if $PRETEND + # Now we create standard packages from the copy. FileUtils.chdir( @release_path ) do pkg.distribute.each do |t| sh_cmd = nil @@ -249,10 +304,50 @@ return true end private - # This builds the gem package. +# # Copy the files into the release package folder. +# +# def package( kind, from, glob, to ) +# mkdirp = [] +# Dir.chdir( @trunk ) do +# next unless File.directory?( from ) +# Dir.chdir( from ) do +# files = Dir.glob( glob ).reject { |f| File.directory?( f ) } +# files.each do |file| +# f = File.join( from, file ) +# t = to ? File.join( @mirror_path, kind, to, file ) : File.join( @mirror_path, kind, file ) +# #m = "mode(:#{kind})" # MODES[kind] +# d = File.dirname(t) +# unless mkdirp.include?(d) +# puts "makedir_p #{d}" +# mkdirp << d +# end +# puts "safe_ln #{f} => ...#{t.sub(@release_path,'')}" +# end +# end +# end +# end + + # + + def apply_rules( file ) + @transfer.each do |rule| + kind, from, glob, to = *rule + if File.fnmatch( File.join( from, glob ), file ) + if to + return File.join( kind, to, file.sub(from,'') ) + else + return File.join( kind, file.sub(from,'') ) + end + end + end + return file + end + + + # Build a gem package. def run_gem # use subsection if given if pkg.gem