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

Side by Side Diff: native_client_sdk/src/tools/create_nmf.py

Issue 10916343: create_nmf can now determine arch of nexe files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 # Names returned by x86_64-nacl-objdump: 29 # Names returned by x86_64-nacl-objdump:
30 'elf64-nacl': 'x86-64', 30 'elf64-nacl': 'x86-64',
31 'elf32-nacl': 'x86-32', 31 'elf32-nacl': 'x86-32',
32 } 32 }
33 33
34 ARCH_LOCATION = { 34 ARCH_LOCATION = {
35 'x86-32': 'lib32', 35 'x86-32': 'lib32',
36 'x86-64': 'lib64', 36 'x86-64': 'lib64',
37 } 37 }
38 38
39 NAME_ARCH_MAP = {
40 '32.nexe': 'x86-32',
41 '64.nexe': 'x86-64',
42 'arm.nexe': 'arm'
43 }
44
45 # These constants are used within nmf files. 39 # These constants are used within nmf files.
46 RUNNABLE_LD = 'runnable-ld.so' # Name of the dynamic loader 40 RUNNABLE_LD = 'runnable-ld.so' # Name of the dynamic loader
47 MAIN_NEXE = 'main.nexe' # Name of entry point for execution 41 MAIN_NEXE = 'main.nexe' # Name of entry point for execution
48 PROGRAM_KEY = 'program' # Key of the program section in an nmf file 42 PROGRAM_KEY = 'program' # Key of the program section in an nmf file
49 URL_KEY = 'url' # Key of the url field for a particular file in an nmf file 43 URL_KEY = 'url' # Key of the url field for a particular file in an nmf file
50 FILES_KEY = 'files' # Key of the files section in an nmf file 44 FILES_KEY = 'files' # Key of the files section in an nmf file
51 45
52 # The proper name of the dynamic linker, as kept in the IRT. This is 46 # The proper name of the dynamic linker, as kept in the IRT. This is
53 # excluded from the nmf file by convention. 47 # excluded from the nmf file by convention.
54 LD_NACL_MAP = { 48 LD_NACL_MAP = {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 '''Collect the list of dependencies for the main_files 209 '''Collect the list of dependencies for the main_files
216 210
217 Returns: 211 Returns:
218 A dict with key=filename and value=ArchFile of input files. 212 A dict with key=filename and value=ArchFile of input files.
219 Includes the input files as well, with arch filled in if absent. 213 Includes the input files as well, with arch filled in if absent.
220 Example: { '/path/to/my.nexe': ArchFile(my.nexe), 214 Example: { '/path/to/my.nexe': ArchFile(my.nexe),
221 '/path/to/libfoo.so': ArchFile(libfoo.so) }''' 215 '/path/to/libfoo.so': ArchFile(libfoo.so) }'''
222 if self.needed: 216 if self.needed:
223 return self.needed 217 return self.needed
224 218
225 runnable = (self.toolchain != 'newlib' and self.toolchain != 'pnacl')
binji 2012/09/17 19:12:22 what about pnacl...?
Sam Clegg 2012/09/18 17:48:22 Done.
226 DebugPrint('GetNeeded(%s)' % self.main_files) 219 DebugPrint('GetNeeded(%s)' % self.main_files)
227 if runnable:
228 examined = set()
229 all_files, unexamined = self.GleanFromObjdump(
230 dict([(f, None) for f in self.main_files]))
231 for name, arch_file in all_files.items():
232 arch_file.url = name
233 if unexamined:
234 unexamined.add('/'.join([arch_file.arch, RUNNABLE_LD]))
235 while unexamined:
236 files_to_examine = {}
237 for arch_name in unexamined:
238 arch, name = arch_name.split('/')
239 for path in self.FindLibsInPath(name):
240 files_to_examine.setdefault(path, set()).add(arch)
241 new_files, needed = self.GleanFromObjdump(files_to_examine)
242 all_files.update(new_files)
243 examined |= unexamined
244 unexamined = needed - examined
245 # With the runnable-ld.so scheme we have today, the proper name of
246 # the dynamic linker should be excluded from the list of files.
247 ldso = [LD_NACL_MAP[arch] for arch in set(FORMAT_ARCH_MAP.values())]
248 for name, arch_map in all_files.items():
249 if arch_map.name in ldso:
250 del all_files[name]
251 self.needed = all_files
252 else:
253 need = {}
254 for filename in self.main_files:
255 arch = filename.split('_')[-1]
256 arch = NAME_ARCH_MAP[arch]
257 url = os.path.split(filename)[1]
258 need[filename] = ArchFile(arch=arch, name=os.path.basename(filename),
259 path=filename, url=url)
260 self.needed = need
261 220
221 examined = set()
222 all_files, unexamined = self.GleanFromObjdump(
223 dict([(f, None) for f in self.main_files]))
224 for name, arch_file in all_files.items():
225 arch_file.url = name
226 if unexamined:
227 unexamined.add('/'.join([arch_file.arch, RUNNABLE_LD]))
228 while unexamined:
229 files_to_examine = {}
230 for arch_name in unexamined:
231 arch, name = arch_name.split('/')
232 for path in self.FindLibsInPath(name):
233 files_to_examine.setdefault(path, set()).add(arch)
234 new_files, needed = self.GleanFromObjdump(files_to_examine)
235 all_files.update(new_files)
236 examined |= unexamined
237 unexamined = needed - examined
238
239 # With the runnable-ld.so scheme we have today, the proper name of
240 # the dynamic linker should be excluded from the list of files.
241 ldso = [LD_NACL_MAP[arch] for arch in set(FORMAT_ARCH_MAP.values())]
242 for name, arch_map in all_files.items():
243 if arch_map.name in ldso:
244 del all_files[name]
245
246 self.needed = all_files
262 return self.needed 247 return self.needed
263 248
264 def StageDependencies(self, destination_dir): 249 def StageDependencies(self, destination_dir):
265 '''Copies over the dependencies into a given destination directory 250 '''Copies over the dependencies into a given destination directory
266 251
267 Each library will be put into a subdirectory that corresponds to the arch. 252 Each library will be put into a subdirectory that corresponds to the arch.
268 253
269 Args: 254 Args:
270 destination_dir: The destination directory for staging the dependencies 255 destination_dir: The destination directory for staging the dependencies
271 ''' 256 '''
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 430
446 431
447 # Invoke this file directly for simple testing. 432 # Invoke this file directly for simple testing.
448 if __name__ == '__main__': 433 if __name__ == '__main__':
449 try: 434 try:
450 rtn = Main(sys.argv[1:]) 435 rtn = Main(sys.argv[1:])
451 except Error, e: 436 except Error, e:
452 print "%s: %s" % (os.path.basename(__file__), e) 437 print "%s: %s" % (os.path.basename(__file__), e)
453 rtn = 1 438 rtn = 1
454 sys.exit(rtn) 439 sys.exit(rtn)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698