Class: Dev::Cmd::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/dev/cmd/Build.rb

Class Method Summary collapse

Class Method Details

.build(branch) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dev/cmd/Build.rb', line 5

def self.build(branch)
  db=Dev::Database.new

  puts " "
  puts "building branch " + branch.foreground(:green)
  h=Dev::Cmd::Build.get_branch_hash(branch)
  Hash.print_hash("",h)

  # does a result already exist?

  results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}", :user=>"#{h[:user]}", :machine=>"#{h[:machine]}"})

  result=results[0] if !results.empty?
  if(results.empty?)
 result=h

 # export to local directory

 FileUtils.mkdir("#{Dev::Environment.dev_root}/exp") if !File.exists?("#{Dev::Environment.dev_root}/exp")
 FileUtils.rm_r(h[:dir]) if File.exists? h[:dir]

 puts "svn exporting #{h[:uri]}@#{h[:revision]} to #{h[:dir]}"
 Dev::Scm::export("#{h[:uri]}@#{h[:revision]}","#{h[:dir]}",'svn')
 # Dev::Commands.execute_cmd("svn export #{h[:uri]}@#{h[:revision]} #{h[:dir]}")


 # rake in local directory

 call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true})
 call.puts_summary

 ch=call.get_hash
 [:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each{ |k| h[k]=ch[k]; }

 # store results to database

  
 db.add_result(result)
 db=nil
  end


  puts "results hash:"
  puts " "
  Hash.print_hash("",result)

  Dev::SystemCall.puts_hash_summary(result)

  return 0
end

.get_branch_hash(branch) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dev/cmd/Build.rb', line 96

def self.get_branch_hash(branch)
  db=Dev::Database.new
  h=Hash.new
  h[:uri]=db.get_branch_uri(branch)
  db=nil
  h[:revision]=Dev::Svn.last_changed_revision(h[:uri])
  h[:dir]="#{Dev::Environment.dev_root}/exp/#{branch}@#{h[:revision]}"
  h[:user]="#{Dev::Environment.user}"
  h[:machine]="#{Dev::Environment.machine}"
  h[:ruby_version]=RUBY_VERSION
  h[:ruby_platform]=RUBY_PLATFORM
  return h
end

.status(branch) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dev/cmd/Build.rb', line 51

def self.status(branch)
  db=Dev::Database.new
  h=Dev::Cmd::Build.get_branch_hash(branch)
  puts "status of branch " + branch.foreground(:green) + "@#{h[:revision]}"

  # do any results exist for latest revision?

  results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}"})
  #resultss=db.get_results({:branch=>h[:branch]})

  #results=db.get_results({:uri=>"#{h[:uri]}"})

  db=nil

  puts "  no results" if results.empty?

  fail="  [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan)
  pass="  [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan)
  results.each{ |r|
 status=pass
 status=fail if r[:status] != 0 && r[:status] != "0"
 elapsed="[" + "%.0f" %(r[:elapsed]) + "s]".foreground(:cyan)
 context="#{r[:user]}@#{r[:machine]}".foreground(:green)
 puts "#{status} #{context} #{elapsed} #{r[:end_time]}"
  }
end

.work(branch) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dev/cmd/Build.rb', line 75

def self.work(branch)
  #db=Dev::Database.new


  puts " "
  puts "working on branch " + branch.foreground(:green)
  h=Dev::Cmd::Build.get_branch_hash(branch)
  h[:dir]="#{Dev::Environment.dev_root}/wrk/#{branch}"
  #Hash.print_hash("",h)


  # export to local directory

  FileUtils.mkdir("#{Dev::Enviroment.dev_root}/wrk") if !File.exists?("#{Dev::Environment.dev_root}/wrk")
  Dev::Commands.execute_cmd("svn co #{h[:uri]} #{h[:dir]}") if !File.exists? h[:dir]

  # rake in local directory

  call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true})
  puts "------------------------------------------------------------".foreground(:green)
  call.puts_summary
  puts "------------------------------------------------------------".foreground(:green)

end