Class: PkgForge::Forge
- Inherits:
-
Object
- Object
- PkgForge::Forge
- 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/state.rb,
lib/pkgforge/components/cflags.rb,
lib/pkgforge/components/source.rb,
lib/pkgforge/components/upload.rb,
lib/pkgforge/components/cleanup.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
- #build_block ⇒ Object
- #cflags ⇒ Object
- #configure_flags ⇒ Object
- #deps ⇒ Object
- #libs ⇒ Object
- #licenses ⇒ Object
- #name ⇒ Object
- #org ⇒ Object
- #package ⇒ Object
- #patches ⇒ Object
-
#remove_linker_archives ⇒ Object
writeonly
Sets the attribute remove_linker_archives.
-
#remove_pkgconfig_files ⇒ Object
writeonly
Sets the attribute remove_pkgconfig_files.
- #source ⇒ Object
- #test_block ⇒ Object
Instance Method Summary collapse
- #add_license! ⇒ Object
- #build! ⇒ Object
- #cleanup! ⇒ Object
- #dep(package) ⇒ Object
-
#initialize(params = {}) ⇒ Forge
constructor
A new instance of Forge.
- #load_state!(statefile) ⇒ Object
- #package! ⇒ Object
- #push! ⇒ Object
- #releasedir ⇒ Object
- #remove_linker_archives? ⇒ Boolean
- #remove_pkgconfig_files? ⇒ Boolean
- #run(*args) ⇒ Object
- #run_patch(file) ⇒ Object
- #test! ⇒ Object
- #test_run(cmd, env = {}) ⇒ Object
- #tmpdir(id) ⇒ Object
- #tmpfile(id) ⇒ Object
- #write_state!(statefile) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Forge
11 12 13 14 |
# File 'lib/pkgforge/base.rb', line 11 def initialize(params = {}) = params nil end |
Instance Attribute Details
#build_block ⇒ Object
10 11 12 |
# File 'lib/pkgforge/components/build.rb', line 10 def build_block @build_block ||= proc { raise 'No build block provided' } end |
#cflags ⇒ Object
8 9 10 |
# File 'lib/pkgforge/components/cflags.rb', line 8 def cflags @cflags ||= [] end |
#configure_flags ⇒ Object
8 9 10 |
# File 'lib/pkgforge/components/configure.rb', line 8 def configure_flags @configure_flags ||= {} end |
#deps ⇒ Object
10 11 12 |
# File 'lib/pkgforge/components/deps.rb', line 10 def deps @deps ||= {} end |
#libs ⇒ Object
13 14 15 |
# File 'lib/pkgforge/components/cflags.rb', line 13 def libs @libs ||= [] end |
#licenses ⇒ Object
20 21 22 |
# File 'lib/pkgforge/components/metadata.rb', line 20 def licenses @licenses ||= ['LICENSE'] end |
#name ⇒ Object
10 11 12 |
# File 'lib/pkgforge/components/metadata.rb', line 10 def name @name || raise('No name provided') end |
#org ⇒ Object
15 16 17 |
# File 'lib/pkgforge/components/metadata.rb', line 15 def org @org || raise('No org provided') end |
#package ⇒ Object
10 11 12 |
# File 'lib/pkgforge/components/package.rb', line 10 def package @package ||= { type: 'tarball' } end |
#patches ⇒ Object
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
7 8 9 |
# File 'lib/pkgforge/components/deps.rb', line 7 def remove_linker_archives=(value) @remove_linker_archives = value end |
#remove_pkgconfig_files=(value) ⇒ Object (writeonly)
Sets the attribute remove_pkgconfig_files
7 8 9 |
# File 'lib/pkgforge/components/deps.rb', line 7 def remove_pkgconfig_files=(value) @remove_pkgconfig_files = value end |
#source ⇒ Object
11 12 13 |
# File 'lib/pkgforge/components/source.rb', line 11 def source @source ||= { type: 'git', path: 'upstream' } end |
#test_block ⇒ Object
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 |
#cleanup! ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/pkgforge/components/cleanup.rb', line 8 def cleanup! @tmpdirs ||= {} @tmpfiles ||= {} paths = [@tmpfiles.values, @tmpdirs.values].flatten puts "Cleaning up tmp paths: #{paths}" FileUtils.rm_rf paths nil end |
#dep(package) ⇒ Object
9 10 11 |
# File 'lib/pkgforge/components/dirs.rb', line 9 def dep(package) tmpdir(package.to_sym) end |
#load_state!(statefile) ⇒ Object
8 9 10 11 12 |
# File 'lib/pkgforge/components/state.rb', line 8 def load_state!(statefile) state = JSON.parse(File.read(statefile)) @tmpfiles = state[:tmpfiles] @tmpdirs = state[:tmpdirs] end |
#package! ⇒ Object
15 16 17 18 19 20 |
# File 'lib/pkgforge/components/package.rb', line 15 def package! add_license! type_method = "#{package[:type]}_prepare_package" return send(type_method) if respond_to?(type_method, true) raise("Unknown package type: #{package[:type]}") end |
#push! ⇒ Object
6 7 8 |
# File 'lib/pkgforge/components/upload.rb', line 6 def push! upload_artifact! end |
#releasedir ⇒ Object
14 15 16 |
# File 'lib/pkgforge/components/dirs.rb', line 14 def releasedir tmpdir(:release) end |
#remove_linker_archives? ⇒ Boolean
15 16 17 |
# File 'lib/pkgforge/components/deps.rb', line 15 def remove_linker_archives? @remove_linker_archives ||= false end |
#remove_pkgconfig_files? ⇒ Boolean
20 21 22 |
# File 'lib/pkgforge/components/deps.rb', line 20 def remove_pkgconfig_files? @remove_pkgconfig_files ||= false end |
#run(*args) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/pkgforge/components/run.rb', line 6 def run(*args) Dir.chdir(tmpdir(:build)) do run_local(*args) end nil end |
#run_patch(file) ⇒ Object
13 14 15 |
# File 'lib/pkgforge/components/patch.rb', line 13 def run_patch(file) run_local "patch -d #{tmpdir(:build)} -p1 < patches/#{file}" 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 |
#write_state!(statefile) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/pkgforge/components/state.rb', line 15 def write_state!(statefile) File.open(statefile, 'w') do |fh| fh << { tmpfiles: @tmpfiles, tmpdirs: @tmpdirs }.to_json end nil end |