Skip to content

Commit

Permalink
added workunits to create_binary, added 'b' literal prefix for unicod…
Browse files Browse the repository at this point in the history
…e class names in archive.py

Testing Done:
compiled my project with --binary-deployjar  that includes cucumber libs with unicode character classnames.

Bugs closed: 109

Reviewed at https://rbcommons.com/s/twitter/r/318/
  • Loading branch information
ericzundel authored and John Sirois committed May 7, 2014
1 parent 167dda7 commit 06a4c2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/python/pants/fs/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def extract(cls, path, outdir):
with open_zip(path) as zip:
for path in zip.namelist():
# While we're at it, we also perform this safety test.
if path.startswith('/') or path.startswith('..'):
if path.startswith(b'/') or path.startswith(b'..'):
raise ValueError('Zip file contains unsafe path: %s' % path)
# Ignore directories. extract() will create parent dirs as needed.
if not path.endswith('/'):
if not path.endswith(b'/'):
zip.extract(path, outdir)

def __init__(self, compression):
Expand Down
50 changes: 27 additions & 23 deletions src/python/pants/tasks/binary_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def setup_parser(cls, option_group, args, mkflag):
def __init__(self, context, workdir):
super(BinaryCreate, self).__init__(context, workdir)

self.context = context
self.outdir = os.path.abspath(
context.options.jvm_binary_create_outdir or
context.config.get('binary-create', 'outdir',
self.context.options.jvm_binary_create_outdir or
self.context.config.get('binary-create', 'outdir',
default=context.config.getdefault('pants_distdir'))
)
self.compression = ZIP_DEFLATED if context.options.binary_create_compressed else ZIP_STORED
Expand All @@ -48,10 +49,9 @@ def __init__(self, context, workdir):
or context.config.getbool('binary-create', 'zip64', default=False)
)
self.deployjar = context.options.jvm_binary_create_deployjar

context.products.require('jars', predicate=self.is_binary)
context.products.require_data('classes_by_target')
context.products.require_data('resources_by_target')
self.context.products.require('jars', predicate=self.is_binary)
self.context.products.require_data('classes_by_target')
self.context.products.require_data('resources_by_target')
if self.deployjar:
self.require_jar_dependencies()

Expand All @@ -77,11 +77,13 @@ def add_jars(target):
for internaljar in jars:
self.dump(os.path.join(basedir, internaljar), jar)

binary.walk(add_jars, lambda t: t.is_internal)
with self.context.new_workunit(name='add-generated-jars'):
binary.walk(add_jars, lambda t: t.is_internal)

if self.deployjar:
for basedir, externaljar in self.list_jar_dependencies(binary):
self.dump(os.path.join(basedir, externaljar), jar)
with self.context.new_workunit(name='add-dependency-jars'):
for basedir, externaljar in self.list_jar_dependencies(binary):
self.dump(os.path.join(basedir, externaljar), jar)

def write_binary_data(product_type):
data = self.context.products.get_data(product_type).get(binary)
Expand All @@ -90,20 +92,22 @@ def write_binary_data(product_type):
for rel_path in rel_paths:
jar.write(os.path.join(root, rel_path), arcname=rel_path)

write_binary_data('classes_by_target')
write_binary_data('resources_by_target')

manifest = Manifest()
manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
manifest.addentry(
Manifest.CREATED_BY,
'python %s pants %s' % (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])
with self.context.new_workunit(name='add-binary-data'):
write_binary_data('classes_by_target')
write_binary_data('resources_by_target')

with self.context.new_workunit(name='add-manifest'):
manifest = Manifest()
manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
manifest.addentry(
Manifest.CREATED_BY,
'python %s pants %s' % (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 dump(self, jarpath, jarfile):
self.context.log.debug(' dumping %s' % jarpath)
Expand Down

0 comments on commit 06a4c2d

Please sign in to comment.