Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework dependency handling on "fpm-cook package" #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/fpm/cookery/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class CLI < Clamp::Command
option ['-p', '--platform'], 'PLATFORM', 'set the target platform (centos, ubuntu, debian)'
option ['-q', '--quiet'], :flag, 'Disable verbose output like progress bars'
option ['-V', '--version'], :flag, 'show fpm-cookery and fpm version'
option '--[no-]deps', :flag, 'enable/disable dependency checking',
:attribute_name => 'dependency_check'
option '--[no-]install-build-depends', :flag, 'enable/disable installation of build dependencies',
:attribute_name => 'install_build_depends'
option '--[no-]install-depends', :flag, 'enable/disable installation of dependencies',
:attribute_name => 'install_depends'
option '--tmp-root', 'DIR', 'directory root for temporary files',
:attribute_name => 'tmp_root'
option '--pkg-dir', 'DIR', 'directory for built packages',
Expand Down Expand Up @@ -128,6 +130,7 @@ class InstallDepsCmd < Command

def exec(config, recipe, packager)
packager.install_deps
Log.info('All dependencies installed!')
end
end

Expand All @@ -142,6 +145,7 @@ def exec(config, recipe, packager)
else
packager.install_build_deps
end
Log.info('Build dependencies installed!')
end
end

Expand Down
7 changes: 4 additions & 3 deletions lib/fpm/cookery/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ module Cookery
class Config
ATTRIBUTES = [
:color, :debug, :target, :platform, :maintainer, :vendor,
:skip_package, :keep_destdir, :dependency_check, :quiet,
:tmp_root, :pkg_dir, :cache_dir
:skip_package, :keep_destdir, :install_build_depends,
:install_depends, :quiet, :tmp_root, :pkg_dir, :cache_dir
].freeze

DEFAULTS = {
:color => true,
:debug => false,
:dependency_check => true,
:install_build_depends => false,
:install_depends => false,
:skip_package => false,
:keep_destdir => false,
:quiet => false
Expand Down
7 changes: 5 additions & 2 deletions lib/fpm/cookery/omnibus_packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ def run

dep_recipes = load_omnibus_recipes(recipe)
dep_recipes.uniq.each do |dep_recipe|
pkg = FPM::Cookery::Packager.new(dep_recipe, :skip_package => true,
:keep_destdir => true, :dependency_check => config.dependency_check )
packager_config = config.to_hash.merge({
:skip_package => true,
:keep_destdir => true
})
pkg = FPM::Cookery::Packager.new(dep_recipe, packager_config)
pkg.target = FPM::Cookery::Facts.target.to_s

Log.info "Located recipe for child recipe #{dep_recipe.name}; starting build"
Expand Down
24 changes: 12 additions & 12 deletions lib/fpm/cookery/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ def cleanup
end

def install_build_deps
recipe.run_lifecycle_hook(:before_dependency_installation)
DependencyInspector.verify!([], recipe.build_depends)
recipe.run_lifecycle_hook(:after_dependency_installation)
Log.info("Build dependencies installed!")
install_dependencies([], recipe.build_depends)
end

def install_deps
install_dependencies(recipe.depends, recipe.build_depends)
end

def install_dependencies(dependencies, build_dependencies)
recipe.run_lifecycle_hook(:before_dependency_installation)
DependencyInspector.verify!(recipe.depends, recipe.build_depends)
DependencyInspector.verify!(Array(dependencies), Array(build_dependencies))
recipe.run_lifecycle_hook(:after_dependency_installation)
Log.info("All dependencies installed!")
end


def dispense
env = ENV.to_hash
package_name = "#{recipe.name}-#{recipe.version}"
Expand All @@ -67,11 +66,12 @@ def dispense
Log.info "Starting package creation for #{package_name} (#{platform}, #{target})"
Log.info ''

# RecipeInspector.verify!(recipe)
if config.fetch(:dependency_check, true)
recipe.run_lifecycle_hook(:before_dependency_installation)
DependencyInspector.verify!(recipe.depends, recipe.build_depends)
recipe.run_lifecycle_hook(:after_dependency_installation)
if config.fetch(:install_build_depends, false)
install_build_deps
elsif config.fetch(:install_depends, false)
install_deps
else
Log.debug 'Not installing any dependencies automatically'
end

recipe.installing = false
Expand Down
17 changes: 13 additions & 4 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ def self.common_tests(name)
common_tests(:keep_destdir)
end

describe '#dependency_check' do
describe '#install_build_depends' do
it 'defaults to false' do
expect(default_config.dependency_check).to eq(true)
expect(default_config.install_build_depends).to eq(false)
end

common_tests(:dependency_check)
common_tests(:install_build_depends)
end

describe '#install_depends' do
it 'defaults to false' do
expect(default_config.install_depends).to eq(false)
end

common_tests(:install_depends)
end

describe '#tmp_root' do
Expand Down Expand Up @@ -145,7 +153,8 @@ def self.common_tests(name)
:vendor => nil,
:skip_package => false,
:keep_destdir => false,
:dependency_check => true,
:install_build_depends => false,
:install_depends => false,
:quiet => false
})
end
Expand Down