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

- old
+ new

@@ -32,10 +32,11 @@ # architecture Can be any, i368, i686, ppc, etc. # dependencies List of packages this program depends. # recommends List of packages that can be used with this package. # replaces List of packages this one replaces. # executables Executable files in this distribution. + # rules (see below) # # RubyGems specific settings: # # autorequire # platform @@ -47,10 +48,49 @@ # # gems # pacman # debian # + # Finally there is one last parameter that you can use for creating packages + # called 'rules'. The rules setting allows you to define how files are + # copied into the distribution package, so instead of a one to one copy + # of the included files, you can actually have a file placed in a different + # location within the distribution. This can be very handy if you wish to + # develop you project with one layout, but need to distribute it with another. + # + # The rules parameter is a literal string that consists of one rule per line. + # A line consists three space separated entries. + # + # from_path, file_glob, to_path + # + # If no 'to_path' is given then it is considered the same as the 'from_path'. + # It also supports two variables $name and $version which will be substitued + # any of these entries. Here is a possible example: + # + # rules: | + # lib **/* lib/$name/$version + # + # This will move any file under lib/ to the equivalent location under lib/$name/$version/. + # The default set of rules is a mirror image transfer, spelled out it would be: + # + # rules: | + # bin * + # ext **/* + # lib **/* + # data **/* + # conf **/* + # + # If your using Rolls against a normal project folder the alterntive is to create + # versioned paths, probably as follows: + # + # rules: | + # ext/$name **/* $name/$version + # lib/$name **/* $name/$version + # data/$name **/* $name/$version + # conf/$name **/* $name/$version ? + # + # Please note that the rules parameter is a new feature and is still considered beta. class Package include TaskUtils @@ -103,52 +143,11 @@ pkg.requirements ||= [] pkg.recommends ||= [] pkg.conflicts ||= [] pkg.replaces ||= [] - # Gem specific - - # load rubygems if available - # (only do this if need be in future?) - begin - require 'rubygems' - rescue LoadError - # no rubygems - end - - if defined?(::Gem) and pkg.gem - if pkg.gem.platform - begin - pkg.gem.platform = ::Gem::Platform.const_get(pkg.gem.platform.upcase) - rescue NameError - pkg.gem.platform = ::Gem::Platform::RUBY - end - 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 ) + @rules = parse_rules( pkg.rules ) end private #-- @@ -158,12 +157,12 @@ 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) ] + from, glob, to = *words + rules << [ vsub(from), vsub(glob), vsub(to) ] } rules end def vsub( str ) @@ -193,51 +192,66 @@ puts "Package directory '#{pkg.package_name}' already exists. Use -f option to overwrite." return nil end end - puts "Creating #{pkg.distribute.join(',')} packages..." + #puts "Creating #{pkg.distribute.join(',')} packages..." # First we make a copy of the files to be distributed. if $PRETEND puts "mkdir_p #{mirror_folder}" else FileUtils.mkdir_p( mirror_folder ) end - @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 ) + trans = transfer_rules() + + list = ::FileList.new + list.include(*pkg.include) + list.exclude(*pkg.exclude) if pkg.exclude + list.resolve + + # build transfer table + folders, files = [], {} + list.each do |from| + to = trans.key?(from) ? trans[from] : from + #to = File.join( mirror_folder, to ) + if File.directory?( from ) + folders << to + else + files[ from ] = to + folders << File.dirname( to ) # ensure creation of files' folder + end + end + + folders.delete('') + folders.uniq! + + # create folders + folders.each do |to| to = File.join( mirror_folder, to ) + if $PRETEND + puts "mkdir_p #{to}" + else + FileUtils.mkdir_p( to ) + end + end + # safe link files + files.each do |from, to| + to = File.join( mirror_folder, to ) if $PRETEND - if File.directory?( from ) - 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 + puts "safe_ln #{from}, #{to}" 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 + FileUtils.safe_ln( from, to ) end end - # TODO Finish pretend mode for the distribution types. - return if $PRETEND + # store package folders and files relative to mirror_folder (gems build uses this) + @package_files = folders + files.values + #@package_files = package_files.collect{ |f| f.sub("#{mirror_folder}/", '') } # Now we create standard packages from the copy. FileUtils.chdir( @release_path ) do pkg.distribute.each do |t| @@ -265,18 +279,31 @@ sh %{#{sh_cmd} #{pkg.package_name}.#{prefix} #{pkg.package_name}} if sh_cmd end puts end + # TODO Finish pretend mode for the distribution types. + return if $PRETEND + # create gem package if pkg.distribute.include?('gem') - if defined?(::Gem) + + # load rubygems if available + begin + require 'rubygems' run_gem - else + rescue LoadError + # no rubygems tell "WARNING: Package .gem requested, but rubygems not found (skipped)." end + +# if defined?(::Gem) +# run_gem +# else +# tell "WARNING: Package .gem requested, but rubygems not found (skipped)." +# end end # create debian package if pkg.distribute.include?('deb') @@ -297,57 +324,34 @@ end end # we can remove mirror folder now - #FileUtils.rm_r(mirror_folder) + FileUtils.rm_r(mirror_folder) unless $PRETEND #or $OPTIONS[:retain] return true end private -# # 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 - + # Determine transfer rules. # + # Rules should proceed from the most general to the most specific. - 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 + def transfer_rules + trans = {} + @rules.each do |rule| + from, glob, to = *rule + to = from unless to #? + files = Dir.glob( File.join( from, glob ) ) + files.each do |file| + trans[file] = File.join( to, file.sub(from,'') ) end end - return file + trans end - # Build a gem package. def run_gem # use subsection if given @@ -367,10 +371,20 @@ else s.add_dependency(d) end } + if pkg.platform + begin + s.platform = ::Gem::Platform.const_get(pkg.platform.upcase) + rescue NameError + s.platform = ::Gem::Platform::RUBY + end + else + s.platform = ::Gem::Platform::RUBY + end + s.summary = pkg.summary s.requirements = pkg.requirements # s.files = Dir.glob("lib/**/*").delete_if {|item| item.include?("CVS")} # s.files.concat Dir.glob("bin/**/*").delete_if {|item| item.include?("CVS")} @@ -387,10 +401,9 @@ s.require_path = 'lib' s.require_paths = pkg.require_paths if pkg.require_paths s.autorequire = pkg.autorequire if pkg.autorequire - s.platform = pkg.platform s.executables = pkg.executables s.bindir = "bin" s.has_rdoc = true