OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from __future__ import with_statement | 6 from __future__ import with_statement |
7 | 7 |
8 import errno | 8 import errno |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 class NmfUtils(object): | 87 class NmfUtils(object): |
88 '''Helper class for creating and managing nmf files | 88 '''Helper class for creating and managing nmf files |
89 | 89 |
90 Attributes: | 90 Attributes: |
91 manifest: A JSON-structured dict containing the nmf structure | 91 manifest: A JSON-structured dict containing the nmf structure |
92 needed: A dict with key=filename and value=ArchFile (see GetNeeded) | 92 needed: A dict with key=filename and value=ArchFile (see GetNeeded) |
93 ''' | 93 ''' |
94 | 94 |
95 def __init__(self, main_files=None, objdump='x86_64-nacl-objdump', | 95 def __init__(self, main_files=None, objdump='x86_64-nacl-objdump', |
96 lib_path=None, extra_files=None, lib_prefix=None, | 96 lib_path=None, extra_files=None, lib_prefix=None, |
97 toolchain=None): | 97 toolchain=None, remap={}): |
98 ''' Constructor | 98 ''' Constructor |
99 | 99 |
100 Args: | 100 Args: |
101 main_files: List of main entry program files. These will be named | 101 main_files: List of main entry program files. These will be named |
102 files->main.nexe for dynamic nexes, and program for static nexes | 102 files->main.nexe for dynamic nexes, and program for static nexes |
103 objdump: path to x86_64-nacl-objdump tool (or Linux equivalent) | 103 objdump: path to x86_64-nacl-objdump tool (or Linux equivalent) |
104 lib_path: List of paths to library directories | 104 lib_path: List of paths to library directories |
105 extra_files: List of extra files to include in the nmf | 105 extra_files: List of extra files to include in the nmf |
106 lib_prefix: A list of path components to prepend to the library paths, | 106 lib_prefix: A list of path components to prepend to the library paths, |
107 both for staging the libraries and for inclusion into the nmf file. | 107 both for staging the libraries and for inclusion into the nmf file. |
108 Examples: ['..'], ['lib_dir'] | 108 Examples: ['..'], ['lib_dir'] |
109 toolchain: Specify which toolchain newlib|glibc|pnacl which can require | 109 toolchain: Specify which toolchain newlib|glibc|pnacl which can require |
110 different forms of the NMF.''' | 110 different forms of the NMF. |
111 remap: Remaps the library name in the manifest. | |
112 ''' | |
111 self.objdump = objdump | 113 self.objdump = objdump |
112 self.main_files = main_files or [] | 114 self.main_files = main_files or [] |
113 self.extra_files = extra_files or [] | 115 self.extra_files = extra_files or [] |
114 self.lib_path = lib_path or [] | 116 self.lib_path = lib_path or [] |
115 self.manifest = None | 117 self.manifest = None |
116 self.needed = None | 118 self.needed = None |
117 self.lib_prefix = lib_prefix or [] | 119 self.lib_prefix = lib_prefix or [] |
118 self.toolchain = toolchain | 120 self.toolchain = toolchain |
121 self.remap = remap | |
119 | 122 |
120 | 123 |
121 def GleanFromObjdump(self, files): | 124 def GleanFromObjdump(self, files): |
122 '''Get architecture and dependency information for given files | 125 '''Get architecture and dependency information for given files |
123 | 126 |
124 Args: | 127 Args: |
125 files: A dict with key=filename and value=list or set of archs. E.g.: | 128 files: A dict with key=filename and value=list or set of archs. E.g.: |
126 { '/path/to/my.nexe': ['x86-32'] | 129 { '/path/to/my.nexe': ['x86-32'] |
127 '/path/to/lib64/libmy.so': ['x86-64'], | 130 '/path/to/lib64/libmy.so': ['x86-64'], |
128 '/path/to/mydata.so': ['x86-32', 'x86-64'], | 131 '/path/to/mydata.so': ['x86-32', 'x86-64'], |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 # We assume that the nexe and the corresponding nmf file are | 275 # We assume that the nexe and the corresponding nmf file are |
273 # installed in the same directory. | 276 # installed in the same directory. |
274 urlinfo[URL_KEY] = os.path.basename(urlinfo[URL_KEY]) | 277 urlinfo[URL_KEY] = os.path.basename(urlinfo[URL_KEY]) |
275 # Place it under program if we aren't using the runnable-ld.so. | 278 # Place it under program if we aren't using the runnable-ld.so. |
276 if not runnable: | 279 if not runnable: |
277 manifest[PROGRAM_KEY][archinfo.arch] = urlinfo | 280 manifest[PROGRAM_KEY][archinfo.arch] = urlinfo |
278 continue | 281 continue |
279 # Otherwise, treat it like another another file named main.nexe. | 282 # Otherwise, treat it like another another file named main.nexe. |
280 name = MAIN_NEXE | 283 name = MAIN_NEXE |
281 | 284 |
285 name = self.remap.get(name, name) | |
282 fileinfo = manifest[FILES_KEY].get(name, {}) | 286 fileinfo = manifest[FILES_KEY].get(name, {}) |
283 fileinfo[archinfo.arch] = urlinfo | 287 fileinfo[archinfo.arch] = urlinfo |
284 manifest[FILES_KEY][name] = fileinfo | 288 manifest[FILES_KEY][name] = fileinfo |
289 print 'need=' + str(need) | |
binji
2012/06/11 20:22:29
debug spew?
noelallen1
2012/06/11 20:34:38
Done.
| |
290 print 'name=' + str(name) | |
285 self.manifest = manifest | 291 self.manifest = manifest |
286 | 292 |
287 def GetManifest(self): | 293 def GetManifest(self): |
288 '''Returns a JSON-formatted dict containing the NaCl dependencies''' | 294 '''Returns a JSON-formatted dict containing the NaCl dependencies''' |
289 if not self.manifest: | 295 if not self.manifest: |
290 self._GenerateManifest() | 296 self._GenerateManifest() |
291 | 297 |
292 return self.manifest | 298 return self.manifest |
293 | 299 |
294 def GetJson(self): | 300 def GetJson(self): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 metavar='DIRECTORY') | 339 metavar='DIRECTORY') |
334 parser.add_option('-s', '--stage-dependencies', dest='stage_dependencies', | 340 parser.add_option('-s', '--stage-dependencies', dest='stage_dependencies', |
335 help='Destination directory for staging libraries', | 341 help='Destination directory for staging libraries', |
336 metavar='DIRECTORY') | 342 metavar='DIRECTORY') |
337 parser.add_option('-r', '--remove', dest='remove', | 343 parser.add_option('-r', '--remove', dest='remove', |
338 help='Remove the prefix from the files.', | 344 help='Remove the prefix from the files.', |
339 metavar='PATH') | 345 metavar='PATH') |
340 parser.add_option('-t', '--toolchain', dest='toolchain', | 346 parser.add_option('-t', '--toolchain', dest='toolchain', |
341 help='Add DIRECTORY to library search path', | 347 help='Add DIRECTORY to library search path', |
342 default=None, metavar='TOOLCHAIN') | 348 default=None, metavar='TOOLCHAIN') |
349 parser.add_option('-n', '--name', dest='name', | |
350 help='Rename FOO as BAR', | |
351 action='append', default=[], metavar='FOO,BAR') | |
343 (options, args) = parser.parse_args(argv) | 352 (options, args) = parser.parse_args(argv) |
344 | 353 |
345 if not options.toolchain: | 354 if not options.toolchain: |
346 options.toolchain = DetermineToolchain(os.path.abspath(options.objdump)) | 355 options.toolchain = DetermineToolchain(os.path.abspath(options.objdump)) |
347 | 356 |
348 if options.toolchain not in ['newlib', 'glibc']: | 357 if options.toolchain not in ['newlib', 'glibc']: |
349 ErrorOut('Unknown toolchain: ' + str(options.toolchain)) | 358 ErrorOut('Unknown toolchain: ' + str(options.toolchain)) |
350 | 359 |
351 if len(args) < 1: | 360 if len(args) < 1: |
352 parser.print_usage() | 361 parser.print_usage() |
353 sys.exit(1) | 362 sys.exit(1) |
354 | 363 |
364 remap = {} | |
365 for ren in options.name: | |
366 parts = ren.split(',') | |
367 if len(parts) != 2: | |
368 ErrorOut('Expecting --name=<orig_arch.so>,<new_name.so>') | |
369 remap[parts[0]] = parts[1] | |
370 | |
355 nmf = NmfUtils(objdump=options.objdump, | 371 nmf = NmfUtils(objdump=options.objdump, |
356 main_files=args, | 372 main_files=args, |
357 lib_path=options.lib_path, | 373 lib_path=options.lib_path, |
358 toolchain=options.toolchain) | 374 toolchain=options.toolchain, |
375 remap=remap) | |
359 | 376 |
360 manifest = nmf.GetManifest() | 377 manifest = nmf.GetManifest() |
361 if options.output is None: | 378 if options.output is None: |
362 sys.stdout.write(nmf.GetJson()) | 379 sys.stdout.write(nmf.GetJson()) |
363 else: | 380 else: |
364 with open(options.output, 'w') as output: | 381 with open(options.output, 'w') as output: |
365 output.write(nmf.GetJson()) | 382 output.write(nmf.GetJson()) |
366 | 383 |
367 if options.stage_dependencies: | 384 if options.stage_dependencies: |
368 nmf.StageDependencies(options.stage_dependencies) | 385 nmf.StageDependencies(options.stage_dependencies) |
369 | 386 |
370 | 387 |
371 # Invoke this file directly for simple testing. | 388 # Invoke this file directly for simple testing. |
372 if __name__ == '__main__': | 389 if __name__ == '__main__': |
373 sys.exit(Main(sys.argv[1:])) | 390 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |