summaryrefslogtreecommitdiffstats
path: root/third_party/python/gyp/test/linux/gyptest-ldflags-from-environment.py
blob: 4aea193e4b6512fd0f264e141522245728635ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

# Copyright (c) 2017 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verifies the use of linker flags in environment variables.

In this test, gyp and build both run in same local environment.
"""

import TestGyp

import re
import subprocess
import sys

FORMATS = ('make', 'ninja')

if sys.platform.startswith('linux'):
  test = TestGyp.TestGyp(formats=FORMATS)

  CHDIR = 'ldflags-from-environment'
  with TestGyp.LocalEnv({'LDFLAGS': '-Wl,--dynamic-linker=/target',
                         'LDFLAGS_host': '-Wl,--dynamic-linker=/host',
                         'GYP_CROSSCOMPILE': '1'}):
    test.run_gyp('test.gyp', chdir=CHDIR)
    test.build('test.gyp', chdir=CHDIR)

  def GetDynamicLinker(p):
    p = test.built_file_path(p, chdir=CHDIR)
    r = re.compile(r'\[Requesting program interpreter: ([^\]]+)\]')
    proc = subprocess.Popen(['readelf', '-l', p], stdout=subprocess.PIPE)
    o = proc.communicate()[0].decode('utf-8')
    assert not proc.returncode
    return r.search(o).group(1)

  if GetDynamicLinker('ldflags') != '/target':
    test.fail_test()

  if GetDynamicLinker('ldflags_host') != '/host':
    test.fail_test()

  test.pass_test()