lib/build-tool/vcs/archive.rb in build-tool-0.2 vs lib/build-tool/vcs/archive.rb in build-tool-0.3
- old
+ new
@@ -17,14 +17,14 @@
Archive.new( self )
end
end # class ArchiveConfiguration
-
class Archive < Base
class ArchiveError < BuildTool::Error; end
+ class FileNotFoundError < BuildTool::Error; end
#
### Attributes
#
def name
@@ -33,10 +33,18 @@
def fetching_supported?
true
end
+ def patches_supported?
+ true
+ end
+
+ def apply_patches_after_rebase?
+ true
+ end
+
def archive_local_path
"#{File.dirname( local_path )}/#{archive_name}"
end
def archive_name
@@ -53,11 +61,29 @@
def checkedout?
File.exist? archive_local_path
end
+ def apply_patches( patches )
+ patches.each do |patch|
+ full_path = self.recipe.find_first_config_file( "custom/#{config.module.name}/patches/#{patch}.patch" )
+ if full_path.nil?
+ raise FileNotFoundError, "Patch '#{patch}' not found from module #{config.module.name}."
+ end
+ logger.info "Applying patch #{patch}"
+ self.class.execute( "patch -p1 -i #{full_path}", local_path )
+ end
+
+ end
+
def clone
+ fetch()
+ rebase()
+ 0
+ end
+
+ def fetch()
# Check if the archive is already downloaded
if File.exist? archive_local_path
logger.debug "Archive already fetched. Skipping."
return 0
end
@@ -81,39 +107,13 @@
target.putc c
end
}
target.close()
end
-
- # Determine if the archive has a top level directory
- topdir = guess_top_level_directory()
-
- if archive_name =~ /(\.tgz|\.tar\.gz)$/
- if self.class.execute( "gunzip -c #{archive_local_path} | tar xf -", File.dirname(local_path) ) != 0
- raise StandardError, "Failed to unpack the archive: $?"
- end
- else
- raise NotImplementedError, "No idea how to unpack the archive"
- end
-
- # Rename the top level directory to our desired path
- logger.trace "mv #{File.dirname(local_path)}/#{topdir} #{local_path}"
- if !$noop
- FileUtils.move( "#{File.dirname(local_path)}/#{topdir}", local_path )
- end
- 0
+ return 0
end
- def fetch()
- if !checkedout?
- clone
- else
- # No update for archives
- end
- return true
- end
-
def guess_top_level_directory
return "<topdir>" if $noop
topdir = nil
if archive_name =~ /(\.tgz|\.tar\.gz)$/
if self.class.execute( "gunzip -c #{archive_local_path} | tar tf -" ) { |line|
@@ -121,18 +121,46 @@
if topdir and topdir != rc[1]
raise StandardError, "Unable to determine toplevel directory for archive #{archive_name}!"
end
topdir = rc[1]
} != 0
- raise StandardError, "Failed to unpack the archive: $?"
+ # No topdir
+ return nil
end
else
- raise NotImplementedError, "No idea how to unpack the archive"
+ raise NotImplementedError, "No idea how to unpack the archive '#{archive_name}'."
end
return topdir
end
def rebase
+
+ # Check if the archive is already downloaded
+ if !File.exist? archive_local_path
+ logger.debug "Archive not fetched. Skipping."
+ return 0
+ end
+
+ if local_path_exist?
+ return 0
+ end
+
+ # Create the directory we want to use to checkout
+ FileUtils.mkdir_p local_path if !$noop
+
+ if archive_name =~ /(\.tgz|\.tar\.gz)$/
+ if guess_top_level_directory()
+ cmd = "gunzip -c #{archive_local_path} | tar --strip-components=1 --extract --file=- --directory=#{local_path}"
+ else
+ cmd = "gunzip -c #{archive_local_path} | tar --strip-components=0 --extract --file=- --directory=#{local_path}"
+ end
+ if self.class.execute( cmd ) != 0
+ raise StandardError, "Failed to unpack the archive: $?"
+ end
+ else
+ raise NotImplementedError, "No idea how to unpack the archive"
+ end
+
0
end
end # class Archive