def get_java_home(): global _java_home if _java_home is not None: return _java_home if is_osx(): # newer macs have an executable to help us try: result = shell("/usr/libexec/java_home") _java_home = result.stdout.decode("utf-8") return _java_home except CommandFailed: traceback.print_exc() if not os.path.exists(MAC_JAVA_HOME): configure_error("No JAVA_HOME") # Apple's JAVA_HOME is predictable, just use that if we can # though it doesn't work for Oracle's JDK if os.path.exists(MAC_JAVA_HOME): _java_home = MAC_JAVA_HOME return _java_home env_home = os.environ.get("JAVA_HOME") if env_home: if is_windows(): # remove quotes from each end if necessary env_home = env_home.strip('"') if os.path.exists(env_home): _java_home = env_home return env_home else: configure_error("Path " + env_home + " indicated by JAVA_HOME does not exist.") configure_error("Please set the environment variable JAVA_HOME to a path containing the JDK.")
def link_native_lib(self, jep_dir, jep_lib): # we'll put the jep_dir as -Djava.library.path in the jep script if is_windows(): jep_dll = os.path.join(jep_dir, 'jep.dll') # Remove the old DLL if it exists to avoid a file move error. if os.path.exists(jep_dll): os.remove(jep_dll) # Do not use 'spawn' as that will run as a non-administrative user # that may no longer have access to the destination directory. self.move_file(os.path.join(jep_dir, jep_lib), jep_dll) elif is_osx(): # Apple says to put the file at /Library/Java/Extensions/libjep.jnilib, # which is good for a permanent install but not so good when using # virtualenv or testing spawn(['ln', '-sf', '{0}'.format(jep_lib), '{0}'.format(os.path.join(jep_dir, 'libjep.jnilib')),]) else: # otherwise, distutils outputs 'jep.so' which needs to be linked # to libjep.so. The JVM will not find the library without. spawn(['ln', '-sf', '{0}'.format(jep_lib), '{0}'.format(os.path.join(jep_dir, 'libjep.so')), ])
def get_java_home(): global _java_home if _java_home is not None: return _java_home if is_osx(): # newer macs have an executable to help us try: result = shell('/usr/libexec/java_home') _java_home = result.stdout return _java_home except CommandFailed: traceback.print_exc() if not os.path.exists(MAC_JAVA_HOME): configure_error('No JAVA_HOME') # Apple's JAVA_HOME is predictable, just use that if we can # though it doesn't work for Oracle's JDK if os.path.exists(MAC_JAVA_HOME): _java_home = MAC_JAVA_HOME return _java_home env_home = os.environ.get('JAVA_HOME') if env_home and os.path.exists(env_home): _java_home = env_home return env_home configure_error("Please set JAVA_HOME to a path containing the JDK.")
def get_java_lib(): lib_name = 'lib' if is_osx(): lib_name = 'Libraries' lib = os.path.join(get_java_home(), lib_name) if not os.path.exists(lib): configure_error("Lib folder should be at '{0}' but doesn't exist. " \ "Please check you've installed the JDK properly.".format(lib)) return lib
def initialize_options(self): build_java.outdir = os.path.join('build', 'java') if not os.path.exists(build_java.outdir): os.makedirs(build_java.outdir) self.java_files = [] if is_osx(): self.javac = os.path.join(get_java_home(), 'Commands', 'javac') else: self.javac = os.path.join(get_java_home(), 'bin', 'javac')
def get_java_lib_folders(): if not is_osx(): jre = os.path.join(get_java_home(), 'jre', 'lib') folders = [] for root, dirnames, filenames in os.walk(jre): for filename in fnmatch.filter(filenames, '*jvm.so'): folders.append(os.path.join(root, os.path.dirname(filename))) return list(set(folders)) return []
def initialize_options(self): build_javah.outdir = os.path.join('build', 'include') if not os.path.exists(build_javah.outdir): os.mkdir(build_javah.outdir) if is_osx(): self.javah = os.path.join(get_java_home(), 'Commands', 'javah') else: self.javah = os.path.join(get_java_home(), 'bin', 'javah') self.javah_files = []
def get_java_home(): global JAVA_HOME # mac's JAVA_HOME is predictable, just use that if we can if is_osx() and os.path.exists(MAC_JAVA_HOME): return MAC_JAVA_HOME if JAVA_HOME and os.path.exists(JAVA_HOME): return JAVA_HOME configure_error("Please set JAVA_HOME to a path containing the JDK.")
def initialize_options(self): build_jar.outdir = os.path.join('build', 'java') if not os.path.exists(build_jar.outdir): os.makedirs(build_java.outdir) self.java_files = [] self.extra_jar_files = [] if is_osx(): self.jar = os.path.join(get_java_home(), 'Commands', 'jar') else: self.jar = os.path.join(get_java_home(), 'bin', 'jar')
def run(self): warning("Using JAVA_HOME:", get_java_home()) if is_osx(): target = os.environ.get("MACOSX_DEPLOYMENT_TARGET") if target: warning("INFO: the MACOSX_DEPLOYMENT_TARGET environment variable is set:", target) result = shell("sw_vers -productVersion") if target.split(".")[:2] != result.stdout.split(".")[:2]: warning("This target appears to be incorrect for the system version:", result.stdout)
def run(self): warning('Using JAVA_HOME:', get_java_home()) if is_osx(): target = os.environ.get('MACOSX_DEPLOYMENT_TARGET') if target: warning('INFO: the MACOSX_DEPLOYMENT_TARGET environment variable is set:', target) result = shell('sw_vers -productVersion') if target.split('.')[:2] != result.stdout.split('.')[:2]: warning('This target appears to be incorrect for the system version:', result.stdout)
def run(self): # make sure we're testing the latest self.run_command('build') # setup java classpath version = self.distribution.metadata.get_version() classpath = os.path.join(self.java_build, 'jep-' + version + '.jar') classpath += os.pathsep + os.path.join(self.java_build, 'jep-' + version + '-test.jar') classpath += os.pathsep + 'src/test/python/lib/sqlitejdbc-v056.jar' classpath += os.pathsep + 'stc/test/python/lib/fakenetty.jar' # setup environment variables environment = {} if not is_osx() and not is_windows(): environment['LD_LIBRARY_PATH'] = sysconfig.get_config_var('LIBDIR') # http://bugs.python.org/issue20614 if is_windows(): environment['SYSTEMROOT'] = os.environ['SYSTEMROOT'] java_path = os.path.join(get_java_home(), 'bin') # if multiple versions of python are installed, this helps ensure the right # version is used executable = sys.executable if executable: py_path = os.path.dirname(executable) environment['PATH'] = py_path + os.pathsep + java_path + os.pathsep + os.environ['PATH'] else: environment['PATH'] = java_path + os.pathsep + os.environ['PATH'] prefix = sysconfig.get_config_var('prefix') exec_prefix = sysconfig.get_config_var('exec_prefix') if prefix == exec_prefix: environment['PYTHONHOME'] = prefix else: environment['PYTHONHOME'] = prefix + ':' + exec_prefix # find the jep library and makes sure it's named correctly build_ext = self.get_finalized_command('build_ext') jep_lib = build_ext.get_outputs()[0] built_dir = os.path.dirname(jep_lib) link_native_lib(built_dir, jep_lib) environment['PYTHONPATH'] = self.get_finalized_command('build').build_lib # actually kick off the tests import subprocess args = [os.path.join(java_path, 'java'), '-classpath', '{0}'.format(classpath), 'jep.Run', 'src/test/python/runtests.py'] p = subprocess.Popen(args, env=environment) rc = p.wait() if rc != 0: raise DistutilsExecError("Unit tests failed with exit status %d" % (rc))
def run(self): # make sure we're testing the latest self.run_command('build') # setup java classpath version = self.distribution.metadata.get_version() classpath = os.path.join(self.java_build, 'jep-' + version + '.jar') classpath += os.pathsep + os.path.join(self.java_build, 'jep.test-' + version + '.jar') classpath += os.pathsep + 'tests/lib/sqlitejdbc-v056.jar' classpath += os.pathsep + 'tests/lib/fakenetty.jar' # setup environment variables environment = {} if not is_osx() and not is_windows(): environment['LD_LIBRARY_PATH'] = sysconfig.get_config_var('LIBDIR') # set the LD_PRELOAD environment variable if we can locate the # libpython<version>.so library. lib_python = get_libpython() if lib_python: environment['LD_PRELOAD'] = lib_python # http://bugs.python.org/issue20614 if is_windows(): environment['SYSTEMROOT'] = os.environ['SYSTEMROOT'] # if multiple versions of python are installed, this helps ensure the right # version is used executable = sys.executable if executable: environment['PATH'] = os.path.dirname(executable) + os.pathsep + os.environ['PATH'] # find the jep library and makes sure it's named correctly build_ext = self.get_finalized_command('build_ext') jep_lib = build_ext.get_outputs()[0] built_dir = os.path.dirname(jep_lib) link_native_lib(built_dir, jep_lib) # actually kick off the tests import subprocess args = ['java', '-classpath', '{0}'.format(classpath), '-Djava.library.path={0}'.format(built_dir), 'jep.Run', 'tests/runtests.py'] p = subprocess.Popen(args, env=environment) p.wait()
def get_java_lib_folders(): if not is_osx(): if is_windows(): jre = os.path.join(get_java_home(), "lib") else: jre = os.path.join(get_java_home(), "jre", "lib") folders = [] for root, dirnames, filenames in os.walk(jre): if is_windows(): for filename in fnmatch.filter(filenames, "*jvm.lib"): folders.append(os.path.join(root, os.path.dirname(filename))) else: for filename in fnmatch.filter(filenames, "*jvm.so"): folders.append(os.path.join(root, os.path.dirname(filename))) return list(set(folders)) return []
def run(self): if skip_java_build(self): log.debug('skipping Java build (up-to-date)') return warning('Using JAVA_HOME:', get_java_home()) if is_osx(): target = os.environ.get('MACOSX_DEPLOYMENT_TARGET') if target: warning( 'INFO: the MACOSX_DEPLOYMENT_TARGET environment variable is set:', target) result = shell('sw_vers -productVersion') if target.split('.')[:2] != result.stdout.decode( "utf-8").split('.')[:2]: warning( 'This target appears to be incorrect for the system version:', result.stdout)
def run(self): install_data.run(self) install = self.get_finalized_command('install') if is_osx(): # link the jep.so output file to /Library/Java/Extensions/libjep.jnilib spawn(['ln', '-sf', '{0}'.format(os.path.join(install.install_lib, 'jep.so')), '/Library/Java/Extensions/libjep.jnilib',]) else: # otherwise, distutils outputs 'jep.so' which needs to be linked # to libjep.so. The JVM will not find the library without. spawn(['ln', '-sf', '{0}'.format(os.path.join(install.install_lib, 'jep.so')), '{0}'.format(os.path.join(install.install_lib, 'libjep.so')), ])
def get_java_include(): """ Locate the Java include folders for compiling JNI applications. """ inc_name = 'include' if is_osx(): inc_name = 'Headers' inc = os.path.join(get_java_home(), inc_name) if not os.path.exists(inc): configure_error("Include folder should be at '{0}' but doesn't exist. " \ "Please check you've installed the JDK properly.".format(inc)) jni = os.path.join(inc, "jni.h") if not os.path.exists(jni): configure_error("jni.h should be in '{0}' but doesn't exist. " \ "Please check you've installed the JDK properly.".format(jni)) paths = [inc] include_linux = os.path.join(inc, 'linux') if os.path.exists(include_linux): paths.append(include_linux) return paths
def link_native_lib(output_dir, jep_lib_path): """ Links or moves the native jep library (jep.so, jep.dll) to where it can be found by Java. Args: output_dir: the directory the linked/moved file should be in should match the value passed as -Djava.library.path jep_lib_path: the path to the jep library e.g. build/lib.linux-x86_64-2.7/jep.so """ jep_lib = os.path.basename(jep_lib_path) if is_windows(): jep_dll = os.path.join(output_dir, 'jep.dll') # Remove the old DLL if it exists to avoid a file move error. if os.path.exists(jep_dll): os.remove(jep_dll) # Do not use 'spawn' as that will run as a non-administrative user # that may no longer have access to the destination directory. shutil.copy(os.path.join(output_dir, jep_lib), jep_dll) elif is_osx(): # Apple says to put the file at /Library/Java/Extensions/libjep.jnilib, # which is good for a permanent install but not so good when using # virtualenv or testing. spawn(['ln', '-sf', '{0}'.format(jep_lib), '{0}'.format(os.path.join(output_dir, 'libjep.jnilib')), ]) else: # Otherwise, distutils outputs 'jep.so' which needs to be linked # to 'libjep.so'. Otherwise the JVM will not find the library. spawn(['ln', '-sf', '{0}'.format(jep_lib), '{0}'.format(os.path.join(output_dir, 'libjep.so')), ])
def run(self): install_data.run(self) install = self.get_finalized_command('install') if is_osx(): # link the jep.so output file to /Library/Java/Extensions/libjep.jnilib spawn([ 'ln', '-sf', '{0}'.format(os.path.join(install.install_lib, 'jep.so')), '/Library/Java/Extensions/libjep.jnilib', ]) else: # otherwise, distutils outputs 'jep.so' which needs to be linked # to libjep.so. The JVM will not find the library without. spawn([ 'ln', '-sf', '{0}'.format(os.path.join(install.install_lib, 'jep.so')), '{0}'.format(os.path.join(install.install_lib, 'libjep.so')), ])
def get_java_home(): global _java_home if _java_home is not None: return _java_home if is_osx(): # newer macs have an executable to help us try: result = shell('/usr/libexec/java_home') _java_home = result.stdout.decode('utf-8') return _java_home except CommandFailed: traceback.print_exc() if not os.path.exists(MAC_JAVA_HOME): configure_error('No JAVA_HOME') # Apple's JAVA_HOME is predictable, just use that if we can # though it doesn't work for Oracle's JDK if os.path.exists(MAC_JAVA_HOME): _java_home = MAC_JAVA_HOME return _java_home env_home = os.environ.get('JAVA_HOME') if env_home: if is_windows(): # remove quotes from each end if necessary env_home = env_home.strip('"') if os.path.exists(env_home): _java_home = env_home return env_home else: configure_error('Path ' + env_home + ' indicated by JAVA_HOME does not exist.') configure_error( 'Please set the environment variable JAVA_HOME to a path containing the JDK.' )
def get_python_linker_args(): if is_osx(): return [] return ['-L{0}'.format(sysconfig.get_config_var('LIBDIR'))]
def get_java_libraries(): if not is_osx(): return ['jvm'] return []
def get_python_linker_args(): if is_osx(): return ['-framework CoreFoundation -u _PyMac_Error'] else: return ['-L{0}'.format(sysconfig.get_config_var('LIBDIR'))]
def get_java_libraries(): if not is_osx(): return ["jvm"] return []
def copy_scripts(self): """Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. """ self.mkpath(self.build_dir) outfiles = [] install = self.get_finalized_command('install') context = dict( version=self.distribution.metadata.get_version(), install_base=install.install_base, install_platbase=install.install_platbase, install_lib=install.install_lib, virtual_env=os.environ.get('VIRTUAL_ENV') or '', ld_library_path='', ld_preload='', ) if not is_osx() and not is_windows(): context['ld_library_path'] = 'LD_LIBRARY_PATH="' + \ sysconfig.get_config_var('LIBDIR') + \ ':{0}"; export LD_LIBRARY_PATH'.format( install.install_lib) # set the LD_PRELOAD environment variable if we can locate the # libpython<version>.so library. lib_python = os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('LDLIBRARY')) if os.path.exists(lib_python): context['ld_preload'] = 'LD_PRELOAD="{0}"; export LD_PRELOAD'.format(lib_python) else: # x64 systems will tend to also have a MULTIARCH folder lib_python = os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('MULTIARCH'), sysconfig.get_config_var('LDLIBRARY')) if os.path.exists(lib_python): context['ld_preload'] = 'LD_PRELOAD="{0}"; export LD_PRELOAD'.format(lib_python) for script in self.scripts: if is_windows(): script='{0}.bat'.format(script) script = convert_path(script) outfile = os.path.join(self.build_dir, os.path.basename(script)) outfiles.append(outfile) if not self.force and not newer(script, outfile): log.debug("not copying %s (up-to-date)", script) continue # Always open the file, but ignore failures in dry-run mode -- # that way, we'll get accurate feedback if we can read the # script. try: f = open(script, "r") except IOError: if not self.dry_run: raise f = None log.info("copying and adjusting %s -> %s", script, self.build_dir) if not self.dry_run: outf = open(outfile, "w") outf.write(f.read().format(**context)) outf.close() if f: f.close() if os.name == 'posix': for file in outfiles: if self.dry_run: log.info("changing mode of %s", file) else: oldmode = os.stat(file)[ST_MODE] & 0o7777 newmode = (oldmode | 0o555) & 0o7777 if newmode != oldmode: log.info("changing mode of %s from %o to %o", file, oldmode, newmode) os.chmod(file, newmode)
def get_java_linker_args(): if is_osx(): return ['-framework JavaVM'] return []
def copy_scripts (self): """Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. """ self.mkpath(self.build_dir) outfiles = [] install = self.get_finalized_command('install') context = dict( prefix=install.prefix, install_base=install.install_base, install_platbase=install.install_platbase, install_lib=install.install_lib, virtual_env=os.environ.get('VIRTUAL_ENV') or '', ld_library_path='', ld_preload='', ) if not is_osx(): context['ld_library_path'] = 'LD_LIBRARY_PATH="{0}"; export LD_LIBRARY_PATH'.format( install.install_lib) # set the LD_PRELOAD environment variable if we can locate the # libpython<version>.so library. lib_python = os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('LDLIBRARY')) if os.path.exists(lib_python): context['ld_preload'] = 'LD_PRELOAD="{0}"; export LD_PRELOAD'.format(lib_python) for script in self.scripts: script = convert_path(script) outfile = os.path.join(self.build_dir, os.path.basename(script)) outfiles.append(outfile) if not self.force and not newer(script, outfile): log.debug("not copying %s (up-to-date)", script) continue # Always open the file, but ignore failures in dry-run mode -- # that way, we'll get accurate feedback if we can read the # script. try: f = open(script, "r") except IOError: if not self.dry_run: raise f = None log.info("copying and adjusting %s -> %s", script, self.build_dir) if not self.dry_run: outf = open(outfile, "w") outf.write(f.read().format(**context)) outf.close() if f: f.close() if os.name == 'posix': for file in outfiles: if self.dry_run: log.info("changing mode of %s", file) else: oldmode = os.stat(file)[ST_MODE] & 07777 newmode = (oldmode | 0555) & 07777 if newmode != oldmode: log.info("changing mode of %s from %o to %o", file, oldmode, newmode) os.chmod(file, newmode)