Class: PkgForge::Forge

Inherits:
Object
  • Object
show all
Includes:
Contracts::Builtin, Contracts::Core
Defined in:
lib/pkgforge/base.rb,
lib/pkgforge/components/run.rb,
lib/pkgforge/components/deps.rb,
lib/pkgforge/components/dirs.rb,
lib/pkgforge/components/test.rb,
lib/pkgforge/components/build.rb,
lib/pkgforge/components/patch.rb,
lib/pkgforge/components/cflags.rb,
lib/pkgforge/components/source.rb,
lib/pkgforge/components/upload.rb,
lib/pkgforge/components/package.rb,
lib/pkgforge/components/metadata.rb,
lib/pkgforge/components/configure.rb

Overview

Add configure flag options to Forge

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Forge

Returns a new instance of Forge.



11
12
13
14
# File 'lib/pkgforge/base.rb', line 11

def initialize(params = {})
  @options = params
  nil
end

Instance Attribute Details

#build_blockObject



10
11
12
# File 'lib/pkgforge/components/build.rb', line 10

def build_block
  @build_block ||= proc { raise 'No build block provided' }
end

#cflagsObject



8
9
10
# File 'lib/pkgforge/components/cflags.rb', line 8

def cflags
  @cflags ||= []
end

#configure_flagsObject



8
9
10
# File 'lib/pkgforge/components/configure.rb', line 8

def configure_flags
  @configure_flags ||= {}
end

#depsObject



10
11
12
# File 'lib/pkgforge/components/deps.rb', line 10

def deps
  @deps ||= {}
end

#libsObject



13
14
15
# File 'lib/pkgforge/components/cflags.rb', line 13

def libs
  @libs ||= []
end

#licensesObject



20
21
22
# File 'lib/pkgforge/components/metadata.rb', line 20

def licenses
  @licenses ||= ['LICENSE']
end

#nameObject



10
11
12
# File 'lib/pkgforge/components/metadata.rb', line 10

def name
  @name || raise('No name provided')
end

#orgObject



15
16
17
# File 'lib/pkgforge/components/metadata.rb', line 15

def org
  @org || raise('No org provided')
end

#patchesObject



8
9
10
# File 'lib/pkgforge/components/patch.rb', line 8

def patches
  @patches ||= []
end

#remove_linker_archives=(value) ⇒ Object (writeonly)

Sets the attribute remove_linker_archives

Parameters:

  • value

    the value to set the attribute remove_linker_archives to.



7
8
9
# File 'lib/pkgforge/components/deps.rb', line 7

def remove_linker_archives=(value)
  @remove_linker_archives = value
end

#sourceObject



11
12
13
# File 'lib/pkgforge/components/source.rb', line 11

def source
  @source ||= { type: 'git' }
end

#test_blockObject



10
11
12
# File 'lib/pkgforge/components/test.rb', line 10

def test_block
  @test_block ||= proc { raise 'No test block provided' }
end

Instance Method Details

#add_license!Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/pkgforge/components/metadata.rb', line 25

def add_license!
  dest_dir = File.join(tmpdir(:release), 'usr', 'share', 'licenses', name)
  FileUtils.mkdir_p dest_dir
  licenses.each do |license|
    src_file = File.join(tmpdir(:build), license)
    dest_file = File.join(dest_dir, license)
    FileUtils.cp src_file, dest_file
  end
  nil
end

#build!Object



15
16
17
18
19
20
21
# File 'lib/pkgforge/components/build.rb', line 15

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

#dep(package) ⇒ Object



9
10
11
# File 'lib/pkgforge/components/dirs.rb', line 9

def dep(package)
  tmpdir(package.to_sym)
end

#package!Object



8
9
10
11
12
# File 'lib/pkgforge/components/package.rb', line 8

def package!
  add_license!
  make_tarball!
  copy_tarball!
end

#push!Object



6
7
8
# File 'lib/pkgforge/components/upload.rb', line 6

def push!
  upload_artifact!
end

#releasedirObject



14
15
16
# File 'lib/pkgforge/components/dirs.rb', line 14

def releasedir
  tmpdir(:release)
end

#remove_linker_archives?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/pkgforge/components/deps.rb', line 15

def remove_linker_archives?
  @remove_linker_archives ||= false
end

#run(cmd, env = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/pkgforge/components/run.rb', line 6

def run(cmd, env = {})
  Dir.chdir(tmpdir(:build)) do
    run_local(cmd, env)
  end
  nil
end

#test!Object



15
16
17
18
# File 'lib/pkgforge/components/test.rb', line 15

def test!
  tester = PkgForge::DSL::Test.new(self)
  tester.instance_eval(&test_block)
end

#test_run(cmd, env = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/pkgforge/components/test.rb', line 21

def test_run(cmd, env = {})
  cmd.unshift('/usr/bin/env') if cmd.is_a? Array
  cmd.prepend('/usr/bin/env ') if cmd.is_a? String
  env['PATH'] ||= './usr/bin'
  lib_override do
    Dir.chdir(tmpdir(:release)) do
      run_local(cmd, env)
    end
  end
end

#tmpdir(id) ⇒ Object



19
20
21
22
# File 'lib/pkgforge/components/dirs.rb', line 19

def tmpdir(id)
  @tmpdirs ||= {}
  @tmpdirs[id] ||= Dir.mktmpdir(id.to_s)
end

#tmpfile(id) ⇒ Object



25
26
27
28
# File 'lib/pkgforge/components/dirs.rb', line 25

def tmpfile(id)
  @tmpfiles ||= {}
  @tmpfiles[id] ||= Tempfile.create(id.to_s).path
end