gyptest-implicit-rpath.py 1.1 KB

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