Sha256: 85169d10700ffa15f90e9b50e6fef909dca8aa42c944d4aa5533b69ccccb6a38

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

require 'dply/helper'
require 'dply/setup'
require 'dply/config_downloader'
require 'dply/yum'
require 'dply/util'
require 'forwardable'
require 'digest'

module Dply
  class Build

    extend Forwardable
    include Helper

    def_delegators :config, :branch, :config_map, :dir_map, :meta_conf

    attr_reader :config

    def initialize(config)
      @config = config
    end

    def run
      setup
      meta_conf.generate if meta_conf
      Dir.chdir repo_dir do
        git_step
        git.clean
        link_all
        install_pkgs
        clean_build_dir
        link_build_dir
        bundle.install
        bundle.clean
        util.run config.task, render_config: false
        generate_checksum
      end
    end

    private

    def setup
      setup = Setup.new(@config)
      setup.build
    end

    def git_step
      return unless config.git
      if config.no_pull
        git.checkout branch
      else
        git.pull branch
      end
    end

    def link_all
      util.link "#{config.dir}/shared", dir_map
      util.link "#{config.dir}/config", config_map
    end

    def install_pkgs
      util.install_pkgs(build_mode: true)
    end

    def clean_build_dir
      logger.debug "clearing build dir"
      FileUtils.rm_rf build_dir if File.exists? build_dir
      FileUtils.mkdir build_dir
    end

    def link_build_dir
      build_artifacts = "tmp/build_artifacts"
      FileUtils.rm_rf build_artifacts if File.exists? build_artifacts
      symlink build_dir, build_artifacts
    end

    def repo_dir
      @repo_dir ||= "#{config.dir}/repo"
    end

    def build_dir
      @build_dir ||= "#{config.dir}/build"
    end

    def generate_checksum
      Dir["#{build_dir}/*"].each do |f|
        checksum = Digest::MD5.file f
        checksum_file = "#{f}.md5"
        File.open(checksum_file, 'w') { |cf| cf.write checksum }
      end
    end

    def util
      @util ||= Util.new
    end

    def bundle
      @bundle ||= Bundle.new
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dply-0.3.4 lib/dply/build.rb
dply-0.3.3 lib/dply/build.rb
dply-0.3.2 lib/dply/build.rb