comparison mx/mx_graal.py @ 21518:c2e58b2a2a76

Extract options file to build
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 18 May 2015 18:30:43 +0200
parents b426469fadb7
children b7ac67354c14
comparison
equal deleted inserted replaced
21517:4cc6793cda69 21518:c2e58b2a2a76
663 for className in classNames: 663 for className in classNames:
664 if classification[className] is True: 664 if classification[className] is True:
665 filtered.append(className) 665 filtered.append(className)
666 return filtered 666 return filtered
667 667
668 def _extractGraalServiceFiles(graalJars, destination, cleanDestination=True): 668 def _extractGraalFiles(graalJars, servicesDir, optionsDir, cleanDestination=True):
669 if cleanDestination: 669 if cleanDestination:
670 if exists(destination): 670 if exists(servicesDir):
671 shutil.rmtree(destination) 671 shutil.rmtree(servicesDir)
672 os.makedirs(destination) 672 if exists(optionsDir):
673 shutil.rmtree(optionsDir)
674 if not exists(servicesDir):
675 os.makedirs(servicesDir)
676 if not exists(optionsDir):
677 os.makedirs(optionsDir)
673 servicesMap = {} 678 servicesMap = {}
679 optionsFiles = []
674 for jar in graalJars: 680 for jar in graalJars:
675 if os.path.isfile(jar): 681 if os.path.isfile(jar):
676 with zipfile.ZipFile(jar) as zf: 682 with zipfile.ZipFile(jar) as zf:
677 for member in zf.namelist(): 683 for member in zf.namelist():
678 if not member.startswith('META-INF/services'): 684 if member.startswith('META-INF/services'):
679 continue 685 serviceName = basename(member)
680 serviceName = basename(member) 686 # we don't handle directories
681 # we don't handle directories 687 assert serviceName and member == 'META-INF/services/' + serviceName
682 assert serviceName and member == 'META-INF/services/' + serviceName 688 with zf.open(member) as serviceFile:
683 with zf.open(member) as serviceFile: 689 serviceImpls = servicesMap.setdefault(serviceName, [])
684 serviceImpls = servicesMap.setdefault(serviceName, []) 690 for line in serviceFile.readlines():
685 for line in serviceFile.readlines(): 691 line = line.strip()
686 line = line.strip() 692 if line:
687 if line: 693 serviceImpls.append(line)
688 serviceImpls.append(line) 694 elif member.startswith('META-INF/options'):
695 filename = basename(member)
696 # we don't handle directories
697 assert filename and member == 'META-INF/options/' + filename
698 targetpath = join(optionsDir, filename)
699 optionsFiles.append(filename)
700 with zf.open(member) as optionsFile, \
701 file(targetpath, "wb") as target:
702 shutil.copyfileobj(optionsFile, target)
689 graalServices = _filterGraalService(servicesMap.keys(), graalJars) 703 graalServices = _filterGraalService(servicesMap.keys(), graalJars)
690 for serviceName in graalServices: 704 for serviceName in graalServices:
691 serviceImpls = servicesMap[serviceName] 705 serviceImpls = servicesMap[serviceName]
692 fd, tmp = tempfile.mkstemp(prefix=serviceName) 706 fd, tmp = tempfile.mkstemp(prefix=serviceName)
693 f = os.fdopen(fd, 'w+') 707 f = os.fdopen(fd, 'w+')
694 for serviceImpl in serviceImpls: 708 for serviceImpl in serviceImpls:
695 f.write(serviceImpl + os.linesep) 709 f.write(serviceImpl + os.linesep)
696 target = join(destination, serviceName) 710 target = join(servicesDir, serviceName)
697 f.close() 711 f.close()
698 shutil.move(tmp, target) 712 shutil.move(tmp, target)
699 if mx.get_os() != 'windows': 713 if mx.get_os() != 'windows':
700 os.chmod(target, JDK_UNIX_PERMISSIONS_FILE) 714 os.chmod(target, JDK_UNIX_PERMISSIONS_FILE)
701 return graalServices 715 return (graalServices, optionsFiles)
702 716
703 def _updateGraalServiceFiles(jdkDir): 717 def _updateGraalFiles(jdkDir):
704 jreGraalDir = join(jdkDir, 'jre', 'lib', 'graal') 718 jreGraalDir = join(jdkDir, 'jre', 'lib', 'graal')
705 graalJars = [join(jreGraalDir, e) for e in os.listdir(jreGraalDir) if e.startswith('graal') and e.endswith('.jar')] 719 graalJars = [join(jreGraalDir, e) for e in os.listdir(jreGraalDir) if e.startswith('graal') and e.endswith('.jar')]
706 jreGraalServicesDir = join(jreGraalDir, 'services') 720 jreGraalServicesDir = join(jreGraalDir, 'services')
707 _extractGraalServiceFiles(graalJars, jreGraalServicesDir) 721 jreGraalOptionsDir = join(jreGraalDir, 'options')
722 _extractGraalFiles(graalJars, jreGraalServicesDir, jreGraalOptionsDir)
708 723
709 724
710 725
711 def _installDistInJdks(deployableDist): 726 def _installDistInJdks(deployableDist):
712 """ 727 """
741 _copyToJdk(dist.path, targetDir) 756 _copyToJdk(dist.path, targetDir)
742 if dist.sourcesPath: 757 if dist.sourcesPath:
743 _copyToJdk(dist.sourcesPath, jdkDir) 758 _copyToJdk(dist.sourcesPath, jdkDir)
744 if deployableDist.isGraalClassLoader: 759 if deployableDist.isGraalClassLoader:
745 # deploy service files 760 # deploy service files
746 _updateGraalServiceFiles(jdkDir) 761 _updateGraalFiles(jdkDir)
747 762
748 # run a command in the windows SDK Debug Shell 763 # run a command in the windows SDK Debug Shell
749 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo=None): 764 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo=None):
750 if respondTo is None: 765 if respondTo is None:
751 respondTo = {} 766 respondTo = {}
916 else: 931 else:
917 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path) 932 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path)
918 if defLine not in defs: 933 if defLine not in defs:
919 mx.abort('Missing following line in ' + defsPath + '\n' + defLine) 934 mx.abort('Missing following line in ' + defsPath + '\n' + defLine)
920 shutil.copy(dist.path, opts2.export_dir) 935 shutil.copy(dist.path, opts2.export_dir)
921 services = _extractGraalServiceFiles(graalJars, join(opts2.export_dir, 'services')) 936 services, optionsFiles = _extractGraalFiles(graalJars, join(opts2.export_dir, 'services'), join(opts2.export_dir, 'options'))
922 for service in services: 937 for service in services:
923 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_GRAAL_SERVICES_DIR)/' + service 938 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_GRAAL_SERVICES_DIR)/' + service
924 if defLine not in defs: 939 if defLine not in defs:
925 mx.abort('Missing following line in ' + defsPath + ' for service from ' + dist.name + '\n' + defLine) 940 mx.abort('Missing following line in ' + defsPath + ' for service from ' + dist.name + '\n' + defLine)
941 for optionsFile in optionsFiles:
942 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_GRAAL_OPTIONS_DIR)/' + optionsFile
943 if defLine not in defs:
944 mx.abort('Missing following line in ' + defsPath + ' for options from ' + dist.name + '\n' + defLine)
926 graalOptions = join(_graal_home, 'graal.options') 945 graalOptions = join(_graal_home, 'graal.options')
927 if exists(graalOptions): 946 if exists(graalOptions):
928 shutil.copy(graalOptions, opts2.export_dir) 947 shutil.copy(graalOptions, opts2.export_dir)
929 948
930 if not _vmSourcesAvailable or not opts2.native: 949 if not _vmSourcesAvailable or not opts2.native: