lib/autobuild/importer.rb in autobuild-1.6.5 vs lib/autobuild/importer.rb in autobuild-1.7.0.rc1
- old
+ new
@@ -85,16 +85,32 @@
def retry_count=(count)
@options[:retry_count] = count
end
def patches
- if @options[:patches].respond_to?(:to_ary)
- @options[:patches]
- elsif !@options[:patches]
- []
+ patches =
+ if @options[:patches].respond_to?(:to_ary)
+ @options[:patches]
+ elsif !@options[:patches]
+ []
+ else
+ [[@options[:patches], 0]]
+ end
+
+ if patches.size == 2 && patches[0].respond_to?(:to_str) && patches[1].respond_to?(:to_int)
+ patches = [patches]
else
- [@options[:patches]]
+ patches.map do |obj|
+ if obj.respond_to?(:to_str)
+ [obj, 0]
+ elsif obj.respond_to?(:to_ary)
+ obj
+ else
+ raise Arguments, "wrong patch specification #{obj.inspect}"
+ obj
+ end
+ end
end
end
def perform_update(package)
cur_patches = currently_applied_patches(package)
@@ -137,11 +153,11 @@
raise
end
package.message "update failed in #{package.srcdir}, retrying (#{retry_count}/#{self.retry_count})"
retry
ensure
- package.progress_done
+ package.progress_done "updated %s"
end
patch(package)
package.updated = true
rescue Interrupt
@@ -149,11 +165,11 @@
rescue Autobuild::Exception => e
fallback(e, package, :import, package)
end
def perform_checkout(package)
- package.progress_start "checking out %s" do
+ package.progress_start "checking out %s", :done_message => 'checked out %s' do
retry_count = 0
begin
checkout(package)
rescue Interrupt
raise
@@ -224,27 +240,39 @@
# have been called)
def patchlist(package)
File.join(package.srcdir, "patches-autobuild-stamp")
end
- def call_patch(package, reverse, file)
+ def call_patch(package, reverse, file, patch_level)
patch = Autobuild.tool('patch')
Dir.chdir(package.srcdir) do
- Subprocess.run(package, :patch, patch, '-p0', (reverse ? '-R' : nil), '--forward', :input => file)
+ Subprocess.run(package, :patch, patch, "-p#{patch_level}", (reverse ? '-R' : nil), '--forward', :input => file)
end
end
- def apply(package, path); call_patch(package, false, path) end
- def unapply(package, path); call_patch(package, true, path) end
+ def apply(package, path, patch_level = 0); call_patch(package, false, path, patch_level) end
+ def unapply(package, path, patch_level = 0); call_patch(package, true, path, patch_level) end
def currently_applied_patches(package)
patches_file = patchlist(package)
if !File.exists?(patches_file) then []
else
+ current_patches = []
File.open(patches_file) do |f|
- f.readlines.collect { |path| path.rstrip }
+ f.readlines.each do |line|
+ line = line.rstrip
+ if line =~ /^(.*)\s+(\d+)$/
+ path = $1
+ level = Integer($2)
+ else
+ path = line
+ level = 0
+ end
+ current_patches << [path, level]
+ end
end
+ current_patches
end
end
def patch(package, patches = self.patches)
# Get the list of already applied patches
@@ -266,20 +294,21 @@
elsif unapply_count > 0
package.message "patching %s: unapplying #{unapply_count} patch(es)"
end
while p = cur_patches.last
- unapply(package, p)
+ p, level = *p
+ unapply(package, p, level)
cur_patches.pop
end
- patches.to_a.each do |p|
- apply(package, p)
- cur_patches << p
+ patches.to_a.each do |p, level|
+ apply(package, p, level)
+ cur_patches << [p, level]
end
ensure
File.open(patchlist(package), 'w+') do |f|
- f.write(cur_patches.join("\n"))
+ f.write(cur_patches.map { |p, l| "#{p} #{l}" }.join("\n"))
end
end
return true
end