java.configure 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. # Java detection
  6. # ========================================================
  7. option('--with-java-bin-path', nargs=1,
  8. help='Location of Java binaries (java, javac, jar)')
  9. @depends('--with-java-bin-path')
  10. @imports(_from='os', _import='environ')
  11. def java_search_paths(path):
  12. if path:
  13. # Look for javac and jar in the specified path.
  14. return path
  15. # With no path specified, look for javac and jar in $JAVA_HOME (if set)
  16. # and $PATH.
  17. if 'JAVA_HOME' in environ:
  18. return [os.path.join(environ['JAVA_HOME'], 'bin'),
  19. environ.get('PATH', '')]
  20. return [environ.get('PATH')]
  21. # Finds the given java tool, failing with a custom error message if we can't
  22. # find it.
  23. @template
  24. def check_java_tool(tool):
  25. check = check_prog(tool.upper(), (tool,), paths=java_search_paths,
  26. allow_missing=True)
  27. @depends(check)
  28. def require_tool(result):
  29. if result is None:
  30. die("The program %s was not found. Set $JAVA_HOME to your Java "
  31. "SDK directory or use '--with-java-bin-path={java-bin-dir}'"
  32. % tool)
  33. return result
  34. return require_tool
  35. check_java_tool('java')
  36. check_java_tool('javah')
  37. check_java_tool('jar')
  38. check_java_tool('jarsigner')
  39. check_java_tool('keytool')
  40. javac = check_java_tool('javac')
  41. @depends(javac)
  42. @checking('for javac version')
  43. @imports('subprocess')
  44. def javac_version(javac):
  45. try:
  46. output = subprocess.check_output([javac, '-version'],
  47. stderr=subprocess.STDOUT).rstrip()
  48. version = Version(output.split(' ')[-1])
  49. if version < '1.7':
  50. die('javac 1.7 or higher is required (found %s)' % version)
  51. return version
  52. except subprocess.CalledProcessError as e:
  53. die('Failed to get javac version: %s', e.output)