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

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

Issue 890033003: Revert of [NaCl SDK] Remove create_nmf dependency on NACL_SDK_ROOT env var (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | native_client_sdk/src/tools/tests/create_nmf_test.py » ('j') | 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 """Tool for automatically creating .nmf files from .nexe/.pexe/.bc executables. 6 """Tool for automatically creating .nmf files from .nexe/.pexe/.bc executables.
7 7
8 As well as creating the nmf file this tool can also find and stage 8 As well as creating the nmf file this tool can also find and stage
9 any shared libraries dependencies that the executables might have. 9 any shared libraries dependencies that the executables might have.
10 """ 10 """
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 else: 459 else:
460 canonicalized.append([unquoted[0], unquoted[2], unquoted[4]]) 460 canonicalized.append([unquoted[0], unquoted[2], unquoted[4]])
461 else: 461 else:
462 err.write('Bad key:arch:url tuple for --extra-files: ' + kv + '\n') 462 err.write('Bad key:arch:url tuple for --extra-files: ' + kv + '\n')
463 if seen_error: 463 if seen_error:
464 return None 464 return None
465 return canonicalized 465 return canonicalized
466 466
467 467
468 def GetSDKRoot(): 468 def GetSDKRoot():
469 """Returns the root directory of the NaCl SDK. 469 """Determine current NACL_SDK_ROOT, either via the environment variable
470 itself, or by attempting to derive it from the location of this script.
470 """ 471 """
471 # This script should be installed in NACL_SDK_ROOT/tools. Assert that 472 sdk_root = os.environ.get('NACL_SDK_ROOT')
472 # the 'toolchain' folder exists within this directory in case, for 473 if not sdk_root:
473 # example, this script is moved to a different location. 474 sdk_root = os.path.dirname(SCRIPT_DIR)
474 # During the Chrome build this script is sometimes run outside of 475 if not os.path.exists(os.path.join(sdk_root, 'toolchain')):
475 # of an SDK but in these cases it should always be run with --objdump= 476 return None
476 # and --no-default-libpath which avoids the need to call this function. 477
477 sdk_root = os.path.dirname(SCRIPT_DIR)
478 assert(os.path.exists(os.path.join(sdk_root, 'toolchain')))
479 return sdk_root 478 return sdk_root
480 479
481 480
482 def FindObjdumpExecutable(): 481 def FindObjdumpExecutable():
483 """Derive path to objdump executable to use for determining shared 482 """Derive path to objdump executable to use for determining shared
484 object dependencies. 483 object dependencies.
485 """ 484 """
485 sdk_root = GetSDKRoot()
486 if not sdk_root:
487 return None
488
486 osname = getos.GetPlatform() 489 osname = getos.GetPlatform()
487 toolchain = os.path.join(GetSDKRoot(), 'toolchain', '%s_x86_glibc' % osname) 490 toolchain = os.path.join(sdk_root, 'toolchain', '%s_x86_glibc' % osname)
488 objdump = os.path.join(toolchain, 'bin', 'x86_64-nacl-objdump') 491 objdump = os.path.join(toolchain, 'bin', 'x86_64-nacl-objdump')
489 if osname == 'win': 492 if osname == 'win':
490 objdump += '.exe' 493 objdump += '.exe'
491 494
492 if not os.path.exists(objdump): 495 if not os.path.exists(objdump):
493 sys.stderr.write('WARNING: failed to find objdump in default ' 496 sys.stderr.write('WARNING: failed to find objdump in default '
494 'location: %s' % objdump) 497 'location: %s' % objdump)
495 return None 498 return None
496 499
497 return objdump 500 return objdump
498 501
499 502
500 def GetDefaultLibPath(config): 503 def GetDefaultLibPath(config):
501 """Derive default library path to use when searching for shared 504 """Derive default library path to use when searching for shared
502 objects. This currently include the toolchain library folders 505 objects. This currently include the toolchain library folders
503 as well as the top level SDK lib folder and the naclports lib 506 as well as the top level SDK lib folder and the naclports lib
504 folder. We include both 32-bit and 64-bit library paths. 507 folder. We include both 32-bit and 64-bit library paths.
505 """ 508 """
506 assert(config in ('Debug', 'Release')) 509 assert(config in ('Debug', 'Release'))
507 sdk_root = GetSDKRoot() 510 sdk_root = GetSDKRoot()
511 if not sdk_root:
512 # TOOD(sbc): output a warning here? We would also need to suppress
513 # the warning when run from the chromium build.
514 return []
508 515
509 osname = getos.GetPlatform() 516 osname = getos.GetPlatform()
510 libpath = [ 517 libpath = [
511 # Core toolchain libraries 518 # Core toolchain libraries
512 'toolchain/%s_x86_glibc/x86_64-nacl/lib' % osname, 519 'toolchain/%s_x86_glibc/x86_64-nacl/lib' % osname,
513 'toolchain/%s_x86_glibc/x86_64-nacl/lib32' % osname, 520 'toolchain/%s_x86_glibc/x86_64-nacl/lib32' % osname,
514 # naclports installed libraries 521 # naclports installed libraries
515 'toolchain/%s_x86_glibc/x86_64-nacl/usr/lib' % osname, 522 'toolchain/%s_x86_glibc/x86_64-nacl/usr/lib' % osname,
516 'toolchain/%s_x86_glibc/i686-nacl/usr/lib' % osname, 523 'toolchain/%s_x86_glibc/i686-nacl/usr/lib' % osname,
517 # SDK bundle libraries 524 # SDK bundle libraries
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 metavar='DIRECTORY') 573 metavar='DIRECTORY')
567 parser.add_argument('--no-arch-prefix', action='store_true', 574 parser.add_argument('--no-arch-prefix', action='store_true',
568 help='Don\'t put shared libraries in the lib32/lib64 ' 575 help='Don\'t put shared libraries in the lib32/lib64 '
569 'directories. Instead, they will be put in the same ' 576 'directories. Instead, they will be put in the same '
570 'directory as the .nexe that matches its architecture.') 577 'directory as the .nexe that matches its architecture.')
571 parser.add_argument('-t', '--toolchain', help='Legacy option, do not use') 578 parser.add_argument('-t', '--toolchain', help='Legacy option, do not use')
572 parser.add_argument('-n', '--name', dest='name', 579 parser.add_argument('-n', '--name', dest='name',
573 help='Rename FOO as BAR', 580 help='Rename FOO as BAR',
574 action='append', default=[], metavar='FOO,BAR') 581 action='append', default=[], metavar='FOO,BAR')
575 parser.add_argument('-x', '--extra-files', 582 parser.add_argument('-x', '--extra-files',
576 help='Add extra key:file tuple to the "files"' 583 help=('Add extra key:file tuple to the "files"' +
577 ' section of the .nmf', 584 ' section of the .nmf'),
578 action='append', default=[], metavar='FILE') 585 action='append', default=[], metavar='FILE')
579 parser.add_argument('-O', '--pnacl-optlevel', 586 parser.add_argument('-O', '--pnacl-optlevel',
580 help='Set the optimization level to N in PNaCl manifests', 587 help='Set the optimization level to N in PNaCl manifests',
581 metavar='N') 588 metavar='N')
582 parser.add_argument('--pnacl-debug-optlevel', 589 parser.add_argument('--pnacl-debug-optlevel',
583 help='Set the optimization level to N for debugging ' 590 help='Set the optimization level to N for debugging '
584 'sections in PNaCl manifests', 591 'sections in PNaCl manifests',
585 metavar='N') 592 metavar='N')
586 parser.add_argument('-v', '--verbose', 593 parser.add_argument('-v', '--verbose',
587 help='Verbose output', action='store_true') 594 help='Verbose output', action='store_true')
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 lib_path=options.lib_path, 662 lib_path=options.lib_path,
656 extra_files=canonicalized, 663 extra_files=canonicalized,
657 lib_prefix=options.lib_prefix, 664 lib_prefix=options.lib_prefix,
658 nexe_prefix=options.nexe_prefix, 665 nexe_prefix=options.nexe_prefix,
659 no_arch_prefix=options.no_arch_prefix, 666 no_arch_prefix=options.no_arch_prefix,
660 remap=remap, 667 remap=remap,
661 pnacl_optlevel=pnacl_optlevel, 668 pnacl_optlevel=pnacl_optlevel,
662 pnacl_debug_optlevel=pnacl_debug_optlevel, 669 pnacl_debug_optlevel=pnacl_debug_optlevel,
663 nmf_root=nmf_root) 670 nmf_root=nmf_root)
664 671
665 if options.output is None: 672 if not options.output:
666 sys.stdout.write(nmf.GetJson()) 673 sys.stdout.write(nmf.GetJson())
667 else: 674 else:
668 with open(options.output, 'w') as output: 675 with open(options.output, 'w') as output:
669 output.write(nmf.GetJson()) 676 output.write(nmf.GetJson())
670 677
671 if options.stage_dependencies and not nmf.pnacl: 678 if options.stage_dependencies and not nmf.pnacl:
672 Trace('Staging dependencies...') 679 Trace('Staging dependencies...')
673 nmf.StageDependencies(options.stage_dependencies) 680 nmf.StageDependencies(options.stage_dependencies)
674 681
675 return 0 682 return 0
676 683
677 684
678 if __name__ == '__main__': 685 if __name__ == '__main__':
679 try: 686 try:
680 rtn = main(sys.argv[1:]) 687 rtn = main(sys.argv[1:])
681 except Error, e: 688 except Error, e:
682 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 689 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
683 rtn = 1 690 rtn = 1
684 except KeyboardInterrupt: 691 except KeyboardInterrupt:
685 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 692 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
686 rtn = 1 693 rtn = 1
687 sys.exit(rtn) 694 sys.exit(rtn)
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/tools/tests/create_nmf_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698