Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 18868:c3bb622095f1
Prompt to fill EXTRA_JAVA_HOMES like JAVA_HOME
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Wed, 14 Jan 2015 09:52:41 -0800 |
parents | 869ee319c377 |
children | c446d00f2cdf |
comparison
equal
deleted
inserted
replaced
18867:7f4cb7587f4c | 18868:c3bb622095f1 |
---|---|
1591 deps = [] | 1591 deps = [] |
1592 for p in projects: | 1592 for p in projects: |
1593 p.all_deps(deps, includeLibs=includeLibs, includeJreLibs=includeJreLibs, includeAnnotationProcessors=includeAnnotationProcessors) | 1593 p.all_deps(deps, includeLibs=includeLibs, includeJreLibs=includeJreLibs, includeAnnotationProcessors=includeAnnotationProcessors) |
1594 return deps | 1594 return deps |
1595 | 1595 |
1596 def _handle_missing_java_home(): | 1596 def _handle_lookup_java_home(jdk): |
1597 return _handle_lookup_jdk(jdk, 'JAVA_HOME', '--java-home', False) | |
1598 | |
1599 def _handle_lookup_extra_java_homes(jdk): | |
1600 return _handle_lookup_jdk(jdk, 'EXTRA_JAVA_HOMES', '--extra-java-homes', True) | |
1601 | |
1602 def _handle_lookup_jdk(jdk, varName, flagName, allowMultiple): | |
1603 if jdk != None and jdk != '': | |
1604 return jdk | |
1605 jdk = os.environ.get(varName) | |
1606 if jdk != None and jdk != '': | |
1607 return jdk | |
1608 | |
1597 if not sys.stdout.isatty(): | 1609 if not sys.stdout.isatty(): |
1598 abort('Could not find bootstrap JDK. Use --java-home option or ensure JAVA_HOME environment variable is set.') | 1610 abort('Could not find bootstrap {0}. Use {1} option or ensure {2} environment variable is set.'.format(varName, flagName, varName)) |
1599 | 1611 |
1600 candidateJdks = [] | 1612 candidateJdks = [] |
1601 if get_os() == 'darwin': | 1613 if get_os() == 'darwin': |
1602 base = '/Library/Java/JavaVirtualMachines' | 1614 base = '/Library/Java/JavaVirtualMachines' |
1603 candidateJdks = [join(base, n, 'Contents/Home') for n in os.listdir(base) if exists(join(base, n, 'Contents/Home'))] | 1615 candidateJdks = [join(base, n, 'Contents/Home') for n in os.listdir(base) if exists(join(base, n, 'Contents/Home'))] |
1611 base = r'C:\Program Files\Java' | 1623 base = r'C:\Program Files\Java' |
1612 candidateJdks = [join(base, n) for n in os.listdir(base) if exists(join(base, n, r'jre\lib\rt.jar'))] | 1624 candidateJdks = [join(base, n) for n in os.listdir(base) if exists(join(base, n, r'jre\lib\rt.jar'))] |
1613 | 1625 |
1614 javaHome = None | 1626 javaHome = None |
1615 if len(candidateJdks) != 0: | 1627 if len(candidateJdks) != 0: |
1616 javaHome = select_items(candidateJdks + ['<other>'], allowMultiple=False) | 1628 log('Missing value for {0}.'.format(varName)) |
1629 javaHome = select_items(candidateJdks + ['<other>'], allowMultiple=allowMultiple) | |
1617 if javaHome == '<other>': | 1630 if javaHome == '<other>': |
1618 javaHome = None | 1631 javaHome = None |
1632 if javaHome != None and allowMultiple: | |
1633 javaHome = os.pathsep.join(javaHome) | |
1619 | 1634 |
1620 while javaHome is None: | 1635 while javaHome is None: |
1621 javaHome = raw_input('Enter path of bootstrap JDK: ') | 1636 javaHome = raw_input('Enter path of JDK for {0}: '.format(varName)) |
1622 rtJarPath = join(javaHome, 'jre', 'lib', 'rt.jar') | 1637 rtJarPath = join(javaHome, 'jre', 'lib', 'rt.jar') |
1623 if not exists(rtJarPath): | 1638 if not exists(rtJarPath): |
1624 log('Does not appear to be a valid JDK as ' + rtJarPath + ' does not exist') | 1639 log('Does not appear to be a valid JDK as ' + rtJarPath + ' does not exist') |
1625 javaHome = None | 1640 javaHome = None |
1626 else: | 1641 else: |
1627 break | 1642 break |
1628 | 1643 |
1629 envPath = join(_primary_suite.mxDir, 'env') | 1644 envPath = join(_primary_suite.mxDir, 'env') |
1630 if ask_yes_no('Persist this setting by adding "JAVA_HOME=' + javaHome + '" to ' + envPath, 'y'): | 1645 if ask_yes_no('Persist this setting by adding "{0}={1}" to {2}'.format(varName, javaHome, envPath), 'y'): |
1631 with open(envPath, 'a') as fp: | 1646 with open(envPath, 'a') as fp: |
1632 print >> fp, 'JAVA_HOME=' + javaHome | 1647 print >> fp, varName + '=' + javaHome |
1633 | 1648 |
1634 return javaHome | 1649 return javaHome |
1635 | 1650 |
1636 class ArgParser(ArgumentParser): | 1651 class ArgParser(ArgumentParser): |
1637 # Override parent to append the list of available commands | 1652 # Override parent to append the list of available commands |
1681 opts.__dict__.setdefault('ptimeout', 0) | 1696 opts.__dict__.setdefault('ptimeout', 0) |
1682 | 1697 |
1683 if opts.very_verbose: | 1698 if opts.very_verbose: |
1684 opts.verbose = True | 1699 opts.verbose = True |
1685 | 1700 |
1686 if opts.java_home is None: | 1701 opts.java_home = _handle_lookup_java_home(opts.java_home) |
1687 opts.java_home = os.environ.get('JAVA_HOME') | 1702 opts.extra_java_homes = _handle_lookup_extra_java_homes(opts.extra_java_homes) |
1688 if opts.extra_java_homes is None: | |
1689 opts.extra_java_homes = os.environ.get('EXTRA_JAVA_HOMES') | |
1690 | |
1691 if opts.java_home is None or opts.java_home == '': | |
1692 opts.java_home = _handle_missing_java_home() | |
1693 | 1703 |
1694 if opts.user_home is None or opts.user_home == '': | 1704 if opts.user_home is None or opts.user_home == '': |
1695 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.') | 1705 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.') |
1696 | 1706 |
1697 os.environ['JAVA_HOME'] = opts.java_home | 1707 os.environ['JAVA_HOME'] = opts.java_home |