• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3# Copyright (c) 2015 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"""
8Verifies that LTO flags work.
9"""
10
11import TestGyp
12
13import os
14import re
15import subprocess
16import sys
17
18if sys.platform == 'darwin':
19  test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
20  CHDIR = 'lto'
21  test.run_gyp('test.gyp', chdir=CHDIR)
22
23  test.build('test.gyp', test.ALL, chdir=CHDIR)
24
25  def ObjPath(srcpath, target):
26    # TODO: Move this into TestGyp if it's needed elsewhere.
27    if test.format == 'xcode':
28      return os.path.join(CHDIR, 'build', 'test.build', 'Default',
29                          target + '.build', 'Objects-normal', 'x86_64',
30                          srcpath + '.o')
31    elif 'ninja' in test.format:  # ninja, xcode-ninja
32      return os.path.join(CHDIR, 'out', 'Default', 'obj',
33                          target + '.' + srcpath + '.o')
34    elif test.format == 'make':
35      return os.path.join(CHDIR, 'out', 'Default', 'obj.target',
36                          target, srcpath + '.o')
37
38  def ObjType(p, t_expected):
39    r = re.compile(r'nsyms\s+(\d+)')
40    o = subprocess.check_output(['file', p])
41    objtype = 'unknown'
42    if ': Mach-O ' in o:
43      objtype = 'mach-o'
44    elif ': LLVM bit-code ' in o:
45      objtype = 'llvm'
46    if objtype != t_expected:
47      print 'Expected %s, got %s' % (t_expected, objtype)
48      test.fail_test()
49
50  ObjType(ObjPath('cfile', 'lto'), 'llvm')
51  ObjType(ObjPath('ccfile', 'lto'), 'llvm')
52  ObjType(ObjPath('mfile', 'lto'), 'llvm')
53  ObjType(ObjPath('mmfile', 'lto'), 'llvm')
54  ObjType(ObjPath('asmfile', 'lto'), 'mach-o')
55
56  ObjType(ObjPath('cfile', 'lto_static'), 'llvm')
57  ObjType(ObjPath('ccfile', 'lto_static'), 'llvm')
58  ObjType(ObjPath('mfile', 'lto_static'), 'llvm')
59  ObjType(ObjPath('mmfile', 'lto_static'), 'llvm')
60  ObjType(ObjPath('asmfile', 'lto_static'), 'mach-o')
61
62  test.pass_test()
63
64  # TODO: Probably test for -object_path_lto too, else dsymutil won't be
65  # useful maybe?
66