Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: native_client_sdk/src/tools/create_nmf.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/tools/create_html.py ('k') | native_client_sdk/src/tools/decode_dump.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tools/create_nmf.py
diff --git a/native_client_sdk/src/tools/create_nmf.py b/native_client_sdk/src/tools/create_nmf.py
index bf87979a6d4384aab0182525b48c69818b222004..de72408c4df141bbcac49f8255d724aa5f18beae 100755
--- a/native_client_sdk/src/tools/create_nmf.py
+++ b/native_client_sdk/src/tools/create_nmf.py
@@ -9,9 +9,9 @@ As well as creating the nmf file this tool can also find and stage
any shared libraries dependencies that the executables might have.
"""
+import argparse
import errno
import json
-import optparse
import os
import posixpath
import shutil
@@ -158,7 +158,7 @@ class ArchFile(object):
self.path = path
self.url = url
self.arch = arch
- if not arch:
+ if arch is None:
self.arch = ParseElfHeader(path)[0]
def __repr__(self):
@@ -402,7 +402,7 @@ class NmfUtils(object):
def GetManifest(self):
"""Returns a JSON-formatted dict containing the NaCl dependencies"""
- if not self.manifest:
+ if self.manifest is None:
if self.pnacl:
self._GeneratePNaClManifest()
else:
@@ -541,60 +541,60 @@ def GetDefaultLibPath(config):
return libpath
-def main(argv):
- parser = optparse.OptionParser(
- usage='Usage: %prog [options] nexe [extra_libs...]', description=__doc__)
- parser.add_option('-o', '--output', dest='output',
- help='Write manifest file to FILE (default is stdout)',
- metavar='FILE')
- parser.add_option('-D', '--objdump', dest='objdump',
- help='Override the default "objdump" tool used to find '
- 'shared object dependencies',
- metavar='TOOL')
- parser.add_option('--no-default-libpath', action='store_true',
- help="Don't include the SDK default library paths")
- parser.add_option('--debug-libs', action='store_true',
- help='Use debug library paths when constructing default '
- 'library path.')
- parser.add_option('-L', '--library-path', dest='lib_path',
- action='append', default=[],
- help='Add DIRECTORY to library search path',
- metavar='DIRECTORY')
- parser.add_option('-P', '--path-prefix', dest='path_prefix', default='',
- help='Deprecated. An alias for --lib-prefix.',
- metavar='DIRECTORY')
- parser.add_option('-p', '--lib-prefix', dest='lib_prefix', default='',
- help='A path to prepend to shared libraries in the .nmf',
- metavar='DIRECTORY')
- parser.add_option('-N', '--nexe-prefix', dest='nexe_prefix', default='',
- help='A path to prepend to nexes in the .nmf',
- metavar='DIRECTORY')
- parser.add_option('-s', '--stage-dependencies', dest='stage_dependencies',
- help='Destination directory for staging libraries',
- metavar='DIRECTORY')
- parser.add_option('--no-arch-prefix', action='store_true',
- help='Don\'t put shared libraries in the lib32/lib64 '
- 'directories. Instead, they will be put in the same '
- 'directory as the .nexe that matches its architecture.')
- parser.add_option('-t', '--toolchain', help='Legacy option, do not use')
- parser.add_option('-n', '--name', dest='name',
- help='Rename FOO as BAR',
- action='append', default=[], metavar='FOO,BAR')
- parser.add_option('-x', '--extra-files',
- help=('Add extra key:file tuple to the "files"' +
- ' section of the .nmf'),
- action='append', default=[], metavar='FILE')
- parser.add_option('-O', '--pnacl-optlevel',
- help='Set the optimization level to N in PNaCl manifests',
- metavar='N')
- parser.add_option('--pnacl-debug-optlevel',
- help='Set the optimization level to N for debugging '
- 'sections in PNaCl manifests',
- metavar='N')
- parser.add_option('-v', '--verbose',
- help='Verbose output', action='store_true')
- parser.add_option('-d', '--debug-mode',
- help='Debug mode', action='store_true')
+def main(args):
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('-o', '--output', dest='output',
+ help='Write manifest file to FILE (default is stdout)',
+ metavar='FILE')
+ parser.add_argument('-D', '--objdump', dest='objdump',
+ help='Override the default "objdump" tool used to find '
+ 'shared object dependencies',
+ metavar='TOOL')
+ parser.add_argument('--no-default-libpath', action='store_true',
+ help="Don't include the SDK default library paths")
+ parser.add_argument('--debug-libs', action='store_true',
+ help='Use debug library paths when constructing default '
+ 'library path.')
+ parser.add_argument('-L', '--library-path', dest='lib_path',
+ action='append', default=[],
+ help='Add DIRECTORY to library search path',
+ metavar='DIRECTORY')
+ parser.add_argument('-P', '--path-prefix', dest='path_prefix', default='',
+ help='Deprecated. An alias for --lib-prefix.',
+ metavar='DIRECTORY')
+ parser.add_argument('-p', '--lib-prefix', dest='lib_prefix', default='',
+ help='A path to prepend to shared libraries in the .nmf',
+ metavar='DIRECTORY')
+ parser.add_argument('-N', '--nexe-prefix', dest='nexe_prefix', default='',
+ help='A path to prepend to nexes in the .nmf',
+ metavar='DIRECTORY')
+ parser.add_argument('-s', '--stage-dependencies', dest='stage_dependencies',
+ help='Destination directory for staging libraries',
+ metavar='DIRECTORY')
+ parser.add_argument('--no-arch-prefix', action='store_true',
+ help='Don\'t put shared libraries in the lib32/lib64 '
+ 'directories. Instead, they will be put in the same '
+ 'directory as the .nexe that matches its architecture.')
+ parser.add_argument('-t', '--toolchain', help='Legacy option, do not use')
+ parser.add_argument('-n', '--name', dest='name',
+ help='Rename FOO as BAR',
+ action='append', default=[], metavar='FOO,BAR')
+ parser.add_argument('-x', '--extra-files',
+ help=('Add extra key:file tuple to the "files"' +
+ ' section of the .nmf'),
+ action='append', default=[], metavar='FILE')
+ parser.add_argument('-O', '--pnacl-optlevel',
+ help='Set the optimization level to N in PNaCl manifests',
+ metavar='N')
+ parser.add_argument('--pnacl-debug-optlevel',
+ help='Set the optimization level to N for debugging '
+ 'sections in PNaCl manifests',
+ metavar='N')
+ parser.add_argument('-v', '--verbose',
+ help='Verbose output', action='store_true')
+ parser.add_argument('-d', '--debug-mode',
+ help='Debug mode', action='store_true')
+ parser.add_argument('executables', metavar='EXECUTABLE', nargs='+')
# To enable bash completion for this command first install optcomplete
# and then add this line to your .bashrc:
@@ -605,7 +605,7 @@ def main(argv):
except ImportError:
pass
- options, args = parser.parse_args(argv)
+ options = parser.parse_args(args)
if options.verbose:
Trace.verbose = True
if options.debug_mode:
@@ -614,9 +614,6 @@ def main(argv):
if options.toolchain is not None:
sys.stderr.write('warning: option -t/--toolchain is deprecated.\n')
- if len(args) < 1:
- parser.error('No nexe files specified. See --help for more info')
-
canonicalized = ParseExtraFiles(options.extra_files, sys.stderr)
if canonicalized is None:
parser.error('Bad --extra-files (-x) argument syntax')
@@ -661,7 +658,7 @@ def main(argv):
nmf_root = os.path.dirname(options.output)
nmf = NmfUtils(objdump=options.objdump,
- main_files=args,
+ main_files=options.executables,
lib_path=options.lib_path,
extra_files=canonicalized,
lib_prefix=options.lib_prefix,
« no previous file with comments | « native_client_sdk/src/tools/create_html.py ('k') | native_client_sdk/src/tools/decode_dump.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698