# HG changeset patch # User Doug Simon # Date 1382435658 -7200 # Node ID a7d44c1399482ef83b96e4ae6f0ae278e3c76312 # Parent 8c64f10f86b772feb16533296a890e1011a31662# Parent 9e33b386281ecb09df78f8a903ff354d50758936 Merge. diff -r 9e33b386281e -r a7d44c139948 mxtool/mx.py --- a/mxtool/mx.py Tue Oct 22 10:15:37 2013 +0200 +++ b/mxtool/mx.py Tue Oct 22 11:54:18 2013 +0200 @@ -504,44 +504,48 @@ """ def __init__(self): self.missing = 'no hg executable found' - try: - subprocess.check_output(['hg']) - self.has_hg = True - except OSError: - self.has_hg = False - warn(self.missing) - - def _check(self, abortOnFail=True): + self.has_hg = None + + def check(self, abortOnFail=True): + if self.has_hg is None: + try: + subprocess.check_output(['hg']) + self.has_hg = True + except OSError: + self.has_hg = False + warn(self.missing) + if not self.has_hg: if abortOnFail: abort(self.missing) else: warn(self.missing) - return self.has_hg - - def _tip(self, s, abortOnError=True): - if not self.has_hg: - return None + + def tip(self, s, abortOnError=True): try: version = subprocess.check_output(['hg', 'tip', '-R', s.dir, '--template', '{node}']) if s.version is not None and s.version != version: abort('version of suite ' + s.name +' has changed during run') return version + except OSError: + warn(self.missing) except subprocess.CalledProcessError: if abortOnError: abort('failed to get tip revision id') else: return None - def _canpush(self, s, strict=True): + def can_push(self, s, strict=True): try: output = subprocess.check_output(['hg', '-R', s.dir, 'status']) # super strict return output == '' + except OSError: + warn(self.missing) except subprocess.CalledProcessError: return False - def _default_push(self, sdir): + def default_push(self, sdir): with open(join(sdir, '.hg', 'hgrc')) as f: for line in f: line = line.rstrip() @@ -763,8 +767,9 @@ self.commands = None self.primary = primary self.name = _suitename(mxDir) # validated in _load_projects - self.version = None # _hg._tip checks current version if not None - self.version = _hg._tip(self, False) + self.version = None # _hg.tip checks current version if not None + # TODO this forces hg to be run every time mx is run + #self.version = _hg.tip(self, False) if load: # load suites bottom up to make sure command overriding works properly self._load_imports() @@ -2979,12 +2984,12 @@ out.close('buildCommand') if _isAnnotationProcessorDependency(p): - _genEclipseBuilder(out, p, 'Jar.launch', 'archive ' + p.name, refresh=False, async=False, xmlIndent='', xmlStandalone='no') - _genEclipseBuilder(out, p, 'Refresh.launch', '', refresh=True, async=True) + _genEclipseBuilder(out, p, 'Jar', 'archive ' + p.name, refresh=False, async=False, xmlIndent='', xmlStandalone='no') + _genEclipseBuilder(out, p, 'Refresh', '', refresh=True, async=True) if projToDist.has_key(p.name): dist, distDeps = projToDist[p.name] - _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist.launch', 'archive @' + dist.name, refresh=False, async=True) + _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist', 'archive @' + dist.name, logToFile=True, refresh=False, async=True) out.close('buildSpec') out.open('natures') @@ -3046,7 +3051,8 @@ """ return p in sorted_deps(annotation_processors()) -def _genEclipseBuilder(dotProjectDoc, p, name, mxCommand, refresh=True, async=False, logToConsole=False, xmlIndent='\t', xmlStandalone=None): +def _genEclipseBuilder(dotProjectDoc, p, name, mxCommand, refresh=True, async=False, logToConsole=False, logToFile=False, appendToLogFile=True, xmlIndent='\t', xmlStandalone=None): + externalToolDir = join(p.dir, '.externalToolBuilders') launchOut = XMLDoc() consoleOn = 'true' if logToConsole else 'false' launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) @@ -3059,6 +3065,10 @@ launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': '${project}'}) launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': consoleOn}) launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true' if async else 'false'}) + if logToFile: + logFile = join(externalToolDir, name + '.log') + launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CAPTURE_IN_FILE', 'value': logFile}) + launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_APPEND_TO_FILE', 'value': 'true' if appendToLogFile else 'false'}) # expect to find the OS command to invoke mx in the same directory baseDir = dirname(os.path.abspath(__file__)) @@ -3082,11 +3092,9 @@ launchOut.close('launchConfiguration') - externalToolDir = join(p.dir, '.externalToolBuilders') - if not exists(externalToolDir): os.makedirs(externalToolDir) - update_file(join(externalToolDir, name), launchOut.xml(indent=xmlIndent, standalone=xmlStandalone, newl='\n')) + update_file(join(externalToolDir, name + '.launch'), launchOut.xml(indent=xmlIndent, standalone=xmlStandalone, newl='\n')) dotProjectDoc.open('buildCommand') dotProjectDoc.element('name', data='org.eclipse.ui.externaltools.ExternalToolBuilder') @@ -3094,7 +3102,7 @@ dotProjectDoc.open('arguments') dotProjectDoc.open('dictionary') dotProjectDoc.element('key', data='LaunchConfigHandle') - dotProjectDoc.element('value', data='/.externalToolBuilders/' + name) + dotProjectDoc.element('value', data='/.externalToolBuilders/' + name + '.launch') dotProjectDoc.close('dictionary') dotProjectDoc.open('dictionary') dotProjectDoc.element('key', data='incclean') @@ -3943,7 +3951,7 @@ def sclone(args): """clone a suite repository, and its imported suites""" - _hg._check(True) + _hg.check(True) parser = ArgumentParser(prog='mx sclone') parser.add_argument('--source', help='url/path of repo containing suite', metavar='') parser.add_argument('--dest', help='destination directory (default basename of source)', metavar='') @@ -4029,7 +4037,7 @@ def scloneimports(args): """clone the imports of an existing suite""" - _hg._check(True) + _hg.check(True) parser = ArgumentParser(prog='mx scloneimports') parser.add_argument('--source', help='url/path of repo containing suite', metavar='') parser.add_argument('nonKWArgs', nargs=REMAINDER, metavar='source [dest]...') @@ -4043,7 +4051,7 @@ s = _scloneimports_suitehelper(args.source) - default_path = _hg._default_push(args.source) + default_path = _hg.default_push(args.source) if default_path is None: abort('no default path in ' + join(args.source, '.hg', 'hgrc')) @@ -4062,13 +4070,13 @@ def _spush_check_import_visitor(s, suite_import, **extra_args): """push check visitor for Suite._visit_imports""" - currentTip = _hg._tip(suite(suite_import.name)) + currentTip = _hg.tip(suite(suite_import.name)) if currentTip != suite_import.version: abort('import version of ' + suite_import.name + ' in suite ' + s.name + ' does not match tip') def _spush(s, suite_import, dest, checks, clonemissing): if checks: - if not _hg._canpush(s): + if not _hg.can_push(s): abort('working directory ' + s.dir + ' contains uncommitted changes, push aborted') # check imports first @@ -4108,7 +4116,7 @@ def spush(args): """push primary suite and all its imports""" - _hg._check(True) + _hg.check(True) parser = ArgumentParser(prog='mx spush') parser.add_argument('--dest', help='url/path of repo to push to (default as per hg push)', metavar='') parser.add_argument('--no-checks', action='store_true', help='checks on status, versions are disabled') @@ -4146,7 +4154,7 @@ def supdate(args): """update primary suite and all its imports""" - _hg._check(True) + _hg.check(True) s = _check_primary_suite() _supdate(s, None) @@ -4159,7 +4167,7 @@ # check imports recursively s._visit_imports(_scheck_imports_visitor, update_versions=update_versions) - currentTip = _hg._tip(s) + currentTip = _hg.tip(s) if currentTip != suite_import.version: print('import version of ' + s.name + ' does not match tip' + (': updating' if update_versions else '')) @@ -4180,18 +4188,18 @@ _spull(suite(suite_import.name), update_versions, updated_imports) def _spull(s, update_versions, updated_imports): - _hg._check(True) + _hg.check(True) # pull imports first s._visit_imports(_spull_import_visitor, update_versions=update_versions) run(['hg', '-R', s.dir, 'pull', '-u']) if update_versions and updated_imports is not None: - tip = _hg._tip(s) + tip = _hg.tip(s) updated_imports.write(SuiteImport._tostring(s.name, tip) + '\n') def spull(args): """pull primary suite and all its imports""" - _hg._check(True) + _hg.check(True) parser = ArgumentParser(prog='mx spull') parser.add_argument('--update-versions', action='store_true', help='update version ids of imported suites') args = parser.parse_args(args)