dev 1.0.147 → 1.0.148
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/devgem +44 -4
- data/lib/dev/Commands.rb +1 -1
- data/lib/dev/Database.rb +59 -4
- data/lib/dev/SystemCall.rb +21 -2
- data/lib/dev/Tasks.rb +12 -6
- data/lib/dev/cmd/Build.rb +105 -0
- data/lib/dev/cmd/Compile.rb +1 -1
- metadata +3 -2
data/bin/devgem
CHANGED
@@ -22,10 +22,50 @@ rescue LoadError
|
|
22
22
|
end
|
23
23
|
|
24
24
|
require 'dev'
|
25
|
+
DB=Dev::Database.new
|
25
26
|
|
26
|
-
|
27
|
+
def get_pattern(args,index)
|
28
|
+
pattern=nil
|
29
|
+
pattern=args[index] if args.count > index
|
30
|
+
pattern="%#{pattern}%" if !pattern.nil? && !pattern.include?('%') && !pattern.include?("'") && !pattern.include?('"')
|
31
|
+
return pattern
|
32
|
+
end
|
33
|
+
|
34
|
+
def usage(args)
|
35
|
+
puts "welcome to devgem"
|
36
|
+
end
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
puts "
|
38
|
+
def list(args)
|
39
|
+
pattern=get_pattern(args,1)
|
40
|
+
puts "listing all branches" if pattern.nil?
|
41
|
+
puts "listing branches LIKE #{pattern}" if !pattern.nil?
|
42
|
+
branches=DB.find_branches(pattern)
|
43
|
+
branches.each{ |b| puts " #{b}" }
|
31
44
|
end
|
45
|
+
|
46
|
+
def status(args)
|
47
|
+
pattern=get_pattern(args,1)
|
48
|
+
branches=DB.find_branches(pattern)
|
49
|
+
branches.each{ |b| Dev::Cmd::Build.status(b) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def build(args)
|
53
|
+
pattern=get_pattern(args,1)
|
54
|
+
puts "building all branches" if pattern.nil?
|
55
|
+
puts "building branches LIKE #{pattern}" if !pattern.nil?
|
56
|
+
branches=DB.find_branches(pattern)
|
57
|
+
branches.each{ |b| Dev::Cmd::Build.build(b) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def work(args)
|
61
|
+
pattern=get_pattern(args,1)
|
62
|
+
branches=DB.find_branches(pattern)
|
63
|
+
branches.each{ |b| Dev::Cmd::Build.work(b) }
|
64
|
+
end
|
65
|
+
|
66
|
+
list(ARGV) if(ARGV.count > 0 && ARGV[0]=="list")
|
67
|
+
status(ARGV) if(ARGV.count > 0 && ARGV[0]=="status")
|
68
|
+
build(ARGV) if(ARGV.count > 0 && ARGV[0]=="build")
|
69
|
+
work(ARGV) if(ARGV.count > 0 && ARGV[0]=="work")
|
70
|
+
usage(ARGV) if(ARGV.count==0 || ARGV[0]=="help")
|
71
|
+
|
data/lib/dev/Commands.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
["Compile","Replace","Setup","Test","Commit","Info","Update","Pull"].each{ |f| require_relative("cmd/#{f}.rb") }
|
1
|
+
["Compile","Replace","Setup","Test","Commit","Info","Update","Pull","Build"].each{ |f| require_relative("cmd/#{f}.rb") }
|
2
2
|
|
3
3
|
module Dev
|
4
4
|
class Commands < Hash
|
data/lib/dev/Database.rb
CHANGED
@@ -29,17 +29,72 @@ class Database
|
|
29
29
|
table_names=Dev::Database.get_table_names(filename)
|
30
30
|
@db = SQLite3::Database.new filename
|
31
31
|
@db.execute("create table Branches(Name text,Uri text,UNIQUE(Name));") if !table_names.include? "Branches"
|
32
|
+
|
33
|
+
columns=""
|
34
|
+
[:uri,:revision,:dir,:user,:machine,:ruby_version,:ruby_platform,:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each { |s|
|
35
|
+
columns="#{columns}," if columns.length > 0
|
36
|
+
columns="#{columns}#{s.to_s} text"
|
37
|
+
}
|
38
|
+
@db.execute("create table Results(#{columns});") if ! table_names.include? "Results"
|
32
39
|
end
|
33
40
|
|
34
41
|
def set_branch_uri(name,uri)
|
35
42
|
@db.execute("insert or replace into Branches (Name,Uri) VALUES ('#{name}','#{uri}');")
|
36
43
|
end
|
37
44
|
|
38
|
-
def
|
45
|
+
def add_result(h)
|
46
|
+
columns=""
|
47
|
+
values=""
|
48
|
+
[:uri,:revision,:dir,:user,:machine,:ruby_version,:ruby_platform,:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each { |s|
|
49
|
+
sval=""
|
50
|
+
sval=h[s].to_s if h.has_key?(s)
|
51
|
+
sval.gsub("'","''") # need to escape single quotes for sqlite
|
52
|
+
columns="#{columns}," if columns.length > 0
|
53
|
+
values="#{values}," if values.length > 0
|
54
|
+
columns="#{columns}#{s.to_s}"
|
55
|
+
values="#{values}'#{sval}'"
|
56
|
+
}
|
57
|
+
#puts "insert or replace into Results (#{columns}) VALUES (#{values});"
|
58
|
+
@db.execute("insert or replace into Results (#{columns}) VALUES (#{values});")
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_results(where_hash)
|
62
|
+
array=Array.new
|
63
|
+
where=""
|
64
|
+
where_hash.each{ |k,v|
|
65
|
+
sval=v.to_s
|
66
|
+
sval.gsub("'","''") # need to escape single quotes for sqlite
|
67
|
+
where="#{where} AND " if where.length > 0
|
68
|
+
where="#{where}#{k.to_s}='#{sval}'"
|
69
|
+
}
|
70
|
+
|
71
|
+
columns=""
|
72
|
+
[:uri,:revision,:dir,:user,:machine,:ruby_version,:ruby_platform,:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each { |s|
|
73
|
+
columns="#{columns}," if columns.length > 0
|
74
|
+
columns="#{columns}#{s.to_s}"
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
@db.execute("select #{columns} from Results where #{where};") do |row|
|
79
|
+
h=Hash.new
|
80
|
+
index = 0
|
81
|
+
[:uri,:revision,:dir,:user,:machine,:ruby_version,:ruby_platform,:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each { |s|
|
82
|
+
#puts "row[#{index}].to_s=#{row[index].to_s}"
|
83
|
+
h[s]=row[index].to_s
|
84
|
+
index=index+1
|
85
|
+
}
|
86
|
+
array << h if !h.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
return array
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_branch_uri(name)
|
93
|
+
uri=""
|
39
94
|
@db.execute("select Uri from Branches where Name='#{name}';") do |row|
|
40
|
-
|
95
|
+
uri=eval(row[0].to_s)[0]
|
41
96
|
end
|
42
|
-
return
|
97
|
+
return uri
|
43
98
|
end
|
44
99
|
|
45
100
|
def find_branches(pattern)
|
@@ -47,7 +102,7 @@ class Database
|
|
47
102
|
sql="select Name from Branches where Name LIKE '#{pattern}';"
|
48
103
|
sql="select Name from Branches;" if pattern.nil? || pattern.length==0
|
49
104
|
@db.execute(sql) do |row|
|
50
|
-
names << row[0]
|
105
|
+
names << row[0] if(row[0].length > 0)
|
51
106
|
end
|
52
107
|
return names
|
53
108
|
end
|
data/lib/dev/SystemCall.rb
CHANGED
@@ -7,7 +7,7 @@ require 'systemu'
|
|
7
7
|
module Dev
|
8
8
|
|
9
9
|
class SystemCall
|
10
|
-
attr_accessor :output,:error,:status,:command,:start_time,:end_time,:timed_out,:dir,:cache, :capture_output, :capture_error
|
10
|
+
attr_accessor :output,:error,:status,:command,:start_time,:end_time,:timeout,:timed_out,:dir,:cache, :capture_output, :capture_error
|
11
11
|
|
12
12
|
def initialize(cmd)
|
13
13
|
if(cmd.kind_of?(Hash))
|
@@ -41,7 +41,9 @@ class SystemCall
|
|
41
41
|
hash[:status]=@status
|
42
42
|
hash[:start_time]=@start_time
|
43
43
|
hash[:end_time]=@end_time
|
44
|
-
|
44
|
+
hash[:elapsed]=elapsed.to_s
|
45
|
+
hash[:time_out]=@time_out
|
46
|
+
hash[:timeout]=@timeout
|
45
47
|
hash[:cache]=@cache
|
46
48
|
hash[:capture_output]=@capture_output
|
47
49
|
hash[:capture_error]=@capture_error
|
@@ -56,6 +58,7 @@ class SystemCall
|
|
56
58
|
@status=hash[:status] unless hash[:status].nil?
|
57
59
|
@start_time=hash[:start_time] unless hash[:start_time].nil?
|
58
60
|
@end_time=hash[:end_time] unless hash[:end_time].nil?
|
61
|
+
@time_out=hash[:timeout] unless hash[:timeout].nil?
|
59
62
|
@timed_out=hash[:timed_out] unless hash[:timed_out].nil?
|
60
63
|
@cache=hash[:cache] unless hash[:cache].nil?
|
61
64
|
@capture_output=hash[:capture_output] unless hash[:capture_output].nil?
|
@@ -174,6 +177,22 @@ class SystemCall
|
|
174
177
|
puts summary
|
175
178
|
end
|
176
179
|
end
|
180
|
+
|
181
|
+
def self.puts_hash_summary(h)
|
182
|
+
if(h[:status] != 0 && h[:status] != "0")
|
183
|
+
summary = " [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan) + " " + h[:cmd].foreground(:green) + " has exit status of " + h[:status].to_s
|
184
|
+
summary += " dir: " + h[:dir] unless h[:dir].nil?
|
185
|
+
puts summary
|
186
|
+
puts h[:output] if !h[:output].nil?
|
187
|
+
warn h[:error] if !h[:error].nil?
|
188
|
+
throw "exit status was " + h[:status].to_s
|
189
|
+
else
|
190
|
+
elapsed_str="[" + "%.0f" %(h[:elapsed]) + "s]"
|
191
|
+
summary = " [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan) + " " + h[:cmd].foreground(:green) + " " + elapsed_str.foreground(:cyan)
|
192
|
+
summary += " dir: " + h[:dir] unless h[:dir].nil?
|
193
|
+
puts summary
|
194
|
+
end
|
195
|
+
end
|
177
196
|
|
178
197
|
end # class SystemCall
|
179
198
|
|
data/lib/dev/Tasks.rb
CHANGED
@@ -21,20 +21,25 @@ CLOBBER.include('bin','obj')
|
|
21
21
|
def generate_task_hash(project)
|
22
22
|
task_hash = {
|
23
23
|
:info=> { :desc=> 'display information about the rakefile' },
|
24
|
-
|
24
|
+
#:test=> { :desc=> 'run unit tests' },
|
25
25
|
:loc=> { :desc=> 'count the lines of code' },
|
26
|
-
|
26
|
+
#:setup=> { :desc=> 'setup the project environment' },
|
27
27
|
:pull=> { :desc=> 'rake working copies of dependencies' },
|
28
28
|
:check=> { :desc=> 'checks if the project default task may be skipped' }
|
29
29
|
}
|
30
|
+
if(!project[:setup].nil? && project[:setup].length > 0)
|
31
|
+
task_hash[:setup]={ :desc=> 'setup the project environment' }
|
32
|
+
end
|
33
|
+
|
30
34
|
if(project[:scm_type]=="svn" || project[:scm_type]=="git")
|
31
35
|
task_hash[:add] ={ :desc=> 'add files defined by src_glob to source code management' }
|
32
36
|
task_hash[:commit]={ :desc=> 'commit changes to source code management' }
|
33
37
|
task_hash[:update]={ :desc=> 'updates changes from source code management' }
|
34
38
|
end
|
35
39
|
|
36
|
-
task_hash[:compile] = { :desc=> 'compile source code' } if CMD.has_key?(:compile)
|
37
|
-
task_hash[:replace] = { :desc=> 'replace text' } if CMD.has_key?(:replace)
|
40
|
+
task_hash[:compile] = { :desc=> 'compile source code' } if CMD.has_key?(:compile) && CMD[:compile].length > 0 #project.has_key?(:compile) && project[:compile].length > 0
|
41
|
+
task_hash[:replace] = { :desc=> 'replace text' } if CMD.has_key?(:replace) && CMD[:replace].length > 0
|
42
|
+
task_hash[:test]={:desc=>'run unit tests'} if CMD.has_key?(:test) && CMD[:test].length > 0
|
38
43
|
|
39
44
|
if project[:type]=="gem" || project[:type]=="ruby"
|
40
45
|
task_hash[:features] = { :desc=> 'tests cucumber features' }
|
@@ -64,13 +69,14 @@ def generate_tasks(project)
|
|
64
69
|
Rake.application.instance_variable_get('@tasks').delete('default')
|
65
70
|
task_list=""
|
66
71
|
["check","add","setup","replace","compile","post_compile","test","commit","update"].each {|t|
|
67
|
-
if(hash.has_key?(t.to_sym) || task_exists?(t) || CMD.has_key?(t.to_sym) )
|
72
|
+
if(hash.has_key?(t.to_sym) || task_exists?(t) || (CMD.has_key?(t.to_sym) && CMD[t.to_sym].count > 0) )
|
68
73
|
task_list = "#{task_list}," if task_list.length > 0
|
69
74
|
task_list = "#{task_list} :#{t}"
|
70
75
|
default_code = "#{default_code} :#{t},"
|
71
76
|
end
|
72
77
|
}
|
73
|
-
|
78
|
+
desc="desc '#{task_list}'".gsub(' ',"").gsub(':',"")
|
79
|
+
eval("#{desc}; task :default => [#{task_list}] do; task_start('default'); end")
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Dev
|
2
|
+
module Cmd
|
3
|
+
class Build
|
4
|
+
|
5
|
+
def self.build(branch)
|
6
|
+
db=Dev::Database.new
|
7
|
+
|
8
|
+
puts " "
|
9
|
+
puts "building branch " + branch.foreground(:green)
|
10
|
+
h=Dev::Cmd::Build.get_branch_hash(branch)
|
11
|
+
Hash.print_hash("",h)
|
12
|
+
|
13
|
+
# does a result already exist?
|
14
|
+
results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}", :user=>"#{h[:user]}", :machine=>"#{h[:machine]}"})
|
15
|
+
|
16
|
+
result=results[0] if !results.empty?
|
17
|
+
if(results.empty?)
|
18
|
+
result=h
|
19
|
+
|
20
|
+
# export to local directory
|
21
|
+
FileUtils.mkdir("#{Dev::Enviroment.dev_root}/exp") if !File.exists?("#{Dev::Environment.dev_root}/exp")
|
22
|
+
FileUtils.rm_r(h[:dir]) if File.exists? h[:dir]
|
23
|
+
Dev::Commands.execute_cmd("svn export #{h[:uri]}@#{h[:revision]} #{h[:dir]}")
|
24
|
+
|
25
|
+
# rake in local directory
|
26
|
+
call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true})
|
27
|
+
call.puts_summary
|
28
|
+
|
29
|
+
ch=call.get_hash
|
30
|
+
[:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each{ |k| h[k]=ch[k]; }
|
31
|
+
|
32
|
+
# store results to database
|
33
|
+
|
34
|
+
db.add_result(result)
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "results hash:"
|
38
|
+
puts " "
|
39
|
+
Hash.print_hash("",result)
|
40
|
+
|
41
|
+
Dev::SystemCall.puts_hash_summary(result)
|
42
|
+
|
43
|
+
return 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.status(branch)
|
47
|
+
db=Dev::Database.new
|
48
|
+
#puts "status of branch " + branch.foreground(:green) + "@#{h[:revision]}"
|
49
|
+
h=Dev::Cmd::Build.get_branch_hash(branch)
|
50
|
+
puts "status of branch " + branch.foreground(:green) + "@#{h[:revision]}"
|
51
|
+
#Hash.print_hash("",h)
|
52
|
+
|
53
|
+
# do any results exist for latest revision?
|
54
|
+
results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}"})
|
55
|
+
|
56
|
+
puts " no results" if results.empty?
|
57
|
+
|
58
|
+
fail=" [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan)
|
59
|
+
pass=" [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan)
|
60
|
+
results.each{ |r|
|
61
|
+
status=pass
|
62
|
+
status=fail if r[:status] != 0 && r[:status] != "0"
|
63
|
+
elapsed="[" + "%.0f" %(r[:elapsed]) + "s]".foreground(:cyan)
|
64
|
+
context="#{r[:user]}@#{r[:machine]}".foreground(:green)
|
65
|
+
puts "#{status} #{context} #{elapsed} #{r[:end_time]}"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.work(branch)
|
70
|
+
db=Dev::Database.new
|
71
|
+
|
72
|
+
puts " "
|
73
|
+
puts "working on branch " + branch.foreground(:green)
|
74
|
+
h=Dev::Cmd::Build.get_branch_hash(branch)
|
75
|
+
h[:dir]="#{Dev::Environment.dev_root}/wrk/#{branch}"
|
76
|
+
#Hash.print_hash("",h)
|
77
|
+
|
78
|
+
# export to local directory
|
79
|
+
FileUtils.mkdir("#{Dev::Enviroment.dev_root}/wrk") if !File.exists?("#{Dev::Environment.dev_root}/wrk")
|
80
|
+
Dev::Commands.execute_cmd("svn co #{h[:uri]} #{h[:dir]}") if !File.exists? h[:dir]
|
81
|
+
|
82
|
+
# rake in local directory
|
83
|
+
call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true})
|
84
|
+
puts "------------------------------------------------------------".foreground(:green)
|
85
|
+
call.puts_summary
|
86
|
+
puts "------------------------------------------------------------".foreground(:green)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.get_branch_hash(branch)
|
91
|
+
db=Dev::Database.new
|
92
|
+
h=Hash.new
|
93
|
+
h[:uri]=db.get_branch_uri(branch)
|
94
|
+
h[:revision]=Dev::Svn.last_changed_revision(h[:uri])
|
95
|
+
h[:dir]="#{Dev::Environment.dev_root}/exp/#{branch}-#{h[:revision]}"
|
96
|
+
h[:user]="#{Dev::Environment.user}"
|
97
|
+
h[:machine]="#{Dev::Environment.machine}"
|
98
|
+
h[:ruby_version]=RUBY_VERSION
|
99
|
+
h[:ruby_platform]=RUBY_PLATFORM
|
100
|
+
return h
|
101
|
+
end
|
102
|
+
|
103
|
+
end # class Setup
|
104
|
+
end # module Cmd
|
105
|
+
end # module Dev
|
data/lib/dev/cmd/Compile.rb
CHANGED
@@ -19,7 +19,7 @@ class Compile < Array
|
|
19
19
|
platforms=Dev::Cmd::Compile.extract_platforms(csproj)
|
20
20
|
platforms.each { |platform|
|
21
21
|
skip=(!RUBY_PLATFORM.include?("w32") && platform=="x64")
|
22
|
-
|
22
|
+
self << "{:cmd=> '#{csbuild} #{csproj} /property:Configuration=Release /property:Platform=\"#{platform}\" /p:OutputPath=./bin/#{platform}/Release', :auto=>true}" if !skip
|
23
23
|
}
|
24
24
|
}
|
25
25
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.148
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- README
|
167
167
|
- lib/dev/Array.rb
|
168
168
|
- lib/dev/BoostBuild.rb
|
169
|
+
- lib/dev/cmd/Build.rb
|
169
170
|
- lib/dev/cmd/Commit.rb
|
170
171
|
- lib/dev/cmd/Compile.rb
|
171
172
|
- lib/dev/cmd/Info.rb
|
@@ -209,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
210
|
version: '0'
|
210
211
|
requirements: []
|
211
212
|
rubyforge_project: dev
|
212
|
-
rubygems_version: 1.8.
|
213
|
+
rubygems_version: 1.8.23
|
213
214
|
signing_key:
|
214
215
|
specification_version: 3
|
215
216
|
summary: dev
|