comparison mxtool/mx.py @ 12741:a5b5e1ebab81

Merge
author Christos Kotselidis <christos.kotselidis@oracle.com>
date Sat, 09 Nov 2013 21:34:07 +0100
parents 697ef4cf18c0
children 68529068f08e
comparison
equal deleted inserted replaced
12740:ad2434911b69 12741:a5b5e1ebab81
1423 if get_os() == 'windows': 1423 if get_os() == 'windows':
1424 creationflags = subprocess.CREATE_NEW_PROCESS_GROUP 1424 creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
1425 else: 1425 else:
1426 preexec_fn = os.setsid 1426 preexec_fn = os.setsid
1427 1427
1428 if not callable(out) and not callable(err) and timeout is None: 1428 def redirect(stream, f):
1429 # The preexec_fn=os.setsid 1429 for line in iter(stream.readline, ''):
1430 p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags, env=env) 1430 f(line)
1431 _currentSubprocess = (p, args) 1431 stream.close()
1432 stdout = out if not callable(out) else subprocess.PIPE
1433 stderr = err if not callable(err) else subprocess.PIPE
1434 p = subprocess.Popen(args, cwd=cwd, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn, creationflags=creationflags, env=env)
1435 _currentSubprocess = (p, args)
1436 if callable(out):
1437 t = Thread(target=redirect, args=(p.stdout, out))
1438 t.daemon = True # thread dies with the program
1439 t.start()
1440 if callable(err):
1441 t = Thread(target=redirect, args=(p.stderr, err))
1442 t.daemon = True # thread dies with the program
1443 t.start()
1444 if timeout is None or timeout == 0:
1432 retcode = waitOn(p) 1445 retcode = waitOn(p)
1433 else: 1446 else:
1434 def redirect(stream, f): 1447 if get_os() == 'windows':
1435 for line in iter(stream.readline, ''): 1448 abort('Use of timeout not (yet) supported on Windows')
1436 f(line) 1449 retcode = _waitWithTimeout(p, args, timeout)
1437 stream.close()
1438 stdout = out if not callable(out) else subprocess.PIPE
1439 stderr = err if not callable(err) else subprocess.PIPE
1440 p = subprocess.Popen(args, cwd=cwd, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn, creationflags=creationflags, env=env)
1441 _currentSubprocess = (p, args)
1442 if callable(out):
1443 t = Thread(target=redirect, args=(p.stdout, out))
1444 t.daemon = True # thread dies with the program
1445 t.start()
1446 if callable(err):
1447 t = Thread(target=redirect, args=(p.stderr, err))
1448 t.daemon = True # thread dies with the program
1449 t.start()
1450 if timeout is None or timeout == 0:
1451 retcode = waitOn(p)
1452 else:
1453 if get_os() == 'windows':
1454 abort('Use of timeout not (yet) supported on Windows')
1455 retcode = _waitWithTimeout(p, args, timeout)
1456 except OSError as e: 1450 except OSError as e:
1457 log('Error executing \'' + ' '.join(args) + '\': ' + str(e)) 1451 log('Error executing \'' + ' '.join(args) + '\': ' + str(e))
1458 if _opts.verbose: 1452 if _opts.verbose:
1459 raise e 1453 raise e
1460 abort(e.errno) 1454 abort(e.errno)
2981 out.close('buildCommand') 2975 out.close('buildCommand')
2982 2976
2983 # The path should always be p.name/dir. independent of where the workspace actually is. 2977 # The path should always be p.name/dir. independent of where the workspace actually is.
2984 # So we use the parent folder of the project, whatever that is, to generate such a relative path. 2978 # So we use the parent folder of the project, whatever that is, to generate such a relative path.
2985 logicalWorkspaceRoot = os.path.dirname(p.dir) 2979 logicalWorkspaceRoot = os.path.dirname(p.dir)
2986 binFolder = os.path.relpath(p.output_dir(), logicalWorkspaceRoot) 2980 binFolder = os.path.relpath(p.output_dir(), logicalWorkspaceRoot)
2987 2981
2988 if _isAnnotationProcessorDependency(p): 2982 if _isAnnotationProcessorDependency(p):
2989 refreshFile = os.path.relpath(join(p.dir, p.name + '.jar'), logicalWorkspaceRoot) 2983 refreshFile = os.path.relpath(join(p.dir, p.name + '.jar'), logicalWorkspaceRoot)
2990 _genEclipseBuilder(out, p, 'Jar', 'archive ' + p.name, refresh=True, refreshFile=refreshFile, relevantResources=[binFolder], async=True, xmlIndent='', xmlStandalone='no') 2984 _genEclipseBuilder(out, p, 'Jar', 'archive ' + p.name, refresh=True, refreshFile=refreshFile, relevantResources=[binFolder], async=True, xmlIndent='', xmlStandalone='no')
2991 2985
2992 if projToDist.has_key(p.name): 2986 if projToDist.has_key(p.name):
2993 dist, distDeps = projToDist[p.name] 2987 dist, distDeps = projToDist[p.name]
2994 _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist', 'archive @' + dist.name, relevantResources=[binFolder], logToFile=True, refresh=False, async=True) 2988 _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist', 'archive @' + dist.name, relevantResources=[binFolder], logToFile=True, refresh=False, async=True)
3066 if refresh: 3060 if refresh:
3067 if refreshFile is None: 3061 if refreshFile is None:
3068 refreshScope = '${project}' 3062 refreshScope = '${project}'
3069 else: 3063 else:
3070 refreshScope = '${working_set:<?xml version="1.0" encoding="UTF-8"?><resources><item path="' + refreshFile + '" type="1"/></resources>}' 3064 refreshScope = '${working_set:<?xml version="1.0" encoding="UTF-8"?><resources><item path="' + refreshFile + '" type="1"/></resources>}'
3071 3065
3072 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_RECURSIVE', 'value': 'false'}) 3066 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_RECURSIVE', 'value': 'false'})
3073 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': refreshScope}) 3067 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': refreshScope})
3074 3068
3075 if relevantResources is not None: 3069 if relevantResources is not None:
3076 resources = '${working_set:<?xml version="1.0" encoding="UTF-8"?><resources>' 3070 resources = '${working_set:<?xml version="1.0" encoding="UTF-8"?><resources>'
3077 for relevantResource in relevantResources: 3071 for relevantResource in relevantResources:
3078 resources += '<item path="' + relevantResource +'" type="2" />' 3072 resources += '<item path="' + relevantResource + '" type="2" />'
3079 resources += '</resources>}' 3073 resources += '</resources>}'
3080 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE', 'value': resources}) 3074 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE', 'value': resources})
3081 3075
3082 3076
3083 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': consoleOn}) 3077 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': consoleOn})
3084 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true' if async else 'false'}) 3078 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true' if async else 'false'})
3085 if logToFile: 3079 if logToFile:
3086 logFile = join(externalToolDir, name + '.log') 3080 logFile = join(externalToolDir, name + '.log')
3087 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CAPTURE_IN_FILE', 'value': logFile}) 3081 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CAPTURE_IN_FILE', 'value': logFile})