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
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
- #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(cmd, env = {}) ⇒ Object
- #run_patch(file) ⇒ Object
- #state ⇒ 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
11 12 13 |
# File 'lib/pkgforge/components/deps.rb', line 11 def deps @deps ||= {} end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/pkgforge/components/upload.rb', line 5 def endpoint @endpoint 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
8 9 10 |
# File 'lib/pkgforge/components/deps.rb', line 8 def remove_linker_archives=(value) @remove_linker_archives = value end |
#remove_pkgconfig_files=(value) ⇒ Object (writeonly)
Sets the attribute remove_pkgconfig_files
8 9 10 |
# File 'lib/pkgforge/components/deps.rb', line 8 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 35 |
# File 'lib/pkgforge/components/metadata.rb', line 25 def add_license! return if licenses.empty? 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 22 |
# File 'lib/pkgforge/components/build.rb', line 15 def build! prepare_source! patch_source! prepare_deps! builder = PkgForge::DSL::Build.new(self) Dir.chdir(tmpdir(:build)) { builder.instance_eval(&build_block) } nil end |
#cleanup! ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/pkgforge/components/cleanup.rb', line 8 def cleanup! state[:tmpdirs] ||= {} state[:tmpfiles] ||= {} paths = state.values_at(:tmpdirs, :tmpfiles).map(&: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
14 15 16 17 |
# File 'lib/pkgforge/components/state.rb', line 14 def load_state!(statefile) @state = Cymbal.symbolize(JSON.parse(File.read(statefile))) nil end |
#package! ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pkgforge/components/package.rb', line 15 def package! add_license! type_method = "#{package[:type]}_prepare_package" method_found = respond_to?(type_method, true) raise("Unknown package type: #{package[:type]}") unless method_found send(type_method) expose_artifacts! end |
#push! ⇒ Object
8 9 10 |
# File 'lib/pkgforge/components/upload.rb', line 8 def push! upload_artifacts! end |
#releasedir ⇒ Object
14 15 16 |
# File 'lib/pkgforge/components/dirs.rb', line 14 def releasedir tmpdir(:release) end |
#remove_linker_archives? ⇒ Boolean
16 17 18 |
# File 'lib/pkgforge/components/deps.rb', line 16 def remove_linker_archives? @remove_linker_archives ||= false end |
#remove_pkgconfig_files? ⇒ Boolean
21 22 23 |
# File 'lib/pkgforge/components/deps.rb', line 21 def remove_pkgconfig_files? @remove_pkgconfig_files ||= false end |
#run(cmd, env = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/pkgforge/components/run.rb', line 6 def run(cmd, env = {}) puts "Running command in #{Dir.pwd}: #{cmd}" puts "Using env: #{env}" unless env.empty? res = system env, *cmd raise('Command failed!') unless res nil end |
#run_patch(file) ⇒ Object
13 14 15 |
# File 'lib/pkgforge/components/patch.rb', line 13 def run_patch(file) run "patch -d #{tmpdir(:build)} -p1 < patches/#{file}" end |
#state ⇒ Object
9 10 11 |
# File 'lib/pkgforge/components/state.rb', line 9 def state @state ||= {} end |
#test! ⇒ Object
15 16 17 18 19 |
# File 'lib/pkgforge/components/test.rb', line 15 def test! tester = PkgForge::DSL::Test.new(self) Dir.chdir(tmpdir(:release)) { tester.instance_eval(&test_block) } nil end |
#test_run(cmd, env = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/pkgforge/components/test.rb', line 22 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 run(cmd, env) end end |
#tmpdir(id) ⇒ Object
19 20 21 22 |
# File 'lib/pkgforge/components/dirs.rb', line 19 def tmpdir(id) state[:tmpdirs] ||= {} state[: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) state[:tmpfiles] ||= {} state[:tmpfiles][id] ||= Tempfile.create(id.to_s).path end |
#write_state!(statefile) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pkgforge/components/state.rb', line 20 def write_state!(statefile) File.open(statefile, 'w') do |fh| fh << state.to_json end nil end |