8 # Following hack is required to allow passing variable |
8 # Following hack is required to allow passing variable |
9 # values in `make` style, i.e., to allow for |
9 # values in `make` style, i.e., to allow for |
10 # |
10 # |
11 # rake PROJECT=stx:jv-branch compile |
11 # rake PROJECT=stx:jv-branch compile |
12 # |
12 # |
13 ARGV.each do | arg | |
13 ARGV.each do |arg| |
14 name_and_value = /^([A-Za-z_]+)\w*=(.*)/.match(arg) |
14 name_and_value = /^([A-Za-z_]+)\w*=(.*)/.match(arg) |
15 if name_and_value |
15 self.class.const_set(name_and_value[1], name_and_value[2]) if name_and_value |
16 self.class.const_set(name_and_value[1], name_and_value[2]) |
|
17 end |
|
18 end |
16 end |
19 |
17 |
20 # Update PATH for build so build scripts may access scripts and programs |
18 # Update PATH for build so build scripts may access scripts and programs |
21 # in `bin` directory. This is required especially on Windows as Windows do |
19 # in `bin` directory. This is required especially on Windows as Windows do |
22 # not ship with some basic tools (e.g. zip) by default. As a courtesy to the |
20 # not ship with some basic tools (e.g. zip) by default. As a courtesy to the |
26 # with dinosaurs) |
24 # with dinosaurs) |
27 ENV['PATH'] = "#{File.expand_path('bin')};#{File::PATH_SEPARATOR}#{ENV['PATH']}" |
25 ENV['PATH'] = "#{File.expand_path('bin')};#{File::PATH_SEPARATOR}#{ENV['PATH']}" |
28 |
26 |
29 # Return true if running under Jenkins, false otherwise |
27 # Return true if running under Jenkins, false otherwise |
30 def jenkins? |
28 def jenkins? |
31 return (ENV.has_key? 'WORKSPACE' and |
29 (ENV.has_key? 'WORKSPACE' and |
32 ENV.has_key? 'JOB_NAME' and |
30 ENV.has_key? 'JOB_NAME' and |
33 ENV.has_key? 'BUILD_ID') |
31 ENV.has_key? 'BUILD_ID') |
34 end |
32 end |
35 |
33 |
36 # Returns true if and only if this is machine of one of the core developers |
34 # Returns true if and only if this is machine of one of the core developers |
37 # (currently only JV). |
35 # (currently only JV). |
38 # Indeed this is a feeble check and can be easily bypassed by chaning the |
36 # Indeed this is a feeble check and can be easily bypassed by changing the |
39 # code or by setting a proper environment variable. But this should not hurt |
37 # code or by setting a proper environment variable. But this should not hurt |
40 # much as in that case, unauthorized person wouldn't be able to connect to |
38 # much as in that case, unauthorized person wouldn't be able to connect to |
41 # stc and librun repository so the build will fail. |
39 # stc and librun repository so the build will fail. |
42 def core_developer? |
40 def core_developer? |
43 # JV's box: jv@..., vranyj1@... |
41 # JV's box: jv@..., vranyj1@... |
44 user = ENV['USER'] || ENV['USERNAME'] |
42 user = ENV['USER'] || ENV['USERNAME'] |
45 if (user == 'jv') or (user == 'vranyj1') |
43 (user == 'jv') or (user == 'vranyj1') ? true : false |
46 return true |
|
47 end |
|
48 return false |
|
49 end |
44 end |
50 |
45 |
51 # A super simple API for Jenkins used to download pre-built stc and librun. |
46 # A super simple API for Jenkins used to download pre-built stc and librun. |
52 module Jenkins |
47 module Jenkins |
53 # Return an a Jenkins build with pre-built stc and librun. |
48 # Return an a Jenkins build with pre-built stc and librun. |
54 # Used to download pre-build stc and librun |
49 # Used to download pre-build stc and librun |
55 def self.smalltalkx_jv_branch_build() |
50 def self.smalltalkx_jv_branch_build |
56 plat = nil |
51 plat = nil |
57 if win32? then |
52 if win32? |
58 plat = 'Windows' |
53 plat = 'Windows' |
59 elsif linux? |
54 elsif linux? |
60 plat = 'Linux' |
55 plat = 'Linux' |
61 else |
56 else |
62 error_unsupported_platform() |
57 error_unsupported_platform |
63 end |
58 end |
64 return Jenkins::Build.new(%Q{https://swing.fit.cvut.cz/jenkins/job/stx_jv/ARCH=#{ARCH},PLATFORM=#{plat}N/lastSuccessfulBuild}) |
59 return Jenkins::Build.new(%Q{https://swing.fit.cvut.cz/jenkins/job/stx_jv/ARCH=#{ARCH},PLATFORM=#{plat}N/lastSuccessfulBuild}) |
65 end |
60 end |
66 |
61 |
67 class Artifact |
62 class Artifact |
71 def initialize(name, uri) |
66 def initialize(name, uri) |
72 @name = name |
67 @name = name |
73 @uri = uri |
68 @uri = uri |
74 end |
69 end |
75 |
70 |
76 def download_to(destination) |
71 def download_to(destination) |
77 if not File.exist? destination |
72 if !File.exist? destination |
78 if not File.directory? File.dirname(destination) |
73 raise Exception.new("Invalid destination for download: #{destination}") unless File.directory? File.dirname(destination) |
79 raise Exception.new("Invalid destination for download: #{destination}") |
|
80 end |
|
81 else |
74 else |
82 if not File.directory? destination |
75 if !File.directory? destination |
83 raise Exception.new("Invalid destination for download: #{destination}") |
76 raise Exception.new("Invalid destination for download: #{destination}") |
84 else |
77 else |
85 destination = File.join(destination, @name) |
78 destination = File.join(destination, @name) |
86 end |
79 end |
87 end |
80 end |
88 Jenkins::get(@uri) do | response | |
81 Jenkins::get(@uri) do |response| |
89 File.open(destination, "wb") do | file | |
82 File.open(destination, 'wb') do |file| |
90 response.read_body do | part | |
83 response.read_body {|part| file.write part} |
91 file.write part |
|
92 end |
|
93 end |
84 end |
94 end |
85 end |
95 end |
86 end |
96 end |
87 end |
97 |
88 |
104 @data = JSON.parse(Jenkins::get(URI(uri.to_s + '/api/json'))) |
95 @data = JSON.parse(Jenkins::get(URI(uri.to_s + '/api/json'))) |
105 end |
96 end |
106 |
97 |
107 # Return a list of artifacts (as instances of `Jenkins::Artifact`) |
98 # Return a list of artifacts (as instances of `Jenkins::Artifact`) |
108 # associated with this build. |
99 # associated with this build. |
109 def artifacts() |
100 def artifacts |
110 if not @artifacts then |
101 unless @artifacts |
111 @artifacts = @data["artifacts"].collect do | each | |
102 @artifacts = @data['artifacts'].collect {|each| Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath']))} |
112 Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath'])) |
|
113 end |
|
114 end |
103 end |
115 return @artifacts |
104 @artifacts |
116 end |
105 end |
117 end |
106 end |
118 |
107 |
119 # A private method to GET data over HTTP(S) |
108 # A private method to GET data over HTTP(S) |
120 def self.get(uri, &block) |
109 def self.get(uri, &block) |
121 # http parameters |
110 # http parameters |
122 http_host = Net::HTTP.new(uri.host, uri.port) |
111 http_host = Net::HTTP.new(uri.host, uri.port) |
123 http_host.use_ssl = (uri.scheme == 'https') # simple true enough |
112 http_host.use_ssl = (uri.scheme == 'https') # simple true enough |
124 |
113 |
125 if false # host verification not used (yet) |
114 if false # host verification not used (yet) |