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 +4 -4
- data/.gemtest +0 -0
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/autobuild.rb +1 -8
- data/lib/autobuild/configurable.rb +0 -1
- data/lib/autobuild/environment.rb +552 -348
- data/lib/autobuild/import/archive.rb +6 -8
- data/lib/autobuild/import/git.rb +24 -2
- data/lib/autobuild/importer.rb +7 -5
- data/lib/autobuild/mail_reporter.rb +107 -0
- data/lib/autobuild/package.rb +156 -50
- data/lib/autobuild/packages/autotools.rb +8 -8
- data/lib/autobuild/packages/cmake.rb +10 -10
- data/lib/autobuild/packages/genom.rb +2 -2
- data/lib/autobuild/packages/gnumake.rb +1 -1
- data/lib/autobuild/packages/orogen.rb +3 -8
- data/lib/autobuild/packages/ruby.rb +6 -14
- data/lib/autobuild/reporting.rb +1 -98
- data/lib/autobuild/subcommand.rb +23 -4
- data/lib/autobuild/version.rb +1 -1
- data/test/import/test_tar.rb +0 -19
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42c625c20b8bfbb4fc824fc40a9b2a41f5d6bb6
|
4
|
+
data.tar.gz: c35720c6c894d3fb3337bafb17424b72c9b1e9e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 728e7d5f5a968767e5d5bea8368bfda85c2601b6d66647f8d2f52ae7fe26019f1ef361ce3b0d9cf43b49e4ee71eb6c794c7b146eeb72c01543b495f83caefa2a
|
7
|
+
data.tar.gz: bc5181729cf2196ab580d175efcf411e0a79f9d3abc02e06280dda2bc15f595e0e8fa40b54cdcba1c11b6cec38ed316067f5de30d642049fdfb82785814ae340
|
data/.gemtest
ADDED
File without changes
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
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
|
-
|
18
|
+
@freebsd
|
23
19
|
end
|
24
20
|
|
25
21
|
def self.bsd?
|
26
|
-
|
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
|
73
|
-
|
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
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
environment.
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
198
|
-
|
235
|
+
@inherit
|
236
|
+
end
|
199
237
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
220
|
-
|
221
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
261
|
+
set = if environment.has_key?(name)
|
262
|
+
environment[name]
|
263
|
+
end
|
228
264
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
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
|
-
|
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
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
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
|
-
|
312
|
-
|
313
|
-
|
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
|
-
|
319
|
-
|
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
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
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
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
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
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
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
|
-
|
372
|
+
add_path(name, *values)
|
386
373
|
end
|
387
|
-
io.puts shell_line
|
388
374
|
end
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
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
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
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
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
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
|
-
|
422
|
-
paths << base_path
|
429
|
+
io.puts shell_line
|
423
430
|
end
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
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
|
-
|
435
|
-
|
436
|
-
|
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
|
-
|
440
|
-
if
|
441
|
-
|
442
|
-
else 32
|
476
|
+
def arch_size
|
477
|
+
if @arch_size
|
478
|
+
return @arch_size
|
443
479
|
end
|
444
|
-
end
|
445
480
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
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
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
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
|
-
|
462
|
-
|
463
|
-
|
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
|
-
|
470
|
-
|
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
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
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
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
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
|
|