Class: Crate::Dependency
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Crate::Dependency
- Includes:
- Utils
- Defined in:
- lib/crate/dependency.rb
Overview
Create a build task that will download, checksum and build and install an upstream source
This task will create the following targets:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#build_commands ⇒ Object
array of shell commands for building.
-
#install_commands ⇒ Object
array of shell commands for installing.
-
#name ⇒ Object
Name of the task, this is also the Rake namespace underwhich all other tasks will follow.
-
#upstream_source ⇒ Object
Upstream location.
-
#version ⇒ Object
Version of the upstream version.
Instance Method Summary collapse
-
#build ⇒ Object
Execute all the build commands.
-
#build_dir ⇒ Object
The build directory for this particular task.
-
#cd_and_sh(dir, cmds) ⇒ Object
Change to a directory and execute a sequence of commands.
-
#define ⇒ Object
Define all the tasks in the namespace of the
name
of this task. - #define_build ⇒ Object
- #define_download ⇒ Object
- #define_install ⇒ Object
- #define_patch ⇒ Object
- #define_unpack ⇒ Object
- #define_verify ⇒ Object
-
#depends_on(other_dependency) ⇒ Object
allow this task to say it depends on something else.
-
#dotfile(name) ⇒ Object
return the full path to a named dotfile.
-
#dotfile!(name) ⇒ Object
make the given dotfile.
-
#initialize(name = nil, version = nil) {|_self| ... } ⇒ Dependency
constructor
Create a Crate Dependency with the given name and version.
-
#install ⇒ Object
Execute all the install commands.
-
#install_dir ⇒ Object
The fake root directory to install into.
-
#local_source ⇒ Object
The local on disk copy of the upstream source.
-
#logger ⇒ Object
handle to the top level logger.
-
#patch_files ⇒ Object
patch the upacked source with files that are in the recipe directory.
-
#pkg_dir ⇒ Object
The directory this task unpacks into.
-
#pkg_dir=(pd) ⇒ Object
override the directory that the local source unpacks into if it is not
name-version
. -
#recipe_dir ⇒ Object
The recipe directory for this particular task.
-
#sh(cmd) ⇒ Object
Execute a shell command, sending the command name to the logger at info level and all the output to the logger at the debug level.
-
#upstream_md5=(checksum) ⇒ Object
record the upstream md5 checksum.
- #upstream_sha1 ⇒ Object
-
#upstream_sha1=(checksum) ⇒ Object
record the upstream sha1 checksum.
- #usptream_md5 ⇒ Object
Constructor Details
#initialize(name = nil, version = nil) {|_self| ... } ⇒ Dependency
Create a Crate Dependency with the given name and version
34 35 36 37 38 39 40 41 42 |
# File 'lib/crate/dependency.rb', line 34 def initialize( name = nil, version = nil ) @name = name @version = version @install_commands = [] @build_commands = [] yield self if block_given? @upstream_source = URI.parse( @upstream_source ) define unless name.nil? or version.nil? end |
Instance Attribute Details
#build_commands ⇒ Object
array of shell commands for building
26 27 28 |
# File 'lib/crate/dependency.rb', line 26 def build_commands @build_commands end |
#install_commands ⇒ Object
array of shell commands for installing
29 30 31 |
# File 'lib/crate/dependency.rb', line 29 def install_commands @install_commands end |
#name ⇒ Object
Name of the task, this is also the Rake namespace underwhich all other tasks will follow
17 18 19 |
# File 'lib/crate/dependency.rb', line 17 def name @name end |
#upstream_source ⇒ Object
Upstream location
23 24 25 |
# File 'lib/crate/dependency.rb', line 23 def upstream_source @upstream_source end |
#version ⇒ Object
Version of the upstream version
20 21 22 |
# File 'lib/crate/dependency.rb', line 20 def version @version end |
Instance Method Details
#build ⇒ Object
Execute all the build commands
237 238 239 |
# File 'lib/crate/dependency.rb', line 237 def build cd_and_sh( pkg_dir, build_commands ) end |
#build_dir ⇒ Object
The build directory for this particular task
47 48 49 |
# File 'lib/crate/dependency.rb', line 47 def build_dir @build_dir ||= File.join(Crate.project.build_dir, name ) end |
#cd_and_sh(dir, cmds) ⇒ Object
Change to a directory and execute a sequence of commands
251 252 253 254 255 256 257 |
# File 'lib/crate/dependency.rb', line 251 def cd_and_sh( dir, cmds ) Dir.chdir( dir ) do cmds.each do |cmd| sh cmd end end end |
#define ⇒ Object
Define all the tasks in the namespace of the name
of this task.
The dependency chain is:
:install => :build => :patch => :unpack => :verify => :download
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/crate/dependency.rb', line 130 def define logger.debug "Defining tasks for #{name} #{version}" namespace "#{name}" do define_download define_verify define_unpack define_patch define_build define_install task :done => "#{name}:install" task :default => "#{name}:done" end desc "Build and Install #{name} #{version}" task name => "#{name}:default" end |
#define_build ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/crate/dependency.rb', line 200 def define_build desc "Build #{name} #{version}" task :build => dotfile( 'build' ) do logger.info "#{name} #{version} built" end file dotfile( 'build' ) => "#{name}:patch" do logger.info "Bulding #{name} #{version}" Dir.chdir( pkg_dir ) do build end dotfile!( 'build' ) end ::CLEAN << dotfile( 'build' ) end |
#define_download ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/crate/dependency.rb', line 149 def define_download file local_source do |t| logger.info "Downloading #{upstream_source} to #{t.name}" download( upstream_source, t.name ) end desc "Download #{File.basename( local_source )}" task :download => local_source end |
#define_install ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/crate/dependency.rb', line 216 def define_install desc "Install #{name} into #{Crate.project.install_dir}" task :install => dotfile('install') do logger.info "#{name} #{version} is installed" end file dotfile( 'install' ) => "#{name}:build" do logger.info "Installing #{name} #{version}" Dir.chdir( pkg_dir ) do install end dotfile!( 'install' ) end ::CLEAN << dotfile( 'install' ) end |
#define_patch ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/crate/dependency.rb', line 183 def define_patch desc "Apply patches to #{name}" task :patch => dotfile( 'patch' ) do logger.info "#{name} #{version} is patched" end file dotfile( 'patch' ) => "#{name}:unpack" do logger.info "Patching #{name} #{version}" patch_files.each do |pfile| logger.info "applying patch #{File.basename( pfile ) }" apply_patch( pfile, pkg_dir ) end dotfile!( 'patch' ) end ::CLEAN << dotfile( 'patch' ) end |
#define_unpack ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/crate/dependency.rb', line 172 def define_unpack #-- unpack desc "Unpack #{name} into #{build_dir}" task :unpack => "#{name}:verify" do logger.info "Unpacking" unpack( local_source, build_dir ) FileUtils.rm_f dotfile( 'patch' ) end ::CLEAN << pkg_dir end |
#define_verify ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/crate/dependency.rb', line 159 def define_verify desc "Verify source against its checksum" task :verify => "#{name}:download" do if @digest then if @digest.valid?( local_source ) then logger.info "#{local_source} validates against #{@digest.hex}" else raise "#{local_source} does not have checksum #{@digest.hex}" end end end end |
#depends_on(other_dependency) ⇒ Object
allow this task to say it depends on something else. This is a build dependency
293 294 295 296 297 |
# File 'lib/crate/dependency.rb', line 293 def depends_on( other_dependency ) namespace name do task :build => "#{other_dependency}:done" end end |
#dotfile(name) ⇒ Object
return the full path to a named dotfile
275 276 277 |
# File 'lib/crate/dependency.rb', line 275 def dotfile( name ) File.join( build_dir, ".#{name}" ) end |
#dotfile!(name) ⇒ Object
make the given dotfile
282 283 284 285 286 287 |
# File 'lib/crate/dependency.rb', line 282 def dotfile!( name ) File.open( dotfile( name ), "w" ) do |f| h = { 'name' => self.name, 'version' => self.version, "#{name}_timestsamp" => Time.now } f.puts h.to_yaml end end |
#install ⇒ Object
Execute all the install commands
244 245 246 |
# File 'lib/crate/dependency.rb', line 244 def install cd_and_sh( pkg_dir, install_commands ) end |
#install_dir ⇒ Object
The fake root directory to install into
61 62 63 |
# File 'lib/crate/dependency.rb', line 61 def install_dir Crate.project.install_dir end |
#local_source ⇒ Object
The local on disk copy of the upstream source
90 91 92 |
# File 'lib/crate/dependency.rb', line 90 def local_source @local_source ||= File.join( build_dir, File.basename( upstream_source.path ) ) end |
#logger ⇒ Object
handle to the top level logger
68 69 70 |
# File 'lib/crate/dependency.rb', line 68 def logger Crate.project.logger end |
#patch_files ⇒ Object
patch the upacked source with files that are in the recipe directory
302 303 304 |
# File 'lib/crate/dependency.rb', line 302 def patch_files Dir[File.join( recipe_dir, "*.patch" )].sort end |
#pkg_dir ⇒ Object
The directory this task unpacks into
75 76 77 |
# File 'lib/crate/dependency.rb', line 75 def pkg_dir @pkg_dir ||= File.join( self.build_dir, "#{name + ( version ? "-#{version}" : "" ) }" ) end |
#pkg_dir=(pd) ⇒ Object
override the directory that the local source unpacks into if it is not name-version
83 84 85 |
# File 'lib/crate/dependency.rb', line 83 def pkg_dir=( pd ) @pkg_dir = File.join( self.build_dir, pd ) end |
#recipe_dir ⇒ Object
The recipe directory for this particular task
54 55 56 |
# File 'lib/crate/dependency.rb', line 54 def recipe_dir @recipe_dir ||= File.join( Crate.project.recipe_dir, name ) end |
#sh(cmd) ⇒ Object
Execute a shell command, sending the command name to the logger at info level and all the output to the logger at the debug level
263 264 265 266 267 268 269 270 |
# File 'lib/crate/dependency.rb', line 263 def sh( cmd ) logger.info( cmd ) io = IO.popen( "#{cmd} 2>&1" ) io.each_line do |l| logger.debug( l.strip ) end end |
#upstream_md5=(checksum) ⇒ Object
record the upstream md5 checksum
111 112 113 |
# File 'lib/crate/dependency.rb', line 111 def upstream_md5=( checksum ) @digest = Crate::Digest.md5( checksum ) end |
#upstream_sha1 ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/crate/dependency.rb', line 100 def upstream_sha1 if @digest then return @digest.hex else return nil end end |
#upstream_sha1=(checksum) ⇒ Object
record the upstream sha1 checksum
97 98 99 |
# File 'lib/crate/dependency.rb', line 97 def upstream_sha1=( checksum ) @digest = Crate::Digest.sha1( checksum ) end |
#usptream_md5 ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/crate/dependency.rb', line 114 def usptream_md5 if @digest then return @digest.hex else return nil end end |