Home | History | Annotate | Download | only in linux
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2013 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 the implicit rpath is added only when needed.
      9 """
     10 
     11 import TestGyp
     12 
     13 import re
     14 import subprocess
     15 import sys
     16 
     17 if sys.platform.startswith('linux'):
     18   test = TestGyp.TestGyp(formats=['ninja', 'make'])
     19 
     20   CHDIR = 'implicit-rpath'
     21   test.run_gyp('test.gyp', chdir=CHDIR)
     22   test.build('test.gyp', test.ALL, chdir=CHDIR)
     23 
     24   def GetRpaths(p):
     25     p = test.built_file_path(p, chdir=CHDIR)
     26     r = re.compile(r'Library rpath: \[([^\]]+)\]')
     27     proc = subprocess.Popen(['readelf', '-d', p], stdout=subprocess.PIPE)
     28     o = proc.communicate()[0]
     29     assert not proc.returncode
     30     return r.findall(o)
     31 
     32   if test.format == 'ninja':
     33     expect = '$ORIGIN/lib/'
     34   elif test.format == 'make':
     35     expect = '$ORIGIN/lib.target/'
     36   else:
     37     test.fail_test()
     38 
     39   if GetRpaths('shared_executable') != [expect]:
     40     test.fail_test()
     41 
     42   if GetRpaths('shared_executable_no_so_suffix') != [expect]:
     43     test.fail_test()
     44 
     45   if GetRpaths('static_executable'):
     46     test.fail_test()
     47 
     48   test.pass_test()
     49