Skip to content

Commit

Permalink
flag works
Browse files Browse the repository at this point in the history
  • Loading branch information
wisechengyi committed Jul 18, 2018
1 parent f9136a9 commit 883d13a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,14 @@ def main(args=None):
log('Saving PEX file to %s' % options.pex_name, v=options.verbosity)
tmp_name = options.pex_name + '~'
safe_delete(tmp_name)
pex_builder.build(tmp_name)
pex_builder.build(tmp_name, verify_entry_point=options.validate_ep)
os.rename(tmp_name, options.pex_name)
return 0

if not _compatible_with_current_platform(options.platforms):
log('WARNING: attempting to run PEX with incompatible platforms!')

pex_builder.freeze()
pex_builder.freeze(verify_entry_point=options.validate_ep)

log('Running PEX file at %s with args %s' % (pex_builder.path(), cmdline), v=options.verbosity)
pex = PEX(pex_builder.path(), interpreter=pex_builder.interpreter)
Expand Down
12 changes: 7 additions & 5 deletions pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def set_script(self, script):
'Could not find script %r in any distribution %s within PEX!' % (
script, ', '.join(str(d) for d in self._distributions)))

def _verify_entry_point(self, entry_point):
def _verify_entry_point(self):
"""
Given entry_point `a.b.c:m`, make sure
1. a/b/c.py exists
Expand All @@ -236,6 +236,7 @@ def _verify_entry_point(self, entry_point):
:return:
"""

entry_point = self._pex_info.entry_point
ep_split = entry_point.split(':')

# Only module is specified
Expand Down Expand Up @@ -290,7 +291,6 @@ def set_entry_point(self, entry_point):
The entry point may also be specified via ``PEXBuilder.set_executable``.
"""
self._ensure_unfrozen('Setting an entry point')
self._verify_entry_point(entry_point)
self._pex_info.entry_point = entry_point

def set_shebang(self, shebang):
Expand Down Expand Up @@ -494,7 +494,7 @@ def _prepare_bootstrap(self):
self._chroot.write(provider.get_resource_string(source_name, fn),
os.path.join(self.BOOTSTRAP_DIR, target_location, fn), 'bootstrap')

def freeze(self, bytecode_compile=True):
def freeze(self, verify_entry_point, bytecode_compile=True):
"""Freeze the PEX.
:param bytecode_compile: If True, precompile .py files into .pyc files when freezing code.
Expand All @@ -508,11 +508,13 @@ def freeze(self, bytecode_compile=True):
self._prepare_manifest()
self._prepare_bootstrap()
self._prepare_main()
if verify_entry_point:
self._verify_entry_point()
if bytecode_compile:
self._precompile_source()
self._frozen = True

def build(self, filename, bytecode_compile=True):
def build(self, filename, bytecode_compile=True, verify_entry_point=False):
"""Package the PEX into a zipfile.
:param filename: The filename where the PEX should be stored.
Expand All @@ -522,7 +524,7 @@ def build(self, filename, bytecode_compile=True):
PEXBuilder immutable.
"""
if not self._frozen:
self.freeze(bytecode_compile=bytecode_compile)
self.freeze(verify_entry_point=verify_entry_point, bytecode_compile=bytecode_compile)
try:
os.unlink(filename + '~')
self._logger.warn('Previous binary unexpectedly exists, cleaning: %s' % (filename + '~'))
Expand Down

0 comments on commit 883d13a

Please sign in to comment.