Class: Metabuild::Target
- Inherits:
-
Object
- Object
- Metabuild::Target
- Defined in:
- lib/metabuild.rb
Overview
A Target is really at the heart of a build. It handles dependencies, caching …
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#depends ⇒ Object
Returns the value of attribute depends.
-
#done ⇒ Object
Returns the value of attribute done.
-
#name ⇒ Object
Returns the value of attribute name.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#results ⇒ Object
Returns the value of attribute results.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #add_dep(dep) ⇒ Object
- #add_result(res) ⇒ Object
- #check_cache ⇒ Object
-
#cksum ⇒ Object
The checksum is a mix of the repository checksum + the default tags + local tags Default tags include processor type, kernel name, etc.
- #each_dep ⇒ Object
- #each_result ⇒ Object
- #get_cache ⇒ Object
-
#initialize(name, repo, depends = [], results = [], tags = []) ⇒ Target
constructor
A new instance of Target.
- #output_graph ⇒ Object
- #propagate_disable ⇒ Object
- #propagate_restart_at(restart_at) ⇒ Object
-
#propagate_run(use_cache = false, parallel = false) ⇒ Object
Run according to dependency list, from bottom to top.
- #remove_dep(dep) ⇒ Object
-
#run(use_cache = false) ⇒ Object
Run a block that defines all the steps of the build.
- #to_s ⇒ Object
- #update_cache ⇒ Object
Constructor Details
#initialize(name, repo, depends = [], results = [], tags = []) ⇒ Target
Returns a new instance of Target.
726 727 728 729 730 |
# File 'lib/metabuild.rb', line 726 def initialize(name, repo, depends = [], results = [], = []) @name, @repo, @tags, @results, @depends = name, repo, , results, depends @done = false @block = lambda { raise "Target #{@name} has empty code block !" } end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def block @block end |
#depends ⇒ Object
Returns the value of attribute depends.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def depends @depends end |
#done ⇒ Object
Returns the value of attribute done.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def done @done end |
#name ⇒ Object
Returns the value of attribute name.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def name @name end |
#repo ⇒ Object
Returns the value of attribute repo.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def repo @repo end |
#results ⇒ Object
Returns the value of attribute results.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def results @results end |
#tags ⇒ Object
Returns the value of attribute tags.
724 725 726 |
# File 'lib/metabuild.rb', line 724 def @tags end |
Instance Method Details
#add_dep(dep) ⇒ Object
740 741 742 743 744 745 746 |
# File 'lib/metabuild.rb', line 740 def add_dep dep if dep.kind_of? Array @depends = @depends | dep else @depends.push dep end end |
#add_result(res) ⇒ Object
736 737 738 |
# File 'lib/metabuild.rb', line 736 def add_result res @results.push res end |
#check_cache ⇒ Object
772 773 774 |
# File 'lib/metabuild.rb', line 772 def check_cache File.exist?(CACHE + cksum + ".tgz") end |
#cksum ⇒ Object
The checksum is a mix of the repository checksum + the default tags + local tags Default tags include processor type, kernel name, etc.
766 767 768 769 770 |
# File 'lib/metabuild.rb', line 766 def cksum DEFAULT_TAGS.concat(@tags).inject(@repo.cksum) { |sum, tag| Digest::SHA1.hexdigest(tag.call).to_i(16) ^ sum }.to_s(16) end |
#each_dep ⇒ Object
752 753 754 755 756 |
# File 'lib/metabuild.rb', line 752 def each_dep @depends.each do |d| yield d end end |
#each_result ⇒ Object
758 759 760 761 762 |
# File 'lib/metabuild.rb', line 758 def each_result @results.each do |r| yield r end end |
#get_cache ⇒ Object
776 777 778 779 |
# File 'lib/metabuild.rb', line 776 def get_cache cmd = "tar zxf " + CACHE + "/" + cksum + ".tgz" raise "Error getting target #{@name} in cache" unless system(cmd) end |
#output_graph ⇒ Object
846 847 848 849 850 |
# File 'lib/metabuild.rb', line 846 def output_graph each_dep do |d| puts "#{@name} -> #{d.name};" end end |
#propagate_disable ⇒ Object
831 832 833 834 835 836 |
# File 'lib/metabuild.rb', line 831 def propagate_disable each_dep do |d| d.done = true d.propagate_disable end end |
#propagate_restart_at(restart_at) ⇒ Object
838 839 840 841 842 843 844 |
# File 'lib/metabuild.rb', line 838 def propagate_restart_at(restart_at) each_dep do |d| return true if d.propagate_restart_at restart_at d.done = true end return @name == restart_at end |
#propagate_run(use_cache = false, parallel = false) ⇒ Object
Run according to dependency list, from bottom to top
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/metabuild.rb', line 809 def propagate_run(use_cache=false, parallel=false) success = true if parallel each_dep do |d| fork { ENV["METABUILD_PARALLEL"] = "1" d.propagate_run(use_cache, parallel) } end Process.waitall.each { |a| success = false unless a[1].success? } unless @depends.empty? else each_dep do |d| d.propagate_run(use_cache, parallel) end end if success run(use_cache) else raise "Dependency failed for #{name}" end end |
#remove_dep(dep) ⇒ Object
748 749 750 |
# File 'lib/metabuild.rb', line 748 def remove_dep dep @depends.delete dep end |
#run(use_cache = false) ⇒ Object
Run a block that defines all the steps of the build. Use caching if asked to. Note : Whatever the directory changes happening in the block,
when the block exits, we are in the same directory as when it started
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
# File 'lib/metabuild.rb', line 790 def run(use_cache = false) return if @done old_dir = pwd if use_cache if check_cache puts "getting from cache" get_cache else block.call self update_cache end else block.call self end cd old_dir @done = true end |
#to_s ⇒ Object
732 733 734 |
# File 'lib/metabuild.rb', line 732 def to_s @name end |
#update_cache ⇒ Object
781 782 783 784 |
# File 'lib/metabuild.rb', line 781 def update_cache cmd = ":;" + @results.inject("tar zcf " + CACHE + "/" + cksum + ".tgz "){|s, r| s += "#{r} "} raise "Error tar for target #{@name}" unless system(cmd) end |