Mercurial > hg > graal-jvmci-8
comparison mx/mx_graal.py @ 21937:3a292e8b9e51
replaced Service marker interface with non-standard META-INF directory names to differentiate JVMCI providers from standard service providers
META-INF/services/ files for Options provider are now generated directly from files in META-INF/jvmci.options/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 12 Jun 2015 01:19:57 +0200 |
parents | 11f241f26c61 |
children | 95956bc1b1a3 |
comparison
equal
deleted
inserted
replaced
21936:11f241f26c61 | 21937:3a292e8b9e51 |
---|---|
548 shutil.copyfile(src, tmp) | 548 shutil.copyfile(src, tmp) |
549 os.close(fd) | 549 os.close(fd) |
550 shutil.move(tmp, dstLib) | 550 shutil.move(tmp, dstLib) |
551 os.chmod(dstLib, permissions) | 551 os.chmod(dstLib, permissions) |
552 | 552 |
553 def _filterJVMCIServices(servicesMap, classpath): | 553 def _extractJVMCIFiles(jdkJars, jvmciJars, servicesDir, optionsDir): |
554 """ | 554 if exists(servicesDir): |
555 Filters and returns the names in 'serviceImplNames' that denote | 555 shutil.rmtree(servicesDir) |
556 types available in 'classpath' implementing or extending | 556 if exists(optionsDir): |
557 com.oracle.jvmci.service.Service. | 557 shutil.rmtree(optionsDir) |
558 """ | |
559 _, binDir = mx._compile_mx_class('FilterTypes', os.pathsep.join(classpath), myDir=dirname(__file__)) | |
560 serialized = [k + '=' + ','.join(v) for k, v in servicesMap.iteritems()] | |
561 cmd = [mx.java().java, '-cp', mx._cygpathU2W(os.pathsep.join([binDir] + classpath)), 'FilterTypes', 'com.oracle.jvmci.service.Service'] + serialized | |
562 serialized = subprocess.check_output(cmd) | |
563 if len(serialized) == 0: | |
564 return {} | |
565 servicesMap = {} | |
566 for e in serialized.split(' '): | |
567 k, v = e.split('=') | |
568 impls = v.split(',') | |
569 servicesMap[k] = impls | |
570 return servicesMap | |
571 | |
572 def _extractJVMCIFiles(jdkJars, jvmciJars, servicesDir, optionsDir, cleanDestination=True): | |
573 if cleanDestination: | |
574 if exists(servicesDir): | |
575 shutil.rmtree(servicesDir) | |
576 if exists(optionsDir): | |
577 shutil.rmtree(optionsDir) | |
578 if not exists(servicesDir): | 558 if not exists(servicesDir): |
579 os.makedirs(servicesDir) | 559 os.makedirs(servicesDir) |
580 if not exists(optionsDir): | 560 if not exists(optionsDir): |
581 os.makedirs(optionsDir) | 561 os.makedirs(optionsDir) |
582 servicesMap = {} | 562 jvmciServices = {} |
583 optionsFiles = [] | 563 optionsFiles = [] |
584 for jar in jvmciJars: | 564 for jar in jvmciJars: |
585 if os.path.isfile(jar): | 565 if os.path.isfile(jar): |
586 with zipfile.ZipFile(jar) as zf: | 566 with zipfile.ZipFile(jar) as zf: |
587 for member in zf.namelist(): | 567 for member in zf.namelist(): |
588 if member.startswith('META-INF/services') and member: | 568 if member.startswith('META-INF/jvmci.services') and member: |
589 serviceName = basename(member) | 569 service = basename(member) |
590 if serviceName == "": | 570 if service == "": |
591 continue # Zip files may contain empty entries for directories (jar -cf ... creates such) | 571 continue # Zip files may contain empty entries for directories (jar -cf ... creates such) |
592 # we don't handle directories | 572 # we don't handle directories |
593 assert serviceName and member == 'META-INF/services/' + serviceName | 573 assert service and member == 'META-INF/jvmci.services/' + service |
594 with zf.open(member) as serviceFile: | 574 with zf.open(member) as serviceFile: |
595 serviceImpls = servicesMap.setdefault(serviceName, []) | 575 providers = jvmciServices.setdefault(service, []) |
596 for line in serviceFile.readlines(): | 576 for line in serviceFile.readlines(): |
597 line = line.strip() | 577 line = line.strip() |
598 if line: | 578 if line: |
599 serviceImpls.append(line) | 579 providers.append(line) |
600 elif member.startswith('META-INF/options'): | 580 elif member.startswith('META-INF/jvmci.options'): |
601 filename = basename(member) | 581 filename = basename(member) |
602 if filename == "": | 582 if filename == "": |
603 continue # Zip files may contain empty entries for directories (jar -cf ... creates such) | 583 continue # Zip files may contain empty entries for directories (jar -cf ... creates such) |
604 # we don't handle directories | 584 # we don't handle directories |
605 assert filename and member == 'META-INF/options/' + filename | 585 assert filename and member == 'META-INF/jvmci.options/' + filename |
606 targetpath = join(optionsDir, filename) | 586 targetpath = join(optionsDir, filename) |
607 optionsFiles.append(filename) | 587 optionsFiles.append(filename) |
608 with zf.open(member) as optionsFile, \ | 588 with zf.open(member) as optionsFile, \ |
609 file(targetpath, "wb") as target: | 589 file(targetpath, "wb") as target: |
610 shutil.copyfileobj(optionsFile, target) | 590 shutil.copyfileobj(optionsFile, target) |
611 servicesMap = _filterJVMCIServices(servicesMap, jdkJars) | 591 for service, providers in jvmciServices.iteritems(): |
612 for serviceName, serviceImpls in servicesMap.iteritems(): | 592 fd, tmp = tempfile.mkstemp(prefix=service) |
613 fd, tmp = tempfile.mkstemp(prefix=serviceName) | |
614 f = os.fdopen(fd, 'w+') | 593 f = os.fdopen(fd, 'w+') |
615 for serviceImpl in serviceImpls: | 594 for provider in providers: |
616 f.write(serviceImpl + os.linesep) | 595 f.write(provider + os.linesep) |
617 target = join(servicesDir, serviceName) | 596 target = join(servicesDir, service) |
618 f.close() | 597 f.close() |
619 shutil.move(tmp, target) | 598 shutil.move(tmp, target) |
620 if mx.get_os() != 'windows': | 599 if mx.get_os() != 'windows': |
621 os.chmod(target, JDK_UNIX_PERMISSIONS_FILE) | 600 os.chmod(target, JDK_UNIX_PERMISSIONS_FILE) |
622 | 601 |