gyptest-installname.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 Google Inc. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """
  6. Verifies that LD_DYLIB_INSTALL_NAME and DYLIB_INSTALL_NAME_BASE are handled
  7. correctly.
  8. """
  9. import TestGyp
  10. import re
  11. import subprocess
  12. import sys
  13. if sys.platform == 'darwin':
  14. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  15. CHDIR = 'installname'
  16. test.run_gyp('test.gyp', chdir=CHDIR)
  17. test.build('test.gyp', test.ALL, chdir=CHDIR)
  18. def GetInstallname(p):
  19. p = test.built_file_path(p, chdir=CHDIR)
  20. r = re.compile(r'cmd LC_ID_DYLIB.*?name (.*?) \(offset \d+\)', re.DOTALL)
  21. proc = subprocess.Popen(['otool', '-l', p], stdout=subprocess.PIPE)
  22. o = proc.communicate()[0]
  23. assert not proc.returncode
  24. m = r.search(o)
  25. assert m
  26. return m.group(1)
  27. if (GetInstallname('libdefault_installname.dylib') !=
  28. '/usr/local/lib/libdefault_installname.dylib'):
  29. test.fail_test()
  30. if (GetInstallname('My Framework.framework/My Framework') !=
  31. '/Library/Frameworks/My Framework.framework/'
  32. 'Versions/A/My Framework'):
  33. test.fail_test()
  34. if (GetInstallname('libexplicit_installname.dylib') !=
  35. 'Trapped in a dynamiclib factory'):
  36. test.fail_test()
  37. if (GetInstallname('libexplicit_installname_base.dylib') !=
  38. '@executable_path/../../../libexplicit_installname_base.dylib'):
  39. test.fail_test()
  40. if (GetInstallname('My Other Framework.framework/My Other Framework') !=
  41. '@executable_path/../../../My Other Framework.framework/'
  42. 'Versions/A/My Other Framework'):
  43. test.fail_test()
  44. if (GetInstallname('libexplicit_installname_with_base.dylib') !=
  45. '/usr/local/lib/libexplicit_installname_with_base.dylib'):
  46. test.fail_test()
  47. if (GetInstallname('libexplicit_installname_with_explicit_base.dylib') !=
  48. '@executable_path/../libexplicit_installname_with_explicit_base.dylib'):
  49. test.fail_test()
  50. if (GetInstallname('libboth_base_and_installname.dylib') !=
  51. 'Still trapped in a dynamiclib factory'):
  52. test.fail_test()
  53. if (GetInstallname('install_name_with_info_plist.framework/'
  54. 'install_name_with_info_plist') !=
  55. '/Library/Frameworks/install_name_with_info_plist.framework/'
  56. 'Versions/A/install_name_with_info_plist'):
  57. test.fail_test()
  58. if ('DYLIB_INSTALL_NAME_BASE:standardizepath: command not found' in
  59. test.stdout()):
  60. test.fail_test()
  61. test.pass_test()