Class: FPM::Cookery::Packager
- Inherits:
-
Object
- Object
- FPM::Cookery::Packager
- Includes:
- Utils
- Defined in:
- lib/fpm/cookery/packager.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#recipe ⇒ Object
readonly
Returns the value of attribute recipe.
Instance Method Summary collapse
- #add_scripts(recipe, input) ⇒ Object
- #build_cookie_name(name) ⇒ Object
- #build_package(recipe, config) ⇒ Object
- #cleanup ⇒ Object
- #dispense ⇒ Object
-
#initialize(recipe, config = {}) ⇒ Packager
constructor
A new instance of Packager.
- #install_deps ⇒ Object
- #keep_destdir? ⇒ Boolean
-
#remove_excluded_files(recipe) ⇒ Object
Remove all excluded files from the destdir so they do not end up in the package.
- #skip_package? ⇒ Boolean
- #target=(target) ⇒ Object
Constructor Details
#initialize(recipe, config = {}) ⇒ Packager
Returns a new instance of Packager.
20 21 22 23 |
# File 'lib/fpm/cookery/packager.rb', line 20 def initialize(recipe, config = {}) @recipe = recipe @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/fpm/cookery/packager.rb', line 18 def config @config end |
#recipe ⇒ Object (readonly)
Returns the value of attribute recipe.
18 19 20 |
# File 'lib/fpm/cookery/packager.rb', line 18 def recipe @recipe end |
Instance Method Details
#add_scripts(recipe, input) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/fpm/cookery/packager.rb', line 179 def add_scripts(recipe, input) error = false scripts = [:pre_install, :post_install, :pre_uninstall, :post_uninstall] scripts.each do |script| unless recipe.send(script).nil? script_file = FPM::Cookery::Path.new(recipe.send(script)) # If the script file is an absolute path, just use that path. # Otherwise consider the location relative to the recipe. unless script_file.absolute? script_file = File.("../#{script_file.to_s}", recipe.filename) end if File.exists?(script_file) input.add_script(script, File.read(script_file.to_s)) else Log.error "#{script} script '#{script_file}' is missing" error = true end end end exit(1) if error end |
#build_cookie_name(name) ⇒ Object
141 142 143 |
# File 'lib/fpm/cookery/packager.rb', line 141 def (name) (recipe.builddir/".build-cookie-#{name.gsub(/[^\w]/,'_')}").to_s end |
#build_package(recipe, config) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/fpm/cookery/packager.rb', line 145 def build_package(recipe, config) recipe.pkgdir.mkdir Dir.chdir(recipe.pkgdir) do version = FPM::Cookery::Package::Version.new(recipe, @target, config) maintainer = FPM::Cookery::Package::Maintainer.new(recipe, config) input = recipe.input(config) input.version = version input.maintainer = maintainer.to_s input.vendor = version.vendor if version.vendor input.epoch = version.epoch if version.epoch add_scripts(recipe, input) remove_excluded_files(recipe) output_class = FPM::Package.types[@target] output = input.convert(output_class) begin output.output(output.to_s) rescue FPM::Package::FileAlreadyExists Log.info "Removing existing package file: #{output.to_s}" FileUtils.rm_f(output.to_s) retry ensure input.cleanup if input output.cleanup if output Log.info "Created package: #{File.join(Dir.pwd, output.to_s)}" end end end |
#cleanup ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fpm/cookery/packager.rb', line 38 def cleanup Log.info "Cleanup!" # TODO(sissel): do some sanity checking to make sure we don't # accidentally rm -rf the wrong thing. FileUtils.rm_rf(recipe.builddir) FileUtils.rm_rf(recipe.destdir) end |
#dispense ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fpm/cookery/packager.rb', line 51 def dispense env = ENV.to_hash package_name = "#{recipe.name}-#{recipe.version}" platform = FPM::Cookery::Facts.platform target = FPM::Cookery::Facts.target Log.info "Starting package creation for #{package_name} (#{platform}, #{target})" Log.info '' # RecipeInspector.verify!(recipe) if config.fetch(:dependency_check, true) DependencyInspector.verify!(recipe.depends, recipe.build_depends) end recipe.installing = false if defined? recipe.source_handler() source = recipe.source_handler recipe.cachedir.mkdir Dir.chdir(recipe.cachedir) do Log.info "Fetching source: #{source.source_url}" source.fetch(:quiet => config[:quiet]) if source.checksum? SourceIntegrityCheck.new(recipe).tap do |check| if check.checksum_missing? Log.warn 'Recipe does not provide a checksum. (sha256, sha1 or md5)' Log.puts <<-__WARN Digest: #{check.digest} Checksum: #{check.checksum_actual} Filename: #{check.filename} __WARN elsif check.error? Log.error 'Integrity check failed!' Log.puts <<-__ERROR Digest: #{check.digest} Checksum expected: #{check.checksum_expected} Checksum actual: #{check.checksum_actual} Filename: #{check.filename} __ERROR exit 1 end #end checksum missing end #end check end #end checksum end #end chdir cachedir recipe.builddir.mkdir Dir.chdir(recipe.builddir) do extracted_source = source.extract Dir.chdir(extracted_source) do #Source::Patches.new(recipe.patches).apply! = (package_name) if File.exists?() Log.warn "Skipping build of #{recipe.name} because build cookie found (#{})," \ " use \"fpm-cook clean\" to rebuild!" else Log.info "Building in #{File.(extracted_source, recipe.builddir)}" recipe.build and FileUtils.touch() end FileUtils.rm_rf(recipe.destdir) unless keep_destdir? recipe.destdir.mkdir unless File.exists?(recipe.destdir) begin recipe.installing = true Log.info "Installing into #{recipe.destdir}" recipe.install ensure recipe.installing = false end end #end chdir extracted_source end #end chdir builddir end #end defined source_handler if skip_package? Log.info "Package building disabled" else build_package(recipe, config) end ensure # Make sure we reset the environment. ENV.replace(env) end |
#install_deps ⇒ Object
46 47 48 49 |
# File 'lib/fpm/cookery/packager.rb', line 46 def install_deps DependencyInspector.verify!(recipe.depends, recipe.build_depends) Log.info("All dependencies installed!") end |
#keep_destdir? ⇒ Boolean
29 30 31 |
# File 'lib/fpm/cookery/packager.rb', line 29 def keep_destdir? !!config[:keep_destdir] end |
#remove_excluded_files(recipe) ⇒ Object
Remove all excluded files from the destdir so they do not end up in the package.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/fpm/cookery/packager.rb', line 207 def remove_excluded_files(recipe) if File.directory?(recipe.destdir) Dir.chdir(recipe.destdir.to_s) do Dir['**/*'].each do |file| recipe.exclude.each do |ex| if File.fnmatch(ex, file) Log.info "Exclude file: #{file}" FileUtils.rm_f(file) end end end end end end |
#skip_package? ⇒ Boolean
25 26 27 |
# File 'lib/fpm/cookery/packager.rb', line 25 def skip_package? !!config[:skip_package] end |
#target=(target) ⇒ Object
33 34 35 36 |
# File 'lib/fpm/cookery/packager.rb', line 33 def target=(target) # TODO(sissel): do sanity checking @target = target end |