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