Sha256: 51be0b9e33351c2d4861cb9a3c5113321c2326d45c4b0354e92fbae6a9bcd4ff

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 KB

Contents

require 'fileutils'

module PkgForge
  ##
  # Add build methods to Forge
  class Forge
    attr_writer :build_block

    Contract None => Proc
    def build_block
      @build_block ||= proc { raise 'No build block provided' }
    end

    Contract None => nil
    def build!
      prepare_source!
      patch_source!
      prepare_deps!
      builder = PkgForge::DSL::Build.new(self)
      builder.instance_eval(&build_block)
    end
  end

  module DSL
    ##
    # Add build method to Forge DSL
    class Forge
      Contract Func[None => nil] => nil
      def build(&block)
        @forge.build_block = block
        nil
      end
    end

    ##
    # Add build methods to Build DSL
    class Build
      Contract Or[String, Array], Or[HashOf[String => String], {}, nil] => nil
      def run(*args)
        @forge.run(*args)
      end

      Contract None => nil
      def configure
        env = {
          'CC' => 'musl-gcc',
          'CFLAGS' => @forge.cflags.join(' '),
          'LIBS' => @forge.libs.join(' ')
        }
        run ['./configure'] + configure_flag_strings, env
      end

      Contract None => nil
      def make
        run 'make'
      end

      Contract None => nil
      def install
        run "make DESTDIR=#{@forge.releasedir} install"
      end

      Contract Or[String, ArrayOf[String]] => nil
      def rm(paths)
        paths = [paths] if paths.is_a? String
        paths.map { |x| File.join(@forge.releasedir, x) }
        FileUtils.rm_r paths
        nil
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pkgforge-0.5.2 lib/pkgforge/components/build.rb
pkgforge-0.5.1 lib/pkgforge/components/build.rb
pkgforge-0.5.0 lib/pkgforge/components/build.rb
pkgforge-0.4.16 lib/pkgforge/components/build.rb
pkgforge-0.4.15 lib/pkgforge/components/build.rb
pkgforge-0.4.14 lib/pkgforge/components/build.rb
pkgforge-0.4.13 lib/pkgforge/components/build.rb
pkgforge-0.4.12 lib/pkgforge/components/build.rb
pkgforge-0.4.11 lib/pkgforge/components/build.rb
pkgforge-0.4.10 lib/pkgforge/components/build.rb
pkgforge-0.4.9 lib/pkgforge/components/build.rb
pkgforge-0.4.8 lib/pkgforge/components/build.rb
pkgforge-0.4.7 lib/pkgforge/components/build.rb
pkgforge-0.4.6 lib/pkgforge/components/build.rb
pkgforge-0.4.5 lib/pkgforge/components/build.rb
pkgforge-0.4.4 lib/pkgforge/components/build.rb
pkgforge-0.4.3 lib/pkgforge/components/build.rb
pkgforge-0.4.2 lib/pkgforge/components/build.rb
pkgforge-0.4.1 lib/pkgforge/components/build.rb
pkgforge-0.4.0 lib/pkgforge/components/build.rb