autobuild 1.9.6 → 1.10.0.b1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d32aea62919186daa0c848f227876a196a27f7a
4
- data.tar.gz: 41f822118c0087c991b84924d4192fdd3d3f835e
3
+ metadata.gz: e42c625c20b8bfbb4fc824fc40a9b2a41f5d6bb6
4
+ data.tar.gz: c35720c6c894d3fb3337bafb17424b72c9b1e9e1
5
5
  SHA512:
6
- metadata.gz: 1285b76ff9092c239da7995261277a61e866396f590d62f86f0283298362db87bb0dfd587491a10eb92f2955f92cfc7196caad560875e792980d9caa842a244b
7
- data.tar.gz: bf5c0c9728d0a47d78fb205f87acce329042a1c83ca03842debbb480a4b1898bfe02b5d61aa4eba4ea1bd64b6cf0255a60f5567031e6164f5c492821420235e0
6
+ metadata.gz: 728e7d5f5a968767e5d5bea8368bfda85c2601b6d66647f8d2f52ae7fe26019f1ef361ce3b0d9cf43b49e4ee71eb6c794c7b146eeb72c01543b495f83caefa2a
7
+ data.tar.gz: bc5181729cf2196ab580d175efcf411e0a79f9d3abc02e06280dda2bc15f595e0e8fa40b54cdcba1c11b6cec38ed316067f5de30d642049fdfb82785814ae340
data/.gemtest ADDED
File without changes
data/Manifest.txt CHANGED
@@ -18,6 +18,7 @@ lib/autobuild/import/hg.rb
18
18
  lib/autobuild/import/svn.rb
19
19
  lib/autobuild/import/tar.rb
20
20
  lib/autobuild/importer.rb
21
+ lib/autobuild/mail_reporter.rb
21
22
  lib/autobuild/package.rb
22
23
  lib/autobuild/packages/autotools.rb
23
24
  lib/autobuild/packages/cmake.rb
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ Utilrb::Rake.hoe do
15
15
 
16
16
  self.extra_deps <<
17
17
  ['rake', '>= 0.9.0'] <<
18
- ['utilrb', '~> 2.0.0'] <<
18
+ ['utilrb', '>= 1.6.0'] <<
19
19
  ['highline', '>= 0']
20
20
 
21
21
  self.test_globs = ['test/suite.rb']
data/lib/autobuild.rb CHANGED
@@ -8,14 +8,6 @@ module Autobuild
8
8
  LIB_DIR = File.expand_path(File.dirname(__FILE__))
9
9
  end
10
10
 
11
- begin
12
- require 'rmail'
13
- require 'rmail/serialize'
14
- Autobuild::HAS_RMAIL = true
15
- rescue LoadError
16
- Autobuild::HAS_RMAIL = false
17
- end
18
-
19
11
  require 'net/smtp'
20
12
  require 'socket'
21
13
  require 'etc'
@@ -32,6 +24,7 @@ require 'autobuild/environment'
32
24
  require 'autobuild/exceptions'
33
25
  require 'autobuild/pkgconfig'
34
26
  require 'autobuild/reporting'
27
+ require 'autobuild/mail_reporter'
35
28
  require 'autobuild/subcommand'
36
29
  require 'autobuild/timestamps'
37
30
  require 'autobuild/parallel'
@@ -52,7 +52,6 @@ module Autobuild
52
52
  @builddir = 'build'
53
53
 
54
54
  def builddir=(new)
55
- raise ConfigException.new(self), "absolute builddirs are not supported" if (Pathname.new(new).absolute?)
56
55
  raise ConfigException.new(self), "builddir must be non-empty" if new.empty?
57
56
  @builddir = new
58
57
  end
@@ -1,12 +1,8 @@
1
1
  require 'set'
2
2
  require 'rbconfig'
3
+ require 'utilrb/hash/map_value'
3
4
 
4
5
  module Autobuild
5
- @inherited_environment = Hash.new
6
- @environment = Hash.new
7
- @env_source_before = Set.new
8
- @env_source_after = Set.new
9
-
10
6
  @windows = RbConfig::CONFIG["host_os"] =~%r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
11
7
  def self.windows?
12
8
  @windows
@@ -19,18 +15,13 @@ module Autobuild
19
15
 
20
16
  @freebsd = RbConfig::CONFIG["host_os"].include?('freebsd')
21
17
  def self.freebsd?
22
- @freebsd
18
+ @freebsd
23
19
  end
24
20
 
25
21
  def self.bsd?
26
- @freebsd || @macos #can be extended to some other OSes liek NetBSD
22
+ @freebsd || @macos #can be extended to some other OSes liek NetBSD
27
23
  end
28
24
 
29
- SYSTEM_ENV = Hash.new
30
- ORIGINAL_ENV = Hash.new
31
- ENV.each do |k, v|
32
- ORIGINAL_ENV[k] = v
33
- end
34
25
  SHELL_VAR_EXPANSION =
35
26
  if windows? then "%%%s%%"
36
27
  else "$%s"
@@ -68,15 +59,13 @@ module Autobuild
68
59
  else 'so'
69
60
  end
70
61
 
62
+ ORIGINAL_ENV = Hash.new
63
+ ENV.each do |k, v|
64
+ ORIGINAL_ENV[k] = v
65
+ end
71
66
 
72
- class << self
73
- # List of the environment that should be set before calling a subcommand
74
- #
75
- # It is a map from environment variable name to the corresponding value.
76
- # If the value is an array, it is joined using the operating system's
77
- # path separator (File::PATH_SEPARATOR)
78
- attr_reader :environment
79
-
67
+ # Manager class for environment variables
68
+ class Environment
80
69
  # In generated environment update shell files, indicates whether an
81
70
  # environment variable should be overriden by the shell script, or
82
71
  # simply updated
@@ -90,415 +79,630 @@ module Autobuild
90
79
  #
91
80
  # export VARNAME=new_value:new_value
92
81
  attr_reader :inherited_environment
93
- end
82
+ # List of the environment that should be set before calling a subcommand
83
+ #
84
+ # It is a map from environment variable name to the corresponding value.
85
+ # If the value is an array, it is joined using the operating system's
86
+ # path separator (File::PATH_SEPARATOR)
87
+ attr_reader :environment
88
+ attr_reader :source_after
89
+ attr_reader :source_before
90
+
91
+ attr_reader :inherited_variables
92
+
93
+ attr_reader :resolved_env
94
+ attr_reader :system_env
95
+ attr_reader :original_env
96
+
97
+ def initialize
98
+ @inherited_environment = Hash.new
99
+ @environment = Hash.new
100
+ @source_before = Set.new
101
+ @source_after = Set.new
102
+ @inherit = true
103
+ @inherited_variables = Set.new
104
+
105
+ @system_env = Hash.new
106
+ @original_env = ORIGINAL_ENV.dup
107
+ @resolved_env = Hash.new
108
+ ENV.each do |k, v|
109
+ resolved_env[k] = v
110
+ end
111
+ end
94
112
 
95
- # Resets the value of +name+ to its original value. If it is inherited from
96
- # the
97
- def self.env_reset(name = nil)
98
- if name
99
- environment.delete(name)
100
- inherited_environment.delete(name)
101
- env_init_from_env(name)
102
- else
103
- environment.keys.each do |env_key|
104
- env_reset(env_key)
113
+ def initialize_copy(old)
114
+ super
115
+ @inherited_environment = @inherited_environment.
116
+ map_value { |k, v| v.dup }
117
+ @environment = @environment.
118
+ map_value { |k, v| v.dup }
119
+ @source_before = @source_before.dup
120
+ @source_after = @source_after.dup
121
+ @inherited_variables = @inherited_variables.dup
122
+
123
+ @system_env = @system_env.
124
+ map_value { |k, v| v.dup }
125
+ @original_env = @original_env.
126
+ map_value { |k, v| v.dup }
127
+ @resolved_env = @resolved_env.
128
+ map_value { |k, v| v.dup }
129
+ end
130
+
131
+ def [](name)
132
+ resolved_env[name]
133
+ end
134
+
135
+ # Resets the value of +name+ to its original value. If it is inherited from
136
+ # the
137
+ def reset(name = nil)
138
+ if name
139
+ environment.delete(name)
140
+ inherited_environment.delete(name)
141
+ init_from_env(name)
142
+ else
143
+ environment.keys.each do |env_key|
144
+ reset(env_key)
145
+ end
105
146
  end
106
147
  end
107
- end
108
148
 
109
- # Unsets any value on the environment variable +name+, including inherited
110
- # value.
111
- #
112
- # In a bourne shell, this would be equivalent to doing
113
- #
114
- # unset name
115
- #
116
- def self.env_clear(name = nil)
117
- if name
118
- environment[name] = nil
119
- inherited_environment[name] = nil
120
- env_update_var(name)
121
- else
122
- environment.keys.each do |env_key|
123
- env_clear(env_key)
149
+ # Unsets any value on the environment variable +name+, including inherited
150
+ # value.
151
+ #
152
+ # In a bourne shell, this would be equivalent to doing
153
+ #
154
+ # unset name
155
+ #
156
+ def clear(name = nil)
157
+ if name
158
+ environment[name] = nil
159
+ inherited_environment[name] = nil
160
+ update_var(name)
161
+ else
162
+ environment.keys.each do |env_key|
163
+ clear(env_key)
164
+ end
124
165
  end
125
166
  end
126
- end
127
167
 
128
- # Set a new environment variable
129
- def self.env_set(name, *values)
130
- environment.delete(name)
131
- env_add(name, *values)
132
- end
168
+ # Set a new environment variable
169
+ def set(name, *values)
170
+ environment.delete(name)
171
+ add(name, *values)
172
+ end
133
173
 
134
- @env_inherit = true
135
- @env_inherited_variables = Set.new
136
174
 
137
- # Returns true if the given environment variable must not be reset by the
138
- # env.sh script, but that new values should simply be prepended to it.
139
- #
140
- # @param [String,nil] name the environment variable that we want to check
141
- # for inheritance. If nil, the global setting is returned.
142
- #
143
- # @see env_inherit env_inherit=
144
- def self.env_inherit?(name = nil)
145
- if @env_inherit
146
- if name
147
- @env_inherited_variables.include?(name)
148
- else true
175
+ # Returns true if the given environment variable must not be reset by the
176
+ # env.sh script, but that new values should simply be prepended to it.
177
+ #
178
+ # @param [String,nil] name the environment variable that we want to check
179
+ # for inheritance. If nil, the global setting is returned.
180
+ #
181
+ # @see env_inherit env_inherit=
182
+ def inherit?(name = nil)
183
+ if @inherit
184
+ if name
185
+ @inherited_variables.include?(name)
186
+ else true
187
+ end
149
188
  end
150
189
  end
151
- end
152
190
 
153
- # If true (the default), the environment variables that are marked as
154
- # inherited will be inherited from the global environment (during the
155
- # build as well as in the generated env.sh files)
156
- #
157
- # Otherwise, only the environment that is explicitely set in autobuild
158
- # will be passed on to subcommands, and saved in the environment
159
- # scripts.
160
- #
161
- # @see env_inherit? env_inherit
162
- def self.env_inherit=(value)
163
- @env_inherit = value
164
- inherited_environment.keys.each do |env_name|
165
- env_init_from_env(env_name)
191
+ # If true (the default), the environment variables that are marked as
192
+ # inherited will be inherited from the global environment (during the
193
+ # build as well as in the generated env.sh files)
194
+ #
195
+ # Otherwise, only the environment that is explicitely set in autobuild
196
+ # will be passed on to subcommands, and saved in the environment
197
+ # scripts.
198
+ #
199
+ # @see inherit? inherit
200
+ def inherit=(value)
201
+ @inherit = value
202
+ inherited_environment.keys.each do |env_name|
203
+ init_from_env(env_name)
204
+ end
166
205
  end
167
- end
168
206
 
169
- # Declare that the given environment variable must not be reset by the
170
- # env.sh script, but that new values should simply be prepended to it.
171
- #
172
- # @return [Boolean] true if environment inheritance is globally enabled and
173
- # false otherwise. This is controlled by {env_inherit=}
174
- #
175
- # @see env_inherit? env_inherit=
176
- def self.env_inherit(*names)
177
- flag =
178
- if !names.last.respond_to?(:to_str)
179
- names.pop
180
- else true
181
- end
182
-
183
- if flag
184
- @env_inherited_variables |= names
185
- names.each do |env_name|
186
- env_init_from_env(env_name)
187
- end
188
- else
189
- names.each do |n|
190
- if @env_inherited_variables.include?(n)
191
- @env_inherited_variables.delete(n)
192
- env_init_from_env(n)
207
+ # Declare that the given environment variable must not be reset by the
208
+ # env.sh script, but that new values should simply be prepended to it.
209
+ #
210
+ # @return [Boolean] true if environment inheritance is globally enabled and
211
+ # false otherwise. This is controlled by {env_inherit=}
212
+ #
213
+ # @see env_inherit? env_inherit=
214
+ def inherit(*names)
215
+ flag =
216
+ if !names.last.respond_to?(:to_str)
217
+ names.pop
218
+ else true
219
+ end
220
+
221
+ if flag
222
+ @inherited_variables |= names
223
+ names.each do |env_name|
224
+ init_from_env(env_name)
225
+ end
226
+ else
227
+ names.each do |n|
228
+ if @inherited_variables.include?(n)
229
+ @inherited_variables.delete(n)
230
+ init_from_env(n)
231
+ end
193
232
  end
194
233
  end
195
- end
196
234
 
197
- @env_inherit
198
- end
235
+ @inherit
236
+ end
199
237
 
200
- def self.env_init_from_env(name)
201
- if env_inherit?(name) && (parent_env = ORIGINAL_ENV[name])
202
- inherited_environment[name] = parent_env.split(File::PATH_SEPARATOR)
203
- else
204
- inherited_environment[name] = Array.new
238
+ def init_from_env(name)
239
+ if inherit?(name) && (parent_env = original_env[name])
240
+ inherited_environment[name] = parent_env.split(File::PATH_SEPARATOR)
241
+ else
242
+ inherited_environment[name] = Array.new
243
+ end
244
+ update_var(name)
205
245
  end
206
- env_update_var(name)
207
- end
208
246
 
209
- def self.env_push(name, *values)
210
- if current = environment[name]
211
- current = current.dup
212
- env_set(name, *values)
213
- env_add(name, *current)
214
- else
215
- env_add(name, *values)
247
+ def push(name, *values)
248
+ if current = environment[name]
249
+ current = current.dup
250
+ env_set(name, *values)
251
+ env_add(name, *current)
252
+ else
253
+ env_add(name, *values)
254
+ end
216
255
  end
217
- end
218
256
 
219
- # Adds a new value to an environment variable
220
- def self.env_add(name, *values)
221
- set = if environment.has_key?(name)
222
- environment[name]
223
- end
257
+ # Adds a new value to an environment variable
258
+ def add(name, *values)
259
+ values = values.map { |v| expand(v) }
224
260
 
225
- if !inherited_environment.has_key?(name)
226
- env_init_from_env(name)
227
- end
261
+ set = if environment.has_key?(name)
262
+ environment[name]
263
+ end
228
264
 
229
- if !set
230
- set = Array.new
231
- elsif !set.respond_to?(:to_ary)
232
- set = [set]
265
+ if !inherited_environment.has_key?(name)
266
+ init_from_env(name)
267
+ end
268
+
269
+ if !set
270
+ set = Array.new
271
+ elsif !set.respond_to?(:to_ary)
272
+ set = [set]
273
+ end
274
+
275
+ values.concat(set)
276
+ @environment[name] = values
277
+ update_var(name)
233
278
  end
234
279
 
235
- values.concat(set)
236
- @environment[name] = values
237
- env_update_var(name)
238
- end
280
+ # Returns an environment variable value
281
+ #
282
+ # @param [String] name the environment variable name
283
+ # @option options [Symbol] inheritance_mode (:expand) controls how
284
+ # environment variable inheritance should be done. If :expand, the current
285
+ # envvar value is inserted in the generated value. If :keep, the name of
286
+ # the envvar is inserted (as e.g. $NAME). If :ignore, inheritance is
287
+ # disabled in the generated value. Not that this applies only for the
288
+ # environment variables for which inheritance has been enabled with
289
+ # {#inherit}, other variables always behave as if :ignore was selected.
290
+ # @return [nil,Array<String>] either nil if this environment variable is not
291
+ # set, or an array of values. How the values should be joined to form the
292
+ # actual value is OS-specific, and not handled by this method
293
+ def value(name, options = Hash.new)
294
+ # For backward compatibility only
295
+ if !options.respond_to?(:to_hash)
296
+ if options
297
+ options = Hash[:inheritance_mode => :expand]
298
+ else
299
+ options = Hash[:inheritance_mode => :keep]
300
+ end
301
+ end
302
+ options = Kernel.validate_options options,
303
+ inheritance_mode: :expand
304
+ inheritance_mode = options[:inheritance_mode]
239
305
 
240
- # Returns an environment variable value
241
- #
242
- # @param [String] name the environment variable name
243
- # @option options [Symbol] inheritance_mode (:expand) controls how
244
- # environment variable inheritance should be done. If :expand, the current
245
- # envvar value is inserted in the generated value. If :keep, the name of
246
- # the envvar is inserted (as e.g. $NAME). If :ignore, inheritance is
247
- # disabled in the generated value. Not that this applies only for the
248
- # environment variables for which inheritance has been enabled with
249
- # #env_inherit, other variables always behave as if :ignore was selected.
250
- # @return [nil,Array<String>] either nil if this environment variable is not
251
- # set, or an array of values. How the values should be joined to form the
252
- # actual value is OS-specific, and not handled by this method
253
- def self.env_value(name, options = Hash.new)
254
- # For backward compatibility only
255
- if !options.respond_to?(:to_hash)
256
- if options
257
- options = Hash[:inheritance_mode => :expand]
306
+ if !environment[name] && !inherited_environment[name] && !system_env[name]
307
+ nil
258
308
  else
259
- options = Hash[:inheritance_mode => :keep]
260
- end
261
- end
262
- options = Kernel.validate_options options,
263
- inheritance_mode: :expand
264
- inheritance_mode = options[:inheritance_mode]
265
-
266
- if !environment[name] && !inherited_environment[name] && !SYSTEM_ENV[name]
267
- nil
268
- else
269
- inherited =
270
- if inheritance_mode == :expand
271
- inherited_environment[name] || []
272
- elsif inheritance_mode == :keep && env_inherit?(name)
273
- ["$#{name}"]
274
- else []
275
- end
309
+ inherited =
310
+ if inheritance_mode == :expand
311
+ inherited_environment[name] || []
312
+ elsif inheritance_mode == :keep && inherit?(name)
313
+ ["$#{name}"]
314
+ else []
315
+ end
276
316
 
277
317
 
278
- value = []
279
- [environment[name], inherited, SYSTEM_ENV[name]].each do |paths|
280
- (paths || []).each do |p|
281
- if !value.include?(p)
282
- value << p
318
+ value = []
319
+ [environment[name], inherited, system_env[name]].each do |paths|
320
+ (paths || []).each do |p|
321
+ if !value.include?(p)
322
+ value << p
323
+ end
283
324
  end
284
325
  end
326
+ value
285
327
  end
286
- value
287
- end
288
- end
289
-
290
- def self.env_update_var(name)
291
- if value = env_value(name)
292
- ENV[name] = value.join(File::PATH_SEPARATOR)
293
- else
294
- ENV.delete(name)
295
328
  end
296
- end
297
-
298
- def self.env_add_path(name, *paths)
299
- oldpath = (environment[name] ||= Array.new)
300
- paths.reverse.each do |path|
301
- next if oldpath.include?(path)
302
329
 
303
- env_add(name, path)
304
- oldpath << path
305
- if name == 'RUBYLIB'
306
- $LOAD_PATH.unshift path
330
+ def update_var(name)
331
+ if value = value(name)
332
+ resolved_env[name] = value.join(File::PATH_SEPARATOR)
333
+ else
334
+ resolved_env.delete(name)
307
335
  end
308
336
  end
309
- end
310
337
 
311
- def self.env_remove_path(name, *paths)
312
- paths.each do |p|
313
- environment[name].delete(p)
338
+ def set_path(name, *paths)
339
+ clear(name)
340
+ add_path(name, *paths)
314
341
  end
315
- env_update_var(name)
316
- end
317
342
 
318
- def self.env_push_path(name, *values)
319
- if current = environment.delete(name)
320
- current = current.dup
321
- env_add_path(name, *values)
322
- env_add_path(name, *current)
323
- else
324
- env_add_path(name, *values)
325
- end
326
- end
343
+ def add_path(name, *paths)
344
+ paths = paths.map { |p| expand(p) }
327
345
 
328
- # Require that generated environment variable scripts source the given shell
329
- # script
330
- def self.env_source_file(file)
331
- env_source_after(file)
332
- end
333
-
334
- # @overload env_source_before
335
- # List of scripts that should be sourced at the top of env.sh
336
- #
337
- # @return [Array<String>] a list of paths that should be sourced at the
338
- # beginning of the shell script generated by {export_env_sh}
339
- #
340
- # @overload env_source_before(path)
341
- # @param [String] path a path that should be added to env_source_before
342
- #
343
- def self.env_source_before(file = nil)
344
- if file
345
- @env_source_before << file
346
- end
347
- end
346
+ oldpath = (environment[name] ||= Array.new)
347
+ paths.reverse.each do |path|
348
+ path = path.to_str
349
+ next if oldpath.include?(path)
348
350
 
349
- # @overload env_source_after
350
- # List of scripts that should be sourced at the end of env.sh
351
- #
352
- # @return [Array<String>] a list of paths that should be sourced at the
353
- # end of the shell script generated by {export_env_sh}
354
- #
355
- # @overload env_source_after(path)
356
- # @param [String] path a path that should be added to env_source_after
357
- #
358
- def self.env_source_after(file = nil)
359
- if file
360
- @env_source_after << file
351
+ add(name, path)
352
+ oldpath << path
353
+ if name == 'RUBYLIB'
354
+ $LOAD_PATH.unshift path
355
+ end
356
+ end
361
357
  end
362
- end
363
358
 
364
- # Generates a shell script that sets the environment variable listed in
365
- # Autobuild.environment, following the inheritance setting listed in
366
- # Autobuild.inherited_environment.
367
- #
368
- # It also sources the files added by Autobuild.env_source_file
369
- def self.export_env_sh(io)
370
- @env_source_before.each do |path|
371
- io.puts SHELL_SOURCE_SCRIPT % path
359
+ def remove_path(name, *paths)
360
+ paths.each do |p|
361
+ environment[name].delete(p)
362
+ end
363
+ update_var(name)
372
364
  end
373
365
 
374
- variables = []
375
- Autobuild.environment.each do |name, _|
376
- variables << name
377
- value_with_inheritance = env_value(name, inheritance_mode: :keep)
378
- value_without_inheritance = env_value(name, inheritance_mode: :ignore)
379
-
380
- if !value_with_inheritance
381
- shell_line = SHELL_UNSET_COMMAND % [name]
382
- elsif value_with_inheritance == value_without_inheritance # no inheritance
383
- shell_line = SHELL_SET_COMMAND % [name, value_with_inheritance.join(File::PATH_SEPARATOR)]
366
+ def push_path(name, *values)
367
+ if current = environment.delete(name)
368
+ current = current.dup
369
+ add_path(name, *values)
370
+ add_path(name, *current)
384
371
  else
385
- shell_line = SHELL_CONDITIONAL_SET_COMMAND % [name, value_with_inheritance.join(File::PATH_SEPARATOR), value_without_inheritance.join(File::PATH_SEPARATOR)]
372
+ add_path(name, *values)
386
373
  end
387
- io.puts shell_line
388
374
  end
389
- variables.each do |var|
390
- io.puts SHELL_EXPORT_COMMAND % [var]
391
- end
392
- @env_source_after.each do |path|
393
- io.puts SHELL_SOURCE_SCRIPT % [path]
375
+
376
+ # @overload source_before
377
+ # List of scripts that should be sourced at the top of env.sh
378
+ #
379
+ # @return [Array<String>] a list of paths that should be sourced at the
380
+ # beginning of the shell script generated by {export_env_sh}
381
+ #
382
+ # @overload source_before(path)
383
+ # @param [String] path a path that should be added to source_before
384
+ #
385
+ def source_before(file = nil)
386
+ if file
387
+ @source_before << file
388
+ end
394
389
  end
395
- end
396
390
 
397
- # DEPRECATED: use env_add_path instead
398
- def self.pathvar(path, varname)
399
- if File.directory?(path)
400
- if block_given?
401
- return unless yield(path)
391
+ # @overload source_after
392
+ # List of scripts that should be sourced at the end of env.sh
393
+ #
394
+ # @return [Array<String>] a list of paths that should be sourced at the
395
+ # end of the shell script generated by {export_env_sh}
396
+ #
397
+ # @overload source_after(path)
398
+ # @param [String] path a path that should be added to source_after
399
+ #
400
+ def source_after(file = nil)
401
+ if file
402
+ @source_after << file
402
403
  end
403
- env_add_path(varname, path)
404
404
  end
405
- end
406
405
 
407
- def self.each_env_search_path(prefix, patterns)
408
- arch_names = self.arch_names
409
- arch_size = self.arch_size
410
-
411
- seen = Set.new
412
- patterns.each do |base_path|
413
- paths = []
414
- if base_path =~ /ARCHSIZE/
415
- base_path = base_path.gsub('ARCHSIZE', arch_size.to_s)
416
- end
417
- if base_path =~ /ARCH/
418
- arch_names.each do |arch|
419
- paths << base_path.gsub('ARCH', arch)
406
+ # Generates a shell script that sets the environment variable listed in
407
+ # Autobuild.environment, following the inheritance setting listed in
408
+ # Autobuild.inherited_environment.
409
+ #
410
+ # It also sources the files added by source_file
411
+ def export_env_sh(io)
412
+ @source_before.each do |path|
413
+ io.puts SHELL_SOURCE_SCRIPT % path
414
+ end
415
+
416
+ variables = []
417
+ environment.each do |name, _|
418
+ variables << name
419
+ value_with_inheritance = value(name, inheritance_mode: :keep)
420
+ value_without_inheritance = value(name, inheritance_mode: :ignore)
421
+
422
+ if !value_with_inheritance
423
+ shell_line = SHELL_UNSET_COMMAND % [name]
424
+ elsif value_with_inheritance == value_without_inheritance # no inheritance
425
+ shell_line = SHELL_SET_COMMAND % [name, value_with_inheritance.join(File::PATH_SEPARATOR)]
426
+ else
427
+ shell_line = SHELL_CONDITIONAL_SET_COMMAND % [name, value_with_inheritance.join(File::PATH_SEPARATOR), value_without_inheritance.join(File::PATH_SEPARATOR)]
420
428
  end
421
- else
422
- paths << base_path
429
+ io.puts shell_line
423
430
  end
424
- paths.each do |p|
425
- p = File.join(prefix, *p.split('/'))
426
- if !seen.include?(p) && File.directory?(p)
427
- yield(p)
428
- seen << p
431
+ variables.each do |var|
432
+ io.puts SHELL_EXPORT_COMMAND % [var]
433
+ end
434
+ @source_after.each do |path|
435
+ io.puts SHELL_SOURCE_SCRIPT % [path]
436
+ end
437
+ end
438
+
439
+ # DEPRECATED: use add_path instead
440
+ def self.pathvar(path, varname)
441
+ if File.directory?(path)
442
+ if block_given?
443
+ return unless yield(path)
429
444
  end
445
+ add_path(varname, path)
430
446
  end
431
447
  end
432
- end
433
448
 
434
- def self.arch_size
435
- if @arch_size
436
- return @arch_size
449
+ def each_env_search_path(prefix, patterns)
450
+ arch_names = self.arch_names
451
+ arch_size = self.arch_size
452
+
453
+ seen = Set.new
454
+ patterns.each do |base_path|
455
+ paths = []
456
+ if base_path =~ /ARCHSIZE/
457
+ base_path = base_path.gsub('ARCHSIZE', arch_size.to_s)
458
+ end
459
+ if base_path =~ /ARCH/
460
+ arch_names.each do |arch|
461
+ paths << base_path.gsub('ARCH', arch)
462
+ end
463
+ else
464
+ paths << base_path
465
+ end
466
+ paths.each do |p|
467
+ p = File.join(prefix, *p.split('/'))
468
+ if !seen.include?(p) && File.directory?(p)
469
+ yield(p)
470
+ seen << p
471
+ end
472
+ end
473
+ end
437
474
  end
438
475
 
439
- @arch_size =
440
- if RbConfig::CONFIG['host_cpu'] =~ /64/
441
- 64
442
- else 32
476
+ def arch_size
477
+ if @arch_size
478
+ return @arch_size
443
479
  end
444
- end
445
480
 
446
- def self.arch_names
447
- if @arch_names
448
- return @arch_names
449
- end
481
+ if File.file?('/usr/bin/dpkg-architecture')
482
+ cmdline = ['/usr/bin/dpkg-architecture']
483
+ if target_arch
484
+ cmdline << "-T" << target_arch
485
+ end
486
+ arch = `#{cmdline.join(" ")}`.split.grep(/DEB_TARGET_ARCH_BITS/).first
487
+ if arch
488
+ @arch_size = Integer(arch.chomp.split('=').last)
489
+ end
490
+ end
450
491
 
451
- result = Set.new
452
- if File.file?('/usr/bin/dpkg-architecture')
453
- arch = `/usr/bin/dpkg-architecture`.split.grep(/DEB_BUILD_MULTIARCH/).first
454
- if arch
455
- result << arch.chomp.split('=').last
492
+ if !@arch_size
493
+ @arch_size =
494
+ if RbConfig::CONFIG['host_cpu'] =~ /64/
495
+ 64
496
+ else 32
497
+ end
456
498
  end
499
+ @arch_size
457
500
  end
458
- @arch_names = result
459
- end
460
501
 
461
- # Updates the environment when a new prefix has been added
462
- def self.update_environment(newprefix, includes = nil)
463
- if !includes || includes.include?('PATH')
464
- if File.directory?("#{newprefix}/bin")
465
- env_add_path('PATH', "#{newprefix}/bin")
466
- end
502
+ def target_arch=(archname)
503
+ @target_arch = archname
504
+ @arch_size, @arch_names = nil
467
505
  end
468
506
 
469
- if !includes || includes.include?('PKG_CONFIG_PATH')
470
- pkg_config_search = ['lib/pkgconfig', 'lib/ARCH/pkgconfig', 'libARCHSIZE/pkgconfig']
471
- each_env_search_path(newprefix, pkg_config_search) do |path|
472
- env_add_path('PKG_CONFIG_PATH', path)
473
- end
507
+ def target_arch
508
+ @target_arch
474
509
  end
475
510
 
476
- if !includes || includes.include?(LIBRARY_PATH)
477
- ld_library_search = ['lib', 'lib/ARCH', 'libARCHSIZE']
478
- each_env_search_path(newprefix, ld_library_search) do |path|
479
- if !Dir.glob(File.join(path, "lib*.#{LIBRARY_SUFFIX}")).empty?
480
- env_add_path(LIBRARY_PATH, path)
511
+ def arch_names
512
+ if @arch_names
513
+ return @arch_names
514
+ end
515
+
516
+ result = Set.new
517
+ if File.file?('/usr/bin/dpkg-architecture')
518
+ cmdline = ['/usr/bin/dpkg-architecture']
519
+ if target_arch
520
+ cmdline << "-T" << target_arch
521
+ end
522
+ arch = `#{cmdline.join(" ")}`.split.grep(/DEB_TARGET_MULTIARCH/).first
523
+ if arch
524
+ result << arch.chomp.split('=').last
481
525
  end
482
526
  end
527
+ @arch_names = result
483
528
  end
484
529
 
485
- # Validate the new rubylib path
486
- if !includes || includes.include?('RUBYLIB')
487
- new_rubylib = "#{newprefix}/lib"
488
- if File.directory?(new_rubylib) && !File.directory?(File.join(new_rubylib, "ruby")) && !Dir["#{new_rubylib}/**/*.rb"].empty?
489
- env_add_path('RUBYLIB', new_rubylib)
530
+ def update_environment(newprefix, includes = nil)
531
+ add_prefix(newprefix, includes)
532
+ end
533
+
534
+ # Updates the environment when a new prefix has been added
535
+ def add_prefix(newprefix, includes = nil)
536
+ if !includes || includes.include?('PATH')
537
+ if File.directory?("#{newprefix}/bin")
538
+ add_path('PATH', "#{newprefix}/bin")
539
+ end
540
+ end
541
+
542
+ if !includes || includes.include?('PKG_CONFIG_PATH')
543
+ pkg_config_search = ['lib/pkgconfig', 'lib/ARCH/pkgconfig', 'libARCHSIZE/pkgconfig']
544
+ each_env_search_path(newprefix, pkg_config_search) do |path|
545
+ add_path('PKG_CONFIG_PATH', path)
546
+ end
490
547
  end
491
548
 
492
- require 'rbconfig'
493
- %w{rubylibdir archdir sitelibdir sitearchdir vendorlibdir vendorarchdir}.
494
- map { |key| RbConfig::CONFIG[key] }.
495
- map { |path| path.gsub(/.*lib(?:32|64)?\//, '\\1') }.
496
- each do |subdir|
497
- if File.directory?("#{newprefix}/lib/#{subdir}")
498
- env_add_path("RUBYLIB", "#{newprefix}/lib/#{subdir}")
549
+ if !includes || includes.include?(LIBRARY_PATH)
550
+ ld_library_search = ['lib', 'lib/ARCH', 'libARCHSIZE']
551
+ each_env_search_path(newprefix, ld_library_search) do |path|
552
+ if !Dir.glob(File.join(path, "lib*.#{LIBRARY_SUFFIX}")).empty?
553
+ add_path(LIBRARY_PATH, path)
499
554
  end
500
555
  end
556
+ end
557
+
558
+ # Validate the new rubylib path
559
+ if !includes || includes.include?('RUBYLIB')
560
+ new_rubylib = "#{newprefix}/lib"
561
+ if File.directory?(new_rubylib) && !File.directory?(File.join(new_rubylib, "ruby")) && !Dir["#{new_rubylib}/**/*.rb"].empty?
562
+ add_path('RUBYLIB', new_rubylib)
563
+ end
564
+
565
+ require 'rbconfig'
566
+ %w{rubylibdir archdir sitelibdir sitearchdir vendorlibdir vendorarchdir}.
567
+ map { |key| RbConfig::CONFIG[key] }.
568
+ map { |path| path.gsub(/.*lib(?:32|64)?\//, '\\1') }.
569
+ each do |subdir|
570
+ if File.directory?("#{newprefix}/lib/#{subdir}")
571
+ add_path("RUBYLIB", "#{newprefix}/lib/#{subdir}")
572
+ end
573
+ end
574
+ end
575
+ end
576
+
577
+ def isolate
578
+ self.inherit = false
579
+ push_path 'PATH', '/usr/local/bin', '/usr/bin', '/bin'
580
+ end
581
+
582
+ def prepare
583
+ # Set up some important autobuild parameters
584
+ inherit 'PATH', 'PKG_CONFIG_PATH', 'RUBYLIB', \
585
+ 'LD_LIBRARY_PATH', 'CMAKE_PREFIX_PATH', 'PYTHONPATH'
586
+ end
587
+
588
+ # Method called to filter the environment variables before they are set,
589
+ # for instance to expand variables
590
+ def expand(value)
591
+ value
501
592
  end
502
593
  end
594
+
595
+ def self.env=(env)
596
+ @env = env
597
+ end
598
+
599
+ def self.env
600
+ if !@env
601
+ @env = Environment.new
602
+ @env.prepare
603
+ end
604
+ @env
605
+ end
606
+
607
+ # @deprecated, use the API on {env} instead
608
+ def self.env_reset(name = nil)
609
+ env.reset(name)
610
+ end
611
+ # @deprecated, use the API on {env} instead
612
+ def self.env_clear(name = nil)
613
+ env.clear(name)
614
+ end
615
+ # @deprecated, use the API on {env} instead
616
+ def self.env_set(name, *values)
617
+ env.set(name, *values)
618
+ end
619
+ # @deprecated, use the API on {env} instead
620
+ def self.env_inherit?(name = nil)
621
+ env.inherit?(name)
622
+ end
623
+ # @deprecated, use the API on {env} instead
624
+ def self.env_inherit=(value)
625
+ env.inherit = value
626
+ end
627
+ # @deprecated, use the API on {env} instead
628
+ def self.env_inherit(*names)
629
+ env.inherit(*names)
630
+ end
631
+ # @deprecated, use the API on {env} instead
632
+ def self.env_init_from_env(name)
633
+ env.init_from_env(name)
634
+ end
635
+ # @deprecated, use the API on {env} instead
636
+ def self.env_push(name, *values)
637
+ env.push(name, *values)
638
+ end
639
+ # @deprecated, use the API on {env} instead
640
+ def self.env_add(name, *values)
641
+ env.add(name, *values)
642
+ end
643
+ # @deprecated, use the API on {env} instead
644
+ def self.env_value(name, options = Hash.new)
645
+ env.value(name, options)
646
+ end
647
+ # @deprecated, use the API on {env} instead
648
+ def self.env_update_var(name)
649
+ env.update_var(name)
650
+ end
651
+ # @deprecated, use the API on {env} instead
652
+ def self.env_add_path(name, *paths)
653
+ env.add_path(name, *paths)
654
+ end
655
+ # @deprecated, use the API on {env} instead
656
+ def self.env_remove_path(name, *paths)
657
+ env.remove_path(name, *paths)
658
+ end
659
+ # @deprecated, use the API on {env} instead
660
+ def self.env_push_path(name, *values)
661
+ env.push_path(name, *values)
662
+ end
663
+ # @deprecated, use the API on {env} instead
664
+ def self.env_source_file(file)
665
+ env.source_after(file)
666
+ end
667
+ # @deprecated, use the API on {env} instead
668
+ def self.env_source_before(file = nil)
669
+ env.source_before(file)
670
+ end
671
+ # @deprecated, use the API on {env} instead
672
+ def self.env_source_after(file = nil)
673
+ env.source_after(file)
674
+ end
675
+ # @deprecated, use the API on {env} instead
676
+ def self.export_env_sh(io)
677
+ env.export_env_sh(io)
678
+ end
679
+ # @deprecated, use the API on {env} instead
680
+ def self.each_env_search_path(prefix, patterns)
681
+ env.each_env_search_path(prefix, patterns)
682
+ end
683
+ # @deprecated, use the API on {env} instead
684
+ def self.update_environment(newprefix, includes = nil)
685
+ env.update_environment(newprefix, includes)
686
+ end
687
+
688
+ # @deprecated use {Env#add_path} on {.env} instead
689
+ def self.pathvar(path, varname)
690
+ if File.directory?(path)
691
+ if block_given?
692
+ return unless yield(path)
693
+ end
694
+ env.add_path(varname, path)
695
+ end
696
+ end
697
+
698
+ def self.arch_size
699
+ Autobuild.warn 'Autobuild.arch_size is deprecated, use Autobuild.env.arch_size instead'
700
+ env.arch_size
701
+ end
702
+
703
+ def self.arch_names
704
+ Autobuild.warn 'Autobuild.arch_names is deprecated, use Autobuild.env.arch_names instead'
705
+ env.arch_names
706
+ end
503
707
  end
504
708