summaryrefslogtreecommitdiff
path: root/deps/gyp/test/make_global_settings/ar/gyptest-make_global_settings_ar.py
blob: e6676de6bdd08690c9fa0134afcd902a0f73ae00 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python

# Copyright (c) 2014 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 'AR' in make_global_settings.
"""

import os
import sys
import TestGyp

def resolve_path(test, path):
  if path is None:
    return None
  elif test.format == 'make':
    return '$(abspath %s)' % path
  elif test.format in ['ninja', 'xcode-ninja']:
    return os.path.join('..', '..', path)
  else:
    test.fail_test()


def verify_ar_target(test, ar=None, rel_path=False):
  if rel_path:
    ar_expected = resolve_path(test, ar)
  else:
    ar_expected = ar
  # Resolve default values
  if ar_expected is None:
    if test.format == 'make':
      # Make generator hasn't set the default value for AR.
      # You can remove the following assertion as long as it doesn't
      # break existing projects.
      test.must_not_contain('Makefile', 'AR ?= ')
      return
    elif test.format in ['ninja', 'xcode-ninja']:
      if sys.platform == 'win32':
        ar_expected = 'lib.exe'
      else:
        ar_expected = 'ar'
  if test.format == 'make':
    test.must_contain('Makefile', 'AR ?= %s' % ar_expected)
  elif test.format in ['ninja', 'xcode-ninja']:
    test.must_contain('out/Default/build.ninja', 'ar = %s' % ar_expected)
  else:
    test.fail_test()


def verify_ar_host(test, ar=None, rel_path=False):
  if rel_path:
    ar_expected = resolve_path(test, ar)
  else:
    ar_expected = ar
  # Resolve default values
  if ar_expected is None:
    if sys.platform == 'win32':
      ar_expected = 'lib.exe'
    else:
      ar_expected = 'ar'
  if test.format == 'make':
    test.must_contain('Makefile', 'AR.host ?= %s' % ar_expected)
  elif test.format in ['ninja', 'xcode-ninja']:
    test.must_contain('out/Default/build.ninja', 'ar_host = %s' % ar_expected)
  else:
    test.fail_test()


test_format = ['ninja']
if sys.platform in ('linux2', 'darwin'):
  test_format += ['make']

test = TestGyp.TestGyp(formats=test_format)

# Check default values
test.run_gyp('make_global_settings_ar.gyp')
verify_ar_target(test)


# Check default values with GYP_CROSSCOMPILE enabled.
with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}):
  test.run_gyp('make_global_settings_ar.gyp')
verify_ar_target(test)
verify_ar_host(test)


# Test 'AR' in 'make_global_settings'.
with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}):
  test.run_gyp('make_global_settings_ar.gyp', '-Dcustom_ar_target=my_ar')
verify_ar_target(test, ar='my_ar', rel_path=True)


# Test 'AR'/'AR.host' in 'make_global_settings'.
with TestGyp.LocalEnv({'GYP_CROSSCOMPILE': '1'}):
  test.run_gyp('make_global_settings_ar.gyp',
               '-Dcustom_ar_target=my_ar_target1',
               '-Dcustom_ar_host=my_ar_host1')
verify_ar_target(test, ar='my_ar_target1', rel_path=True)
verify_ar_host(test, ar='my_ar_host1', rel_path=True)


# Test $AR and $AR_host environment variables.
with TestGyp.LocalEnv({'AR': 'my_ar_target2',
                       'AR_host': 'my_ar_host2'}):
  test.run_gyp('make_global_settings_ar.gyp')
# Ninja generator resolves $AR in gyp phase. Make generator doesn't.
if test.format == 'ninja':
  if sys.platform == 'win32':
    # TODO(yukawa): Make sure if this is an expected result or not.
    verify_ar_target(test, ar='lib.exe', rel_path=False)
  else:
    verify_ar_target(test, ar='my_ar_target2', rel_path=False)
verify_ar_host(test, ar='my_ar_host2', rel_path=False)


# Test 'AR' in 'make_global_settings' with $AR_host environment variable.
with TestGyp.LocalEnv({'AR_host': 'my_ar_host3'}):
  test.run_gyp('make_global_settings_ar.gyp',
               '-Dcustom_ar_target=my_ar_target3')
verify_ar_target(test, ar='my_ar_target3', rel_path=True)
verify_ar_host(test, ar='my_ar_host3', rel_path=False)


test.pass_test()