View | Details | Raw Unified | Return to bug 2975
Collapse All | Expand All

(-)a/bake/ModuleEnvironment.py (-115 / +113 lines)
 Lines 1-10    Link Here 
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2013 INRIA
2
# Copyright (c) 2013 INRIA
3
# 
3
#
4
# This program is free software; you can redistribute it and/or modify
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License version 2 as
5
# it under the terms of the GNU General Public License version 2 as
6
# published by the Free Software Foundation;
6
# published by the Free Software Foundation;
7
# 
7
#
8
# This program is distributed in the hope that it will be useful,
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 Lines 17-40    Link Here 
17
# Authors: Daniel Camara  <daniel.camara@inria.fr>
17
# Authors: Daniel Camara  <daniel.camara@inria.fr>
18
#          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
#          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
###############################################################################
19
###############################################################################
20
''' 
20
'''
21
 ModuleEnvironment.py
21
 ModuleEnvironment.py
22
 
22
23
 This file stores the class Module Environment responsible for the interaction
23
 This file stores the class Module Environment responsible for the interaction
24
 between Bake and the execution of third party softwares and the operating 
24
 between Bake and the execution of third party softwares and the operating
25
 system.  
25
 system.
26
''' 
26
'''
27
27
28
import os
28
import os
29
import subprocess
29
import subprocess
30
import sys
30
import sys
31
import platform
31
import platform
32
32
33
from bake.Exceptions import TaskError 
33
from bake.Exceptions import TaskError
34
from bake.Utils import ColorTool
34
from bake.Utils import ColorTool
35
35
36
class ModuleEnvironment:
36
class ModuleEnvironment:
37
    ''' Main class to interact with the host system to execute the external 
37
    ''' Main class to interact with the host system to execute the external
38
    tools.
38
    tools.
39
    '''
39
    '''
40
    _stopOnError = False
40
    _stopOnError = False
 Lines 42-53    Link Here 
42
    _binpaths = set([])
42
    _binpaths = set([])
43
    _pkgpaths =  set([])
43
    _pkgpaths =  set([])
44
    _variables =  set([])
44
    _variables =  set([])
45
     
45
46
    (HIGHER, LOWER, EQUAL) = range(0,3)
46
    (HIGHER, LOWER, EQUAL) = range(0,3)
47
47
48
    def __init__(self, logger, installdir, sourcedir, objdir, debug=False):
48
    def __init__(self, logger, installdir, sourcedir, objdir, debug=False):
49
        ''' Internal variables initialization.'''
49
        ''' Internal variables initialization.'''
50
        
50
51
        self._logger = logger
51
        self._logger = logger
52
        self._installdir = installdir
52
        self._installdir = installdir
53
        self._sourcedir = sourcedir
53
        self._sourcedir = sourcedir
 Lines 72-146    Link Here 
72
    @property
72
    @property
73
    def installdir(self):
73
    def installdir(self):
74
        ''' Returns the name of the set installation directory.'''
74
        ''' Returns the name of the set installation directory.'''
75
        
75
76
        return self._installdir
76
        return self._installdir
77
    
77
78
    @property
78
    @property
79
    def debug(self):
79
    def debug(self):
80
        ''' Returns if this execution was set to show the debug messages or not.'''
80
        ''' Returns if this execution was set to show the debug messages or not.'''
81
81
82
        return self._debug
82
        return self._debug
83
    
83
84
    @property
84
    @property
85
    def srcdir(self):
85
    def srcdir(self):
86
        ''' Returns the directory where Bake stores the source of the present 
86
        ''' Returns the directory where Bake stores the source of the present
87
        module.
87
        module.
88
        '''
88
        '''
89
        
89
90
        try:
90
        try:
91
            return os.path.join(self._sourcedir, self._module_directory())
91
            return os.path.join(self._sourcedir, self._module_directory())
92
        except AttributeError as e:
92
        except AttributeError as e:
93
            raise TaskError('Missing configuration: sourcedir= %s, ' 
93
            raise TaskError('Missing configuration: sourcedir= %s, '
94
                            'module_directory= %s, Error: %s' 
94
                            'module_directory= %s, Error: %s'
95
                            % (self._sourcedir,self._module_directory(), e))
95
                            % (self._sourcedir,self._module_directory(), e))
96
        
96
97
    @property
97
    @property
98
    def srcrepo(self):
98
    def srcrepo(self):
99
        ''' The root of the source repository, where all the sources for all 
99
        ''' The root of the source repository, where all the sources for all
100
        the modules will be stored.
100
        the modules will be stored.
101
        '''
101
        '''
102
        
102
103
        return self._sourcedir
103
        return self._sourcedir
104
    
104
105
    @property
105
    @property
106
    def objdir(self):
106
    def objdir(self):
107
        ''' Returns the directory where Bake stores the object code of the  
107
        ''' Returns the directory where Bake stores the object code of the
108
        present module.
108
        present module.
109
        '''
109
        '''
110
        
110
111
        if not self._module_supports_objdir:
111
        if not self._module_supports_objdir:
112
            obj = self.srcdir
112
            obj = self.srcdir
113
        else:
113
        else:
114
            try:
114
            try:
115
                obj = os.path.join(self.srcdir, self._objdir)
115
                obj = os.path.join(self.srcdir, self._objdir)
116
            except AttributeError as e:
116
            except AttributeError as e:
117
                raise TaskError('Missing configuration: sourcedir= %s, '  
117
                raise TaskError('Missing configuration: sourcedir= %s, '
118
                                'objdir= %s, Error: %s' 
118
                                'objdir= %s, Error: %s'
119
                                % (self._sourcedir, self._module_directory(), e))
119
                                % (self._sourcedir, self._module_directory(), e))
120
        return obj
120
        return obj
121
121
122
    @property
122
    @property
123
    def sudoEnabled(self):
123
    def sudoEnabled(self):
124
        ''' Returns the setting of the --sudo option'''
124
        ''' Returns the setting of the --sudo option'''
125
        
125
126
        return self._sudoEnabled
126
        return self._sudoEnabled
127
127
128
    @property
128
    @property
129
    def stopOnErrorEnabled(self):
129
    def stopOnErrorEnabled(self):
130
        ''' Returns the setting of the --stop_on_error option'''
130
        ''' Returns the setting of the --stop_on_error option'''
131
        
131
132
        return ModuleEnvironment._stopOnError
132
        return ModuleEnvironment._stopOnError
133
133
134
    def _pkgconfig_var(self):
134
    def _pkgconfig_var(self):
135
        ''' Returns the PKG_CONFIG_PATH configured environment variable.'''
135
        ''' Returns the PKG_CONFIG_PATH configured environment variable.'''
136
136
137
        return 'PKG_CONFIG_PATH'
137
        return 'PKG_CONFIG_PATH'
138
    
138
139
    def _pkgconfig_path(self):
139
    def _pkgconfig_path(self):
140
        ''' Returns the PKG_CONFIG_PATH configured path. '''
140
        ''' Returns the PKG_CONFIG_PATH configured path. '''
141
        
141
142
        return os.path.join(self._lib_path(), 'pkgconfig')
142
        return os.path.join(self._lib_path(), 'pkgconfig')
143
    
143
144
    def _lib_var(self):
144
    def _lib_var(self):
145
        ''' Returns the value of the system configured library path.'''
145
        ''' Returns the value of the system configured library path.'''
146
146
 Lines 149-184    Link Here 
149
                    'Darwin' : 'DYLD_LIBRARY_PATH',
149
                    'Darwin' : 'DYLD_LIBRARY_PATH',
150
                    'Windows' : 'PATH'}
150
                    'Windows' : 'PATH'}
151
        if not platform.system() in lib_var:
151
        if not platform.system() in lib_var:
152
            sys.stderr('Error: Unsupported platform. Send email to ' 
152
            sys.stderr('Error: Unsupported platform. Send email to '
153
                       'bake_support@inria.fr (%s)' % platform.system())
153
                       'bake_support@inria.fr (%s)' % platform.system())
154
            sys.exit(1)
154
            sys.exit(1)
155
        return lib_var[platform.system()]
155
        return lib_var[platform.system()]
156
    
156
157
    def _lib_path(self):
157
    def _lib_path(self):
158
        ''' Returns the value of the library path for the in-use module.'''
158
        ''' Returns the value of the library path for the in-use module.'''
159
        
159
160
        return os.path.join(self._installdir, 'lib')
160
        return os.path.join(self._installdir, 'lib')
161
    
161
162
    def _bin_var(self):
162
    def _bin_var(self):
163
        return 'PATH'
163
        return 'PATH'
164
    def _bin_path(self):
164
    def _bin_path(self):
165
        ''' Returns the value of the binary path for the in-use module.'''
165
        ''' Returns the value of the binary path for the in-use module.'''
166
        
166
167
        return os.path.join(self._installdir, 'bin')
167
        return os.path.join(self._installdir, 'bin')
168
    
168
169
    def _py_var(self):
169
    def _py_var(self):
170
        return 'PYTHONPATH'
170
        return 'PYTHONPATH'
171
    def _py_path(self):
171
    def _py_path(self):
172
        ''' Returns the value of the python path for the in-use module.'''
172
        ''' Returns the value of the python path for the in-use module.'''
173
        
173
174
        return os.path.join(self._installdir, 'lib', 
174
        return os.path.join(self._installdir, 'lib',
175
                            'python'+platform.python_version_tuple()[0]+  
175
                            'python'+platform.python_version_tuple()[0]+
176
                            '.'+platform.python_version_tuple()[1], 
176
                            '.'+platform.python_version_tuple()[1],
177
                            'site-packages')
177
                            'site-packages')
178
        
178
179
    def _append_path(self, d, name, value, sep):
179
    def _append_path(self, d, name, value, sep):
180
        ''' Append the variable to the system in use configuration. '''
180
        ''' Append the variable to the system in use configuration. '''
181
        
181
182
        if not name in d:
182
        if not name in d:
183
            d[name] = value
183
            d[name] = value
184
        else:
184
        else:
 Lines 186-197    Link Here 
186
186
187
    def start_source(self, name, dir):
187
    def start_source(self, name, dir):
188
        ''' Sets the environment to be used by the given source module.'''
188
        ''' Sets the environment to be used by the given source module.'''
189
        
189
190
        assert self._module_supports_objdir is None
190
        assert self._module_supports_objdir is None
191
        self._module_name = name
191
        self._module_name = name
192
        self._module_dir = dir
192
        self._module_dir = dir
193
        self._logger.set_current_module(name)
193
        self._logger.set_current_module(name)
194
        
194
195
        # ensure source directory exists
195
        # ensure source directory exists
196
        if not os.path.isdir(self._sourcedir):
196
        if not os.path.isdir(self._sourcedir):
197
            os.makedirs(self._sourcedir)
197
            os.makedirs(self._sourcedir)
 Lines 200-213    Link Here 
200
        ''' Cleans the environment regarding the informations of the last used
200
        ''' Cleans the environment regarding the informations of the last used
201
        source module.
201
        source module.
202
        '''
202
        '''
203
        
203
204
        self._module_name = None
204
        self._module_name = None
205
        self._module_dir = None
205
        self._module_dir = None
206
        self._logger.clear_current_module()
206
        self._logger.clear_current_module()
207
207
208
    def start_build(self, name, dir, supports_objdir):
208
    def start_build(self, name, dir, supports_objdir):
209
        ''' Sets the environment to be used by the given build module.'''
209
        ''' Sets the environment to be used by the given build module.'''
210
        
210
211
#        assert self._module_supports_objdir is None
211
#        assert self._module_supports_objdir is None
212
        self._module_name = name
212
        self._module_name = name
213
        self._module_dir = dir
213
        self._module_dir = dir
 Lines 223-251    Link Here 
223
        ''' Cleans the environment regarding the informations of the last used
223
        ''' Cleans the environment regarding the informations of the last used
224
        build module.
224
        build module.
225
        '''
225
        '''
226
        
226
227
        self._module_name = None
227
        self._module_name = None
228
        self._module_dir = None
228
        self._module_dir = None
229
        self._module_supports_objdir = None
229
        self._module_supports_objdir = None
230
        self._logger.clear_current_module()
230
        self._logger.clear_current_module()
231
    
231
232
    def exist_file(self, file):
232
    def exist_file(self, file):
233
        ''' Finds if the file exists in the path.'''
233
        ''' Finds if the file exists in the path.'''
234
        
234
235
        return os.path.exists(file)
235
        return os.path.exists(file)
236
236
237
    def path_list(self):
237
    def path_list(self):
238
        ''' Return path that will be searched for executables '''
238
        ''' Return path that will be searched for executables '''
239
        pythonpath=[]
239
        pythonpath=[]
240
        
240
241
        if os.environ.get('PYTHONPATH'):
241
        if os.environ.get('PYTHONPATH'):
242
            pythonpath=os.environ.get('PYTHONPATH').split(os.pathsep)                
242
            pythonpath=os.environ.get('PYTHONPATH').split(os.pathsep)
243
        return os.environ.get('PATH').split(os.pathsep) + [self._bin_path()] + pythonpath
243
        return os.environ.get('PATH').split(os.pathsep) + [self._bin_path()] + pythonpath
244
244
245
    def _program_location(self, program):
245
    def _program_location(self, program):
246
        ''' Finds where the executable is located in the user's path.'''
246
        ''' Finds where the executable is located in the user's path.'''
247
        
247
248
        # function to verify if the program exists on the given path 
248
        # function to verify if the program exists on the given path
249
        # and if it is executable
249
        # and if it is executable
250
        def is_exe(path):
250
        def is_exe(path):
251
            return os.path.exists(path) and os.access(path, os.X_OK)
251
            return os.path.exists(path) and os.access(path, os.X_OK)
 Lines 260-272    Link Here 
260
                exe_file = os.path.join(path, program)
260
                exe_file = os.path.join(path, program)
261
                if is_exe(exe_file):
261
                if is_exe(exe_file):
262
                    return exe_file
262
                    return exe_file
263
                
263
264
            toFindIn=None 
264
            toFindIn=None
265
            # search for libs with that name on the library path
265
            # search for libs with that name on the library path
266
            index=program.find(".so") + program.find(".a")
266
            index=program.find(".so") + program.find(".a")
267
            if index>0 :
267
            if index>0 :
268
                toFindIn=['/usr/lib','/usr/lib64','/usr/lib32','/usr/local/lib',
268
                toFindIn=['/usr/lib','/usr/lib64','/usr/lib32','/usr/local/lib',
269
                     '/lib','/opt/local/lib','/opt/local/Library']
269
                     '/lib','/opt/local/lib','/opt/local/Library', '/usr/local/opt']
270
                for libpath in self._libpaths:
270
                for libpath in self._libpaths:
271
                    toFindIn.append(libpath)
271
                    toFindIn.append(libpath)
272
                stdLibs = []
272
                stdLibs = []
 Lines 276-290    Link Here 
276
                        stdLibs=libPath.split(os.pathsep)
276
                        stdLibs=libPath.split(os.pathsep)
277
                except:
277
                except:
278
                    pass
278
                    pass
279
                
279
280
                tofindIn=toFindIn+stdLibs+[self._lib_path()]
280
                tofindIn=toFindIn+stdLibs+[self._lib_path()]
281
281
282
            elif program.endswith(".h"):
282
            elif program.endswith(".h"):
283
                toFindIn=['/usr/include', '/usr/local/include', '/usr/lib','/opt/local/include']  
283
                toFindIn=['/usr/include', '/usr/local/include', '/usr/lib','/opt/local/include', '/usr/local/opt']
284
                 
284
285
            if toFindIn : 
285
            if toFindIn :
286
                for eachdir in toFindIn:
286
                for eachdir in toFindIn:
287
                    for dirname, dirnames, filenames in os.walk(eachdir):
287
                    for dirname, dirnames, filenames in os.walk(eachdir, True, None, True):
288
#                        print (dirname)
288
#                        print (dirname)
289
                    # print path to all filenames.
289
                    # print path to all filenames.
290
                        for filename in filenames:
290
                        for filename in filenames:
 Lines 294-310    Link Here 
294
#
294
#
295
#
295
#
296
#
296
#
297
#                for path in (stdLibs + tmp + 
297
#                for path in (stdLibs + tmp +
298
#                             [self._lib_path()]):
298
#                             [self._lib_path()]):
299
#                    lib_file = os.path.join(path, program)
299
#                    lib_file = os.path.join(path, program)
300
#                    if os.path.exists(lib_file):
300
#                    if os.path.exists(lib_file):
301
#                        return lib_file
301
#                        return lib_file
302
             
302
303
        return None
303
        return None
304
304
305
    def _check_version(self, found, required, match_type):
305
    def _check_version(self, found, required, match_type):
306
        ''' Checks the version of the required executable.'''
306
        ''' Checks the version of the required executable.'''
307
        
307
308
        smallerSize=min(len(found),len(required))
308
        smallerSize=min(len(found),len(required))
309
        if match_type == self.HIGHER:
309
        if match_type == self.HIGHER:
310
            for i in range(0,smallerSize):
310
            for i in range(0,smallerSize):
 Lines 324-330    Link Here 
324
                elif int(found[i]) < int(required[i]):
324
                elif int(found[i]) < int(required[i]):
325
                    return True
325
                    return True
326
            if len(found) >= len(required):
326
            if len(found) >= len(required):
327
                return False               
327
                return False
328
            return True
328
            return True
329
        elif match_type == self.EQUAL:
329
        elif match_type == self.EQUAL:
330
            if len(found) != len(required):
330
            if len(found) != len(required):
 Lines 337-378    Link Here 
337
            assert False
337
            assert False
338
338
339
    def add_libpaths(self, libpaths):
339
    def add_libpaths(self, libpaths):
340
        ''' Adds the list of paths to the in-use library path environment 
340
        ''' Adds the list of paths to the in-use library path environment
341
        variable.
341
        variable.
342
        '''
342
        '''
343
        
343
344
        for element in libpaths :
344
        for element in libpaths :
345
            self._libpaths.add(self.replace_variables(element))
345
            self._libpaths.add(self.replace_variables(element))
346
        
346
347
    def add_binpaths(self, libpaths):
347
    def add_binpaths(self, libpaths):
348
        ''' Adds the list of paths to the in-use binary path environment 
348
        ''' Adds the list of paths to the in-use binary path environment
349
        variable.
349
        variable.
350
        '''
350
        '''
351
        
351
352
        for element in libpaths :
352
        for element in libpaths :
353
            self._binpaths.add(self.replace_variables(element))
353
            self._binpaths.add(self.replace_variables(element))
354
        
354
355
    def add_pkgpaths(self, libpaths):
355
    def add_pkgpaths(self, libpaths):
356
        ''' Adds the list of paths to the in-use package path environment 
356
        ''' Adds the list of paths to the in-use package path environment
357
        variable.
357
        variable.
358
        '''
358
        '''
359
        
359
360
        for element in libpaths :
360
        for element in libpaths :
361
            self._pkgpaths.add(self.replace_variables(element))
361
            self._pkgpaths.add(self.replace_variables(element))
362
362
363
    def add_variables(self, libpaths):
363
    def add_variables(self, libpaths):
364
        ''' Adds/replace the list of variables to the in-use set of environment 
364
        ''' Adds/replace the list of variables to the in-use set of environment
365
        variables.
365
        variables.
366
        '''
366
        '''
367
        
367
368
        for element in libpaths :
368
        for element in libpaths :
369
            self._variables.add(self.replace_variables(element))
369
            self._variables.add(self.replace_variables(element))
370
            
370
371
    def create_environment_file(self, fileName):
371
    def create_environment_file(self, fileName):
372
        ''' Creates the set environment file to help users to call the Bake 
372
        ''' Creates the set environment file to help users to call the Bake
373
        built modules.
373
        built modules.
374
        '''
374
        '''
375
                
375
376
        script = "#!/bin/bash \n#### \n# Environment setting script. Automatically generated by Bake\n####\n\n"
376
        script = "#!/bin/bash \n#### \n# Environment setting script. Automatically generated by Bake\n####\n\n"
377
        script = script + "if [ \"${BASH_SOURCE:-}\" == \"${0}\" ]; then \n" + \
377
        script = script + "if [ \"${BASH_SOURCE:-}\" == \"${0}\" ]; then \n" + \
378
                 "    echo \"> Call with . bakeSetEnv.sh or source bakeSetEnv.sh\" \n" + \
378
                 "    echo \"> Call with . bakeSetEnv.sh or source bakeSetEnv.sh\" \n" + \
 Lines 381-393    Link Here 
381
381
382
        self._binpaths.add(self._bin_path())
382
        self._binpaths.add(self._bin_path())
383
        self._libpaths.add(self._lib_path())
383
        self._libpaths.add(self._lib_path())
384
        
384
385
        if len(self._libpaths) > 0:
385
        if len(self._libpaths) > 0:
386
            script = script + self.add_onPath("LD_LIBRARY_PATH", self._libpaths) + "\n"
386
            script = script + self.add_onPath("LD_LIBRARY_PATH", self._libpaths) + "\n"
387
            
387
388
        if len(self._binpaths) > 0:
388
        if len(self._binpaths) > 0:
389
            script = script + self.add_onPath("PATH", self._binpaths) + "\n"
389
            script = script + self.add_onPath("PATH", self._binpaths) + "\n"
390
            
390
391
        if len(self._pkgpaths) > 0:
391
        if len(self._pkgpaths) > 0:
392
            script = script + self.add_onPath("PKG_CONFIG_PATH", self._pkgpaths) + "\n"
392
            script = script + self.add_onPath("PKG_CONFIG_PATH", self._pkgpaths) + "\n"
393
393
 Lines 397-420    Link Here 
397
        if libDir:
397
        if libDir:
398
            begin=libDir.lower().index('python')
398
            begin=libDir.lower().index('python')
399
            localLibPath=os.path.join(self._lib_path(),libDir[begin:])
399
            localLibPath=os.path.join(self._lib_path(),libDir[begin:])
400
             
400
401
        
401
402
        script = script + self.add_onPath("PYTHONPATH", [sys.path[0],self._lib_path(),localLibPath]) + "\n"
402
        script = script + self.add_onPath("PYTHONPATH", [sys.path[0],self._lib_path(),localLibPath]) + "\n"
403
        
403
404
        for element in self._variables:
404
        for element in self._variables:
405
            script = script + " export " + element  + "\n"
405
            script = script + " export " + element  + "\n"
406
        
406
407
        fout = open(fileName, "w")
407
        fout = open(fileName, "w")
408
        fout.write(script)
408
        fout.write(script)
409
        fout.close()
409
        fout.close()
410
        os.chmod(fileName, 0o755)
410
        os.chmod(fileName, 0o755)
411
        
411
412
        return script
412
        return script
413
        
413
414
    def add_onPath (self, variableName, vectorPath):
414
    def add_onPath (self, variableName, vectorPath):
415
        ''' Format the variable to be added on the system.
415
        ''' Format the variable to be added on the system.
416
        '''
416
        '''
417
        
417
418
        returnString = " export " + variableName + "=\"${" + variableName + ":+${" + variableName + "}:}"
418
        returnString = " export " + variableName + "=\"${" + variableName + ":+${" + variableName + "}:}"
419
        for element in vectorPath:
419
        for element in vectorPath:
420
            returnString = returnString + element + ":"
420
            returnString = returnString + element + ":"
 Lines 426-435    Link Here 
426
        return returnString
426
        return returnString
427
427
428
    def replace_variables(self, string):
428
    def replace_variables(self, string):
429
        ''' Replace the variables on the string, if they exist, by their 
429
        ''' Replace the variables on the string, if they exist, by their
430
        system real values.
430
        system real values.
431
        '''
431
        '''
432
        
432
433
        import re
433
        import re
434
        tmp = string
434
        tmp = string
435
        tmp = re.sub('\$INSTALLDIR', self.installdir, tmp)
435
        tmp = re.sub('\$INSTALLDIR', self.installdir, tmp)
 Lines 440-459    Link Here 
440
    def check_program(self, program, version_arg = None,
440
    def check_program(self, program, version_arg = None,
441
                      version_regexp = None, version_required = None,
441
                      version_regexp = None, version_required = None,
442
                      match_type=HIGHER):
442
                      match_type=HIGHER):
443
        '''Checks if the program, with the desired version, exists in the 
443
        '''Checks if the program, with the desired version, exists in the
444
        system.
444
        system.
445
        '''
445
        '''
446
        
446
447
        if self._program_location(program) is None:
447
        if self._program_location(program) is None:
448
            return False
448
            return False
449
        if version_arg is None and version_regexp is None and version_required is None:
449
        if version_arg is None and version_regexp is None and version_required is None:
450
            return True
450
            return True
451
        else:
451
        else:
452
            # This assert as it was avoided the checking of the version of the 
452
            # This assert as it was avoided the checking of the version of the
453
            # executable assert not (version_arg is None or version_regexp is 
453
            # executable assert not (version_arg is None or version_regexp is
454
            # None or version_required is None)
454
            # None or version_required is None)
455
            assert not (version_arg is None and version_regexp is None and  version_required is None)
455
            assert not (version_arg is None and version_regexp is None and  version_required is None)
456
            popen = subprocess.Popen([self._program_location(program), 
456
            popen = subprocess.Popen([self._program_location(program),
457
                                        version_arg],
457
                                        version_arg],
458
                                     stdout = subprocess.PIPE,
458
                                     stdout = subprocess.PIPE,
459
                                     stderr = subprocess.STDOUT)
459
                                     stderr = subprocess.STDOUT)
 Lines 469-503    Link Here 
469
469
470
    def append_to_path(self, env_vars):
470
    def append_to_path(self, env_vars):
471
        """Sets the library and binary paths."""
471
        """Sets the library and binary paths."""
472
        
472
473
        for libpath in self._libpaths:
473
        for libpath in self._libpaths:
474
            self._append_path(env_vars, self._lib_var(), libpath, os.pathsep)
474
            self._append_path(env_vars, self._lib_var(), libpath, os.pathsep)
475
            if self.debug:
475
            if self.debug:
476
                print("  -> " + self._lib_var() + " " + libpath + " ")
476
                print("  -> " + self._lib_var() + " " + libpath + " ")
477
        
477
478
        self._append_path(env_vars, self._lib_var(), self._lib_path(), os.pathsep)
478
        self._append_path(env_vars, self._lib_var(), self._lib_path(), os.pathsep)
479
        for libpath in self._binpaths:
479
        for libpath in self._binpaths:
480
            self._append_path(env_vars, self._bin_var(), libpath, os.pathsep)
480
            self._append_path(env_vars, self._bin_var(), libpath, os.pathsep)
481
            if self.debug:
481
            if self.debug:
482
                print("  -> " + self._bin_var() + " " + libpath + " ")
482
                print("  -> " + self._bin_var() + " " + libpath + " ")
483
        
483
484
        self._append_path(env_vars, self._bin_var(), self._bin_path(), os.pathsep)
484
        self._append_path(env_vars, self._bin_var(), self._bin_path(), os.pathsep)
485
        for libpath in self._pkgpaths:
485
        for libpath in self._pkgpaths:
486
            self._append_path(env_vars, self._pkgconfig_var(), libpath, os.pathsep)
486
            self._append_path(env_vars, self._pkgconfig_var(), libpath, os.pathsep)
487
            if self.debug:
487
            if self.debug:
488
                print("  -> " + self._pkgconfig_var() + " " + libpath + " ")
488
                print("  -> " + self._pkgconfig_var() + " " + libpath + " ")
489
        
489
490
        self._append_path(env_vars, self._pkgconfig_var(), self._pkgconfig_path(), os.pathsep)
490
        self._append_path(env_vars, self._pkgconfig_var(), self._pkgconfig_path(), os.pathsep)
491
        self._append_path(env_vars, self._py_var(), self._py_path(), os.pathsep)
491
        self._append_path(env_vars, self._py_var(), self._py_path(), os.pathsep)
492
        self._append_path(env_vars, self._py_var(), os.path.join(self._installdir, 'lib'), os.pathsep)
492
        self._append_path(env_vars, self._py_var(), os.path.join(self._installdir, 'lib'), os.pathsep)
493
        
493
494
        return env_vars
494
        return env_vars
495
495
496
    def run(self, args, directory = None, env = dict(), interactive = False):
496
    def run(self, args, directory = None, env = dict(), interactive = False):
497
        '''Executes a system program adding the libraries and over the correct 
497
        '''Executes a system program adding the libraries and over the correct
498
        directories.
498
        directories.
499
        '''
499
        '''
500
        
500
501
        if not interactive:
501
        if not interactive:
502
            env_string = ''
502
            env_string = ''
503
            if len(env) != 0:
503
            if len(env) != 0:
 Lines 505-514    Link Here 
505
            try:
505
            try:
506
                args_string = ' '.join(args)
506
                args_string = ' '.join(args)
507
            except TypeError as e:
507
            except TypeError as e:
508
                raise TaskError('Wrong argument type: %s, expected string,' 
508
                raise TaskError('Wrong argument type: %s, expected string,'
509
                                ' error: %s' % (str(args), e))
509
                                ' error: %s' % (str(args), e))
510
               
510
511
            self._logger.commands.write(env_string + ' ' + args_string + 
511
            self._logger.commands.write(env_string + ' ' + args_string +
512
                                        ' dir=' + str(directory) + '\n')
512
                                        ' dir=' + str(directory) + '\n')
513
            stdin = None
513
            stdin = None
514
            stdout = self._logger.stdout
514
            stdout = self._logger.stdout
 Lines 516-528    Link Here 
516
        else:
516
        else:
517
            stdin = sys.stdin
517
            stdin = sys.stdin
518
            stdout = sys.stdout
518
            stdout = sys.stdout
519
            stderr = sys.stderr      
519
            stderr = sys.stderr
520
                  
520
521
        tmp = dict(list(os.environ.items()) + list(env.items()))
521
        tmp = dict(list(os.environ.items()) + list(env.items()))
522
        
522
523
        # sets the library and binary paths 
523
        # sets the library and binary paths
524
        tmp = self.append_to_path(tmp)
524
        tmp = self.append_to_path(tmp)
525
        
525
526
        # Calls the third party executable with the whole context
526
        # Calls the third party executable with the whole context
527
        try:
527
        try:
528
            popen = subprocess.Popen(args,
528
            popen = subprocess.Popen(args,
 Lines 532-543    Link Here 
532
                                     cwd = directory,
532
                                     cwd = directory,
533
                                     env = tmp)
533
                                     env = tmp)
534
        except Exception as e:
534
        except Exception as e:
535
            raise TaskError('could not execute: %s %s. \nUnexpected error: %s' 
535
            raise TaskError('could not execute: %s %s. \nUnexpected error: %s'
536
                                % (str(directory), str(args), str(e)))
536
                                % (str(directory), str(args), str(e)))
537
        
537
538
        # Waits for the full execution of the third party software
538
        # Waits for the full execution of the third party software
539
        retcode = popen.wait()
539
        retcode = popen.wait()
540
        if retcode != 0:
540
        if retcode != 0:
541
            raise TaskError('Subprocess failed with error %d: %s' % (retcode, str(args)))
541
            raise TaskError('Subprocess failed with error %d: %s' % (retcode, str(args)))
542
543
        

Return to bug 2975