# HG changeset patch # User Gilles Duboscq # Date 1434029922 -7200 # Node ID 7a0c8adc0a303cb0b788b4a386bd6bad3b5dfe1a # Parent e23e6dc49a1122249d740893f1d6f05e96e92846 mx: Fix typos and error if mx/env does not exist diff -r e23e6dc49a11 -r 7a0c8adc0a30 mxtool/mx.py --- a/mxtool/mx.py Mon Jun 15 14:25:29 2015 +0200 +++ b/mxtool/mx.py Thu Jun 11 15:38:42 2015 +0200 @@ -1276,7 +1276,7 @@ del _libs[d.name] self.libs.remove(d) elif d.isProject(): - if java(d.javaCompliance, cancel='some projects will be omitted which may result in errrors') is None: + if java(d.javaCompliance, cancel='some projects will be omitted which may result in errors') is None: logv('[omitting project {0} as Java compliance {1} cannot be satisfied by configured JDKs]'.format(d, d.javaCompliance)) ommittedDeps.add(d.name) del _projects[d.name] @@ -1840,13 +1840,13 @@ return jdk def _find_jdk(versionCheck=None, versionDescription=None, purpose=None, cancel=None): - if not versionCheck: - versionCheck = lambda v: True assert not versionDescription or versionCheck if not versionCheck and not purpose: isDefaultJdk = True else: isDefaultJdk = False + if not versionCheck: + versionCheck = lambda v: True candidateJdks = [] source = '' @@ -1935,7 +1935,7 @@ selected = configs[0] msg = 'Selected ' + str(selected) + ' as ' if isDefaultJdk: - msg += 'default' + msg += 'default ' msg += 'JDK' if versionDescription: msg = msg + ' ' + versionDescription @@ -1961,26 +1961,30 @@ envPath = join(_primary_suite.mxDir, 'env') if is_interactive() and ask_yes_no('Persist this setting by adding "{0}={1}" to {2}'.format(varName, selected.jdk, envPath), 'y'): envLines = [] - with open(envPath) as fp: - append = True - for line in fp: - if line.rstrip().startswith(varName): - _, currentValue = line.split('=', 1) - currentValue = currentValue.strip() - if not allowMultiple and currentValue: - if not ask_yes_no('{0} is already set to {1}, overwrite with {2}?'.format(varName, currentValue, selected.jdk), 'n'): - return selected + if exists(envPath): + with open(envPath) as fp: + append = True + for line in fp: + if line.rstrip().startswith(varName): + _, currentValue = line.split('=', 1) + currentValue = currentValue.strip() + if not allowMultiple and currentValue: + if not ask_yes_no('{0} is already set to {1}, overwrite with {2}?'.format(varName, currentValue, selected.jdk), 'n'): + return selected + else: + line = varName + '=' + selected.jdk + os.linesep else: - line = varName + '=' + selected.jdk + os.linesep - else: - line = line.rstrip() - if currentValue: - line += os.pathsep - line += selected.jdk + os.linesep - append = False - envLines.append(line) + line = line.rstrip() + if currentValue: + line += os.pathsep + line += selected.jdk + os.linesep + append = False + envLines.append(line) + else: + append = True + if append: - envLines.append(varName + '=' + selected.jdk) + envLines.append(varName + '=' + selected.jdk + os.linesep) with open(envPath, 'w') as fp: for line in envLines: