<commit_before>#require 'digest/md5'
#require 'fpm/cookery/recipe_inspector'
require 'fpm/cookery/dependency_inspector'
require 'fpm/cookery/utils'
require 'fpm/cookery/source_integrity_check'
require 'fpm/cookery/path'
require 'fpm/cookery/log'
require 'fpm/cookery/package/dir'
require 'fpm/package/deb'
require 'fpm/package/rpm'

module FPM
  module Cookery
    class Packager
      include FPM::Cookery::Utils

      attr_reader :recipe, :config

      def initialize(recipe, config = {})
        @recipe = recipe
        @config = config
      end

      def target=(target)
        # TODO(sissel): do sanity checking
        @target = target
      end

      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

      def install_deps
        DependencyInspector.verify!(recipe.depends, recipe.build_depends) 
        Log.info("All dependencies installed!")
      end

      def omnibus
        # Omnibus packages are many builds in one package; e.g. Ruby + Puppet together.
        Log.info "Recipe #{recipe.name} is an Omnibus package; looking for child recipes to build"

        # Store original recipe
        @original_recipe = recipe

        # Collect all the 'depends' from child packages to be added to the final package
        combined_depends = Array.new

        recipe.omnibus_recipes.each do |omnibus_recipe_name|
          # Look for recipes in the same dir as the recipe we loaded
          omnibus_recipe_file = File.expand_path(File.dirname(recipe.filename) + "/#{omnibus_recipe_name}.rb")
          if File.exists?(omnibus_recipe_file)
            FPM::Cookery::Recipe.send(:include, FPM::Cookery::BookHook)
            FPM::Cookery::Book.load_recipe(omnibus_recipe_file) do |omnibus_recipe|
              @skip_package = true    # Don't package till we've built everything
              Log.info "Located recipe at #{omnibus_recipe_file} for child recipe #{omnibus_recipe_name}; starting build"
              @recipe = omnibus_recipe
              self.dispense()
              Log.info "Finished building #{omnibus_recipe_name}, moving on to next recipe"
              combined_depends += omnibus_recipe.depends
            end
          else
            Log.fatal "Cannot find a recipe for #{omnibus_recipe_name} at #{omnibus_recipe_file}"
            exit 1
          end
        end

        # Now all child recipes are built; set depends to combined set of dependencies
        recipe = @original_recipe
        recipe.class.depends(combined_depends.flatten.uniq)
        Log.info "Combined dependencies: #{recipe.depends.join(', ')}"
        recipe.destdir = recipe.omnibus_dir
        build_package(recipe, config)

      end

      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})"<commit_msg>Don't reset builddir if omnibus_dir isn't set<commit_after>#require 'digest/md5'
#require 'fpm/cookery/recipe_inspector'
require 'fpm/cookery/dependency_inspector'
require 'fpm/cookery/utils'
require 'fpm/cookery/source_integrity_check'
require 'fpm/cookery/path'
require 'fpm/cookery/log'
require 'fpm/cookery/package/dir'
require 'fpm/package/deb'
require 'fpm/package/rpm'

module FPM
  module Cookery
    class Packager
      include FPM::Cookery::Utils

      attr_reader :recipe, :config

      def initialize(recipe, config = {})
        @recipe = recipe
        @config = config
      end

      def target=(target)
        # TODO(sissel): do sanity checking
        @target = target
      end

      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

      def install_deps
        DependencyInspector.verify!(recipe.depends, recipe.build_depends) 
        Log.info("All dependencies installed!")
      end

      def omnibus
        # Omnibus packages are many builds in one package; e.g. Ruby + Puppet together.
        Log.info "Recipe #{recipe.name} is an Omnibus package; looking for child recipes to build"

        # Store original recipe
        @original_recipe = recipe

        # Collect all the 'depends' from child packages to be added to the final package
        combined_depends = Array.new

        recipe.omnibus_recipes.each do |omnibus_recipe_name|
          # Look for recipes in the same dir as the recipe we loaded
          omnibus_recipe_file = File.expand_path(File.dirname(recipe.filename) + "/#{omnibus_recipe_name}.rb")
          if File.exists?(omnibus_recipe_file)
            FPM::Cookery::Recipe.send(:include, FPM::Cookery::BookHook)
            FPM::Cookery::Book.load_recipe(omnibus_recipe_file) do |omnibus_recipe|
              @skip_package = true    # Don't package till we've built everything
              Log.info "Located recipe at #{omnibus_recipe_file} for child recipe #{omnibus_recipe_name}; starting build"
              @recipe = omnibus_recipe
              self.dispense()
              Log.info "Finished building #{omnibus_recipe_name}, moving on to next recipe"
              combined_depends += omnibus_recipe.depends
            end
          else
            Log.fatal "Cannot find a recipe for #{omnibus_recipe_name} at #{omnibus_recipe_file}"
            exit 1
          end
        end

        # Now all child recipes are built; set depends to combined set of dependencies
        recipe = @original_recipe
        recipe.class.depends(combined_depends.flatten.uniq)
        Log.info "Combined dependencies: #{recipe.depends.join(', ')}"
        unless recipe.omnibus_dir == nil
          recipe.destdir = recipe.omnibus_dir
        end
        build_package(recipe, config)

      end

      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})"
{'fraction_non_alphanumeric': 0.0892605909019853, 'fraction_numerical': 0.0006252931061435048, 'mean_word_length': 2.592363840539023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630251', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1913, 'n_words': 497}