Class: ChkBuild::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/chkbuild/target.rb

Overview

Copyright © 2006,2007,2008,2009 Tanaka Akira <[email protected]>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Defined Under Namespace

Classes: Result

Constant Summary collapse

CHANGE_LINE_PAT =
/^(ADD|DEL|CHG) .*\t.*->.*\n|^COMMIT .*\n|^last commit:\n/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_name, *args, &block) ⇒ Target

Returns a new instance of Target.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chkbuild/target.rb', line 26

def initialize(target_name, *args, &block)
  @target_name = target_name
  @build_proc = block
  @opts = ChkBuild.get_options
  @opts.update args.pop if Hash === args.last
  init_target(*args)
  @title_hook = []
  init_default_title_hooks
  @failure_hook = []
  @diff_preprocess_hook = []
  init_default_diff_preprocess_hooks
  @diff_preprocess_sort_patterns = []
end

Instance Attribute Details

#build_procObject (readonly)

Returns the value of attribute build_proc.



39
40
41
# File 'lib/chkbuild/target.rb', line 39

def build_proc
  @build_proc
end

#optsObject (readonly)

Returns the value of attribute opts.



39
40
41
# File 'lib/chkbuild/target.rb', line 39

def opts
  @opts
end

#target_nameObject (readonly)

Returns the value of attribute target_name.



39
40
41
# File 'lib/chkbuild/target.rb', line 39

def target_name
  @target_name
end

Instance Method Details

#add_diff_preprocess_gsub(pat, &block) ⇒ Object



108
109
110
# File 'lib/chkbuild/target.rb', line 108

def add_diff_preprocess_gsub(pat, &block)
  @diff_preprocess_hook << lambda {|line| line.gsub(pat) { yield $~ } }
end

#add_diff_preprocess_hook(&block) ⇒ Object



111
# File 'lib/chkbuild/target.rb', line 111

def add_diff_preprocess_hook(&block) @diff_preprocess_hook << block end

#add_diff_preprocess_sort(pat) ⇒ Object



114
# File 'lib/chkbuild/target.rb', line 114

def add_diff_preprocess_sort(pat) @diff_preprocess_sort_patterns << pat end

#add_failure_hook(secname, &block) ⇒ Object



90
# File 'lib/chkbuild/target.rb', line 90

def add_failure_hook(secname, &block) @failure_hook << [secname, block] end

#add_title_hook(secname, &block) ⇒ Object



87
# File 'lib/chkbuild/target.rb', line 87

def add_title_hook(secname, &block) @title_hook << [secname, block] end

#diff_preprocess_sort_patternObject



115
116
117
118
119
120
121
# File 'lib/chkbuild/target.rb', line 115

def diff_preprocess_sort_pattern()
  if @diff_preprocess_sort_patterns.empty?
    nil
  else
    /\A#{Regexp.union(*@diff_preprocess_sort_patterns)}/
  end
end

#each_build_obj(&block) ⇒ Object



144
145
146
# File 'lib/chkbuild/target.rb', line 144

def each_build_obj(&block)
  make_build_objs.each(&block)
end

#each_diff_preprocess_hook(&block) ⇒ Object



112
# File 'lib/chkbuild/target.rb', line 112

def each_diff_preprocess_hook(&block) @diff_preprocess_hook.each(&block) end

#each_failure_hook(&block) ⇒ Object



91
# File 'lib/chkbuild/target.rb', line 91

def each_failure_hook(&block) @failure_hook.each(&block) end

#each_suffixesObject



123
124
125
126
127
# File 'lib/chkbuild/target.rb', line 123

def each_suffixes
  @branches.each {|suffixes|
    yield suffixes
  }
end

#each_title_hook(&block) ⇒ Object



88
# File 'lib/chkbuild/target.rb', line 88

def each_title_hook(&block) @title_hook.each(&block) end

#init_default_diff_preprocess_hooksObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/chkbuild/target.rb', line 95

def init_default_diff_preprocess_hooks
  add_diff_preprocess_gsub(/ # \d{4,}-\d\d-\d\dT\d\d:\d\d:\d\d[-+]\d\d:\d\d$/) {|match|
    ' # <time>'
  }
  add_diff_preprocess_gsub(CHANGE_LINE_PAT) {|match| '' }
  add_diff_preprocess_gsub(/timeout: the process group \d+ is alive/) {|match|
    "timeout: the process group <pgid> is alive"
  }
  add_diff_preprocess_gsub(/some descendant process in process group \d+ remain/) {|match|
    "some descendant process in process group <pgid> remain"
  }
end

#init_default_title_hooksObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/chkbuild/target.rb', line 61

def init_default_title_hooks
  add_title_hook('success') {|title, log|
    title.update_title(:status) {|val| 'success' if !val }
  }
  add_title_hook('failure') {|title, log|
    title.update_title(:status) {|val|
      if !val
        line = /\n/ =~ log ? $` : log
        line = line.strip
        line if !line.empty?
      end
    }
  }
  add_title_hook(nil) {|title, log|
    num_warns = log.scan(/warn/i).length
    title.update_title(:warn) {|val| "#{num_warns}W" } if 0 < num_warns
  }
  add_title_hook('dependencies') {|title, log|
    dep_versions = []
    title.logfile.dependencies.each {|suffixed_name, time, ver|
      dep_versions << "(#{ver})"
    }
    title.update_title(:dep_versions, dep_versions)
  }
end

#init_target(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chkbuild/target.rb', line 41

def init_target(*args)
  @dep_targets = []
  suffixes_ary = []
  args.each {|arg|
    if ChkBuild::Target === arg
      @dep_targets << arg
    else
      suffixes_ary << arg
    end
  }
  @branches = []
  Util.rproduct(*suffixes_ary) {|suffixes|
    if @opts[:limit_combination]
      next if !@opts[:limit_combination].call(*suffixes)
    end
    suffixes.compact!
    @branches << suffixes
  }
end

#make_build_objsObject



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/chkbuild/target.rb', line 133

def make_build_objs
  return @builds if defined? @builds
  builds = []
  each_suffixes {|suffixes|
    dep_builds = @dep_targets.map {|dep_target| dep_target.make_build_objs }
    Util.rproduct(*dep_builds) {|dependencies|
      builds << ChkBuild::Build.new(self, suffixes, dependencies)
    }
  }
  @builds = builds
end

#make_resultObject



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/chkbuild/target.rb', line 148

def make_result
  return @result if defined? @result
  succeed = Result.new
  each_build_obj {|build|
    if build.depbuilds.all? {|depbuild| depbuild.success? }
      succeed.add(build) if build.build
    end
  }
  @result = succeed
  succeed
end

#resultObject



160
161
162
163
# File 'lib/chkbuild/target.rb', line 160

def result
  return @result if defined? @result
  raise "#{@target_name}: no result yet"
end

#update_option(hash) ⇒ Object



129
130
131
# File 'lib/chkbuild/target.rb', line 129

def update_option(hash)
  @opts.update(hash)
end