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

#inspector, #logger, #package_recipe, #variables

Instance Method Summary collapse

Methods inherited from PackageBuilder

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

Constructor Details

#initialize(variables, options = {}) ⇒ Builder

Returns a new instance of Builder.

Parameters:

  • variables (Hash<Symbol,Object>)
  • options (Hash) (defaults to: {})

Options Hash (options):



210
211
212
213
214
215
216
217
218
# File 'lib/fpm/fry/recipe/builder.rb', line 210

def initialize( variables, options = {} )
  recipe = options.fetch(:recipe){ Recipe.new }
  variables = variables.dup
  variables.freeze
  @recipe = recipe
  @steps = :steps
  register_default_source_types!
  super(variables, recipe.packages[0], options)
end

Instance Attribute Details

#keep_modified_filesObject (readonly)

Returns the value of attribute keep_modified_files.



309
310
311
# File 'lib/fpm/fry/recipe/builder.rb', line 309

def keep_modified_files
  @keep_modified_files
end

#recipeFPM::Fry::Recipe (readonly)

Returns:



203
204
205
# File 'lib/fpm/fry/recipe/builder.rb', line 203

def recipe
  @recipe
end

Instance Method Details

#add(source, target) ⇒ Object



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

def add(source, target)
  recipe.build_mounts << [source, target]
end

#apt_setup(cmd) ⇒ Object



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

def apt_setup(cmd)
  before_dependencies do
    bash cmd
  end
end

#bash(name = nil, code) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/fpm/fry/recipe/builder.rb', line 262

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

#before_buildObject



277
278
279
280
281
282
# File 'lib/fpm/fry/recipe/builder.rb', line 277

def before_build
  steps, @steps = @steps, :before_build
  yield
ensure
  @steps = steps
end

#before_dependenciesObject



284
285
286
287
288
289
# File 'lib/fpm/fry/recipe/builder.rb', line 284

def before_dependencies
  steps, @steps = @steps, :before_dependencies
  yield
ensure
  @steps = steps
end

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



291
292
293
294
# File 'lib/fpm/fry/recipe/builder.rb', line 291

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

#input_hooksObject



296
297
298
# File 'lib/fpm/fry/recipe/builder.rb', line 296

def input_hooks
  recipe.input_hooks
end

#keep_modified_files!Object



311
312
313
# File 'lib/fpm/fry/recipe/builder.rb', line 311

def keep_modified_files!
  @keep_modified_files = true
end

#load_file(file) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/fpm/fry/recipe/builder.rb', line 220

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



300
301
302
303
304
305
306
307
# File 'lib/fpm/fry/recipe/builder.rb', line 300

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, logger: logger, inspector: inspector).instance_eval(&block)
end

#run(*args) ⇒ Object



251
252
253
254
255
256
257
258
259
260
# File 'lib/fpm/fry/recipe/builder.rb', line 251

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



233
234
235
236
237
238
239
# File 'lib/fpm/fry/recipe/builder.rb', line 233

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