def bundle(self, app): bundledir = os.path.join(self.outdir, '%s-bundle' % app.basename) self.context.log.info('creating %s' % os.path.relpath(bundledir, get_buildroot())) safe_mkdir(bundledir, clean=True) classpath = OrderedSet() if not self.deployjar: libdir = os.path.join(bundledir, 'libs') os.mkdir(libdir) for basedir, externaljar in self.list_jar_dependencies(app.binary): src = os.path.join(basedir, externaljar) link_name = os.path.join(libdir, externaljar) try: os.symlink(src, link_name) except OSError as e: if e.errno == errno.EEXIST: raise TaskError('Trying to symlink %s to %s, but it is already symlinked to %s. ' % (link_name, src, os.readlink(link_name)) + 'Does the bundled target depend on multiple jvm_binary targets?') else: raise classpath.add(externaljar) for basedir, jars in self.context.products.get('jars').get(app.binary).items(): if len(jars) != 1: raise TaskError('Expected 1 mapped binary but found: %s' % jars) binary = jars.pop() binary_jar = os.path.join(basedir, binary) bundle_jar = os.path.join(bundledir, binary) if not classpath: os.symlink(binary_jar, bundle_jar) else: with open_zip(binary_jar, 'r') as src: with open_zip(bundle_jar, 'w', compression=ZIP_DEFLATED) as dest: for item in src.infolist(): buffer = src.read(item.filename) if Manifest.PATH == item.filename: manifest = Manifest(buffer) manifest.addentry(Manifest.CLASS_PATH, ' '.join(os.path.join('libs', jar) for jar in classpath)) buffer = manifest.contents() dest.writestr(item, buffer) for bundle in app.bundles: for path, relpath in bundle.filemap.items(): bundlepath = os.path.join(bundledir, relpath) safe_mkdir(os.path.dirname(bundlepath)) os.symlink(path, bundlepath) return bundledir
def create_binary(self, binary): import platform safe_mkdir(self.outdir) jarmap = self.context.products.get('jars') binary_jarname = '%s.jar' % binary.basename binaryjarpath = os.path.join(self.outdir, binary_jarname) self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot())) with open_jar(binaryjarpath, 'w', compression=self.compression, allowZip64=self.zip64) as jar: def add_jars(target): generated = jarmap.get(target) if generated: for basedir, jars in generated.items(): for internaljar in jars: self.dump(os.path.join(basedir, internaljar), jar) binary.walk(add_jars, is_internal) if self.deployjar: for basedir, externaljar in self.list_jar_dependencies(binary): self.dump(os.path.join(basedir, externaljar), jar) manifest = Manifest() manifest.addentry(Manifest.MANIFEST_VERSION, '1.0') manifest.addentry( Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version()) ) main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***' manifest.addentry(Manifest.MAIN_CLASS, main) jar.writestr(Manifest.PATH, manifest.contents()) jarmap.add(binary, self.outdir, [binary_jarname])
def bundle(self, app): bundledir = os.path.join(self.outdir, '%s-bundle' % app.basename) self.context.log.info('creating %s' % os.path.relpath(bundledir, get_buildroot())) safe_mkdir(bundledir, clean=True) classpath = OrderedSet() if not self.deployjar: libdir = os.path.join(bundledir, 'libs') os.mkdir(libdir) for basedir, externaljar in self.list_jar_dependencies(app.binary): path = os.path.join(basedir, externaljar) os.symlink(path, os.path.join(libdir, externaljar)) classpath.add(externaljar) for basedir, jars in self.context.products.get('jars').get( app.binary).items(): if len(jars) != 1: raise TaskError('Expected 1 mapped binary but found: %s' % jars) binary = jars.pop() binary_jar = os.path.join(basedir, binary) bundle_jar = os.path.join(bundledir, binary) if not classpath: os.symlink(binary_jar, bundle_jar) else: with open_zip(binary_jar, 'r') as src: with open_zip(bundle_jar, 'w', compression=ZIP_DEFLATED) as dest: for item in src.infolist(): buffer = src.read(item.filename) if Manifest.PATH == item.filename: manifest = Manifest(buffer) manifest.addentry( Manifest.CLASS_PATH, ' '.join( os.path.join('libs', jar) for jar in classpath)) buffer = manifest.contents() dest.writestr(item, buffer) for bundle in app.bundles: for path, relpath in bundle.filemap.items(): bundlepath = os.path.join(bundledir, relpath) safe_mkdir(os.path.dirname(bundlepath)) os.symlink(path, bundlepath) return bundledir
def bundle(self, app): bundledir = os.path.join(self.outdir, "%s-bundle" % app.basename) self.context.log.info("creating %s" % os.path.relpath(bundledir, get_buildroot())) safe_mkdir(bundledir, clean=True) classpath = OrderedSet() if not self.deployjar: libdir = os.path.join(bundledir, "libs") os.mkdir(libdir) for basedir, externaljar in self.list_jar_dependencies(app.binary): path = os.path.join(basedir, externaljar) os.symlink(path, os.path.join(libdir, externaljar)) classpath.add(externaljar) for basedir, jars in self.context.products.get("jars").get(app.binary).items(): if len(jars) != 1: raise TaskError("Expected 1 mapped binary but found: %s" % jars) binary = jars.pop() binary_jar = os.path.join(basedir, binary) bundle_jar = os.path.join(bundledir, binary) if not classpath: os.symlink(binary_jar, bundle_jar) else: with open_zip(binary_jar, "r") as src: with open_zip(bundle_jar, "w", compression=ZIP_DEFLATED) as dest: for item in src.infolist(): buffer = src.read(item.filename) if Manifest.PATH == item.filename: manifest = Manifest(buffer) manifest.addentry( Manifest.CLASS_PATH, " ".join(os.path.join("libs", jar) for jar in classpath) ) buffer = manifest.contents() dest.writestr(item, buffer) for bundle in app.bundles: for path, relpath in bundle.filemap.items(): bundlepath = os.path.join(bundledir, relpath) safe_mkdir(os.path.dirname(bundlepath)) os.symlink(path, bundlepath) return bundledir
def bundle(self, app): bundledir = os.path.join(self.outdir, '%s-bundle' % app.name) self.context.log.info('creating %s' % os.path.relpath(bundledir, get_buildroot())) safe_mkdir(bundledir, clean=True) libdir = os.path.join(bundledir, 'libs') os.mkdir(libdir) genmap = self.context.products.get('jar_dependencies') classpath = OrderedSet() def link_jar(target): generated = genmap.get(target) if generated: for basedir, jars in generated.items(): for jar in jars: if jar not in classpath: path = os.path.join(basedir, jar) os.symlink(path, os.path.join(libdir, jar)) classpath.add(jar) app.walk(link_jar, is_internal) for basedir, jars in self.context.products.get('jars').get(app.binary).items(): if len(jars) != 1: raise TaskError('Expected 1 mapped binary but found: %s' % jars) binary = jars.pop() with open_zip(os.path.join(basedir, binary), 'r') as src: with open_zip(os.path.join(bundledir, binary), 'w', compression=ZIP_DEFLATED) as dest: for item in src.infolist(): buffer = src.read(item.filename) if Manifest.PATH == item.filename: manifest = Manifest(buffer) manifest.addentry(Manifest.CLASS_PATH, ' '.join(os.path.join('libs', jar) for jar in classpath)) buffer = manifest.contents() dest.writestr(item, buffer) for bundle in app.bundles: for path, relpath in bundle.filemap.items(): bundlepath = os.path.join(bundledir, relpath) safe_mkdir(os.path.dirname(bundlepath)) os.symlink(path, bundlepath) return bundledir
def create_binary(self, binary): import platform safe_mkdir(self.outdir) jarmap = self.context.products.get('jars') binary_jarname = '%s.jar' % binary.basename binaryjarpath = os.path.join(self.outdir, binary_jarname) self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot())) with open_jar(binaryjarpath, 'w', compression=self.compression, allowZip64=self.zip64) as jar: def add_jars(target): generated = jarmap.get(target) if generated: for basedir, jars in generated.items(): for internaljar in jars: self.dump(os.path.join(basedir, internaljar), jar) binary.walk(add_jars, is_internal) if self.deployjar: for basedir, externaljar in self.list_jar_dependencies(binary): self.dump(os.path.join(basedir, externaljar), jar) manifest = Manifest() manifest.addentry(Manifest.MANIFEST_VERSION, '1.0') manifest.addentry( Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version())) main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***' manifest.addentry(Manifest.MAIN_CLASS, main) jar.writestr(Manifest.PATH, manifest.contents()) jarmap.add(binary, self.outdir, [binary_jarname])
def create_binary(self, binary): import platform safe_mkdir(self.outdir) jarmap = self.context.products.get('jars') jardepmap = self.context.products.get('jar_dependencies') if self.deployjar else None binary_jarname = '%s.jar' % binary.name binaryjarpath = os.path.join(self.outdir, binary_jarname) self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot())) with self.create_jar(binaryjarpath) as jar: externaljars = set() def add_jars(target): generated = jarmap.get(target) if generated: for basedir, jars in generated.items(): for internaljar in jars: self.dump(os.path.join(basedir, internaljar), jar) if jardepmap: resolved = jardepmap.get(target) if resolved: for basedir, jars in resolved.items(): for externaljar in jars: if externaljar not in externaljars: self.dump(os.path.join(basedir, externaljar), jar) externaljars.add(externaljar) binary.walk(add_jars, is_internal) manifest = Manifest() manifest.addentry(Manifest.MANIFEST_VERSION, '1.0') manifest.addentry( Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version()) ) manifest.addentry(Manifest.MAIN_CLASS, binary.main) jar.writestr(Manifest.PATH, manifest.contents()) jarmap.add(binary, self.outdir, [binary_jarname])