Class: FPM::Fry::Recipe::Builder

Inherits:
PackageBuilder show all
Defined in:
lib/fpm/fry/recipe/builder.rb

Instance Attribute Summary collapse

Attributes inherited from PackageBuilder

#logger, #package_recipe, #variables

Instance Method Summary collapse

Methods inherited from PackageBuilder

#after_install, #after_remove, #before_install, #before_remove, #codename, #conflicts, #depends, #distribution, #distribution_version, #files, #flavour, #iteration, #name, #output_hooks, #plugin, #provides, #replaces, #script, #vendor, #version

Constructor Details

#initialize(variables, recipe = Recipe.new, options = {}) ⇒ Builder

Returns a new instance of Builder.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/fpm/fry/recipe/builder.rb', line 179

def initialize( variables, recipe = Recipe.new, options = {})
  variables = variables.dup
  if variables[:distribution] && !variables[:flavour] && OsDb[variables[:distribution]]
    variables[:flavour] = OsDb[variables[:distribution]][:flavour]
  end
  if !variables[:codename] && OsDb[variables[:distribution]] && variables[:distribution_version]
    codename = OsDb[variables[:distribution]][:codenames].find{|name,version| variables[:distribution_version].start_with? version }
    variables[:codename] = codename[0] if codename
  end
  variables.freeze
  @recipe = recipe
  @before_build = false
  register_default_source_types!
  super(variables, recipe.packages[0], options)
end

Instance Attribute Details

#recipeObject (readonly)

Returns the value of attribute recipe.



177
178
179
# File 'lib/fpm/fry/recipe/builder.rb', line 177

def recipe
  @recipe
end

Instance Method Details

#bash(name = nil, code) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/fpm/fry/recipe/builder.rb', line 227

def bash( name = nil, code )
  if name
    code = Recipe::Step.new(name, code)
  end
  # Don't do this at home
  if @before_build
    recipe.before_build_steps << code
  else
    recipe.steps << code
  end
end

#before_buildObject



239
240
241
242
243
244
# File 'lib/fpm/fry/recipe/builder.rb', line 239

def before_build
  @before_build = true
  yield
ensure
  @before_build = false
end

#build_depends(name, options = {}) ⇒ Object



246
247
248
249
# File 'lib/fpm/fry/recipe/builder.rb', line 246

def build_depends( name , options = {} )
  name, options = parse_package(name, options)
  recipe.build_depends[name] = options
end

#input_hooksObject



251
252
253
# File 'lib/fpm/fry/recipe/builder.rb', line 251

def input_hooks
  recipe.input_hooks
end

#load_file(file) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/fpm/fry/recipe/builder.rb', line 195

def load_file( file )
  file = File.expand_path(file)
  begin
    content = IO.read(file)
  rescue Errno::ENOENT => e
    raise NotFound, e
  end
  basedir = File.dirname(file)
  Dir.chdir(basedir) do
    instance_eval(content,file,0)
  end
end

#package(name, &block) ⇒ Object



255
256
257
258
259
260
261
262
# File 'lib/fpm/fry/recipe/builder.rb', line 255

def package(name, &block)
  pr = PackageRecipe.new
  pr.name = name
  pr.version = package_recipe.version
  pr.iteration = package_recipe.iteration
  recipe.packages << pr
  PackageBuilder.new(variables, pr).instance_eval(&block)
end

#run(*args) ⇒ Object



216
217
218
219
220
221
222
223
224
225
# File 'lib/fpm/fry/recipe/builder.rb', line 216

def run(*args)
  if args.first.kind_of? Hash
    options = args.shift
  else
    options = {}
  end
  command = args.shift
  name = options.fetch(:name){ [command,*args].select{|c| c[0] != '-' }.join(' ') }
  bash( name, Shellwords.join([command, *args]) )
end

#source(url, options = {}) ⇒ Object



208
209
210
211
212
213
214
# File 'lib/fpm/fry/recipe/builder.rb', line 208

def source( url , options = {} )
  options = options.merge(logger: logger)
  source = Source::Patched.decorate(options) do |options|
    guess_source(url,options).new(url, options)
  end
  recipe.source = source
end