Example #1
0
"""
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]
Example #2
0
# found in the LICENSE file.
"""
Test that environment variables are ignored when --ignore-environment is
specified.
"""

import os

import TestGyp

os.environ['GYP_DEFINES'] = 'FOO=BAR'
os.environ['GYP_GENERATORS'] = 'foo'
os.environ['GYP_GENERATOR_FLAGS'] = 'genflag=foo'
os.environ['GYP_GENERATOR_OUTPUT'] = 'somedir'

test = TestGyp.TestGyp(format='gypd')

expect = test.read('commands.gyp.ignore-env.stdout')

# Set $HOME so that gyp doesn't read the user's actual
# ~/.gyp/include.gypi file, which may contain variables
# and other settings that would change the output.
os.environ['HOME'] = test.workpath()

test.run_gyp('commands.gyp',
             '--debug',
             'variables',
             '--debug',
             'general',
             '--ignore-environment',
             stdout=expect)
Example #3
0
        os.environ['CC_host'] = 'python %s/my_cc.py HOST' % here
        os.environ['CXX_host'] = 'python %s/my_cxx.py HOST' % here
        os.environ['LINK_host'] = 'python %s/my_ld.py HOST_LINK' % here
        CheckCompiler('compiler-host.gyp', expected, True)
    finally:
        os.environ.clear()
        os.environ.update(oldenv)

    # Run the same tests once the eviron has been restored.  The
    # generated should have embedded all the settings in the
    # project files so the results should be the same.
    CheckCompiler('compiler-host.gyp', expected, False)


# ======== Test script ========

here = os.path.dirname(os.path.abspath(__file__))

# Clear any existing compiler related env vars.
for key in ['CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host']:
    if key in os.environ:
        del os.environ[key]

test = TestGyp.TestGyp(formats=['ninja', 'make'], platforms=['!win32'])

TestTargetOveride()
TestTargetOverideCompilerOnly()
TestHostOveride()

test.pass_test()
#!/usr/bin/env python

# Copyright (c) 2009 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 inclusion of $HOME/.gyp/includes.gypi works.
"""

import os
import TestGyp

test = TestGyp.TestGyp()

os.environ['HOME'] = os.path.abspath('home')

test.run_gyp('all.gyp', chdir='src')

# After relocating, we should still be able to build (build file shouldn't
# contain relative reference to ~/.gyp/includes.gypi)
test.relocate('src', 'relocate/src')

test.build('all.gyp', test.ALL, chdir='relocate/src')

test.run_built_executable('printfoo',
                          chdir='relocate/src',
                          stdout="FOO is fromhome\n")

test.pass_test()
Example #5
0
env_stack = []


def PushEnv():
    env_copy = os.environ.copy()
    env_stack.append(env_copy)


def PopEnv():
    os.eniron = env_stack.pop()


# Regenerating build files when a gyp file changes is currently only supported
# by the make generator.
test = TestGyp.TestGyp(formats=['make'])

try:
    PushEnv()
    os.environ['CXXFLAGS'] = '-O0'
    test.run_gyp('cxxflags.gyp')
finally:
    # We clear the environ after calling gyp.  When the auto-regeneration happens,
    # the same define should be reused anyway.  Reset to empty string first in
    # case the platform doesn't support unsetenv.
    PopEnv()

test.build('cxxflags.gyp')

expect = """\
Using no optimization flag
Example #6
0
def CheckFileXMLPropertyList(file):
    output = subprocess.check_output(['file', file])
    if not 'XML 1.0 document text' in output:
        print 'File: Expected XML 1.0 document text, got %s' % output
        test.fail_test()


def CheckFileBinaryPropertyList(file):
    output = subprocess.check_output(['file', file])
    if not 'Apple binary property list' in output:
        print 'File: Expected Apple binary property list, got %s' % output
        test.fail_test()


if sys.platform == 'darwin':
    test = TestGyp.TestGyp(formats=['xcode', 'ninja'])

    test.run_gyp('test.gyp', chdir='app-bundle')

    test.build('test.gyp', test.ALL, chdir='app-bundle')

    # Test that the extension is .bundle
    test.built_file_must_exist('Test App Gyp.app/Test App Gyp',
                               chdir='app-bundle')

    # Info.plist
    info_plist = test.built_file_path('Test App Gyp.app/Info.plist',
                                      chdir='app-bundle')
    test.built_file_must_exist(info_plist)
    CheckFileBinaryPropertyList(info_plist)
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verifies make_global_settings.
"""

import os
import sys
import TestGyp

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

test = TestGyp.TestGyp(formats=test_format)

test.run_gyp('make_global_settings.gyp')

if test.format == 'make':
  cc_expected = """ifneq (,$(filter $(origin CC), undefined default))
  CC = $(abspath clang)
endif
"""
  if sys.platform == 'linux2':
    link_expected = """
LINK ?= flock $(builddir)/linker.lock $(abspath clang)
"""
  elif sys.platform == 'darwin':
    link_expected = """
LINK ?= ./gyp-mac-tool flock $(builddir)/linker.lock $(abspath clang)
#!/usr/bin/env python

# Copyright (c) 2009 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.

"""
Build a .gyp that depends on 2 gyp files with the same name.
"""

import TestGyp

# This causes a problem on XCode (duplicate ID).
# See http://code.google.com/p/gyp/issues/detail?id=114
test = TestGyp.TestGyp(formats=['msvs', 'scons', 'make'])

test.run_gyp('all.gyp', chdir='src')

test.relocate('src', 'relocate/src')

test.build('all.gyp', chdir='relocate/src')

expect1 = """\
Hello from main1.cc
"""

expect2 = """\
Hello from main2.cc
"""

test.run_built_executable('program1', chdir='relocate/src', stdout=expect1)
Example #9
0
      ar_expected = '$(abspath %s)' % ar
    elif test.is_ninja:
      ar_expected = os.path.join('..', '..', ar)
    else:
      test.fail_test()
      return
  else:
    ar_expected = ar or ''
  return ar_expected


test_format = ['ninja']
if sys.platform.startswith('linux') or sys.platform == 'darwin':
  test_format += ['make']

test = TestGyp.TestGyp(formats=test_format)

# Check default values
test.run_gyp('make_global_settings_ar.gyp')
verify_ar(is_cross=False)


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


# 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')
Example #10
0
#!/usr/bin/env python

# Copyright (c) 2012 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 that uldi can be disabled on a per-project-reference basis in vs2010.
"""

import TestGyp

test = TestGyp.TestGyp(formats=['msvs'], workdir='workarea_all')

test.run_gyp('hello.gyp')

if test.uses_msbuild:
    test.must_contain('hello.vcxproj', '<UseLibraryDependencyInputs>false')

test.pass_test()
Example #11
0
# found in the LICENSE file.

"""
Verifies the use of the environment during regeneration when the gyp file
changes, specifically via build of an executable with C preprocessor
definition specified by CFLAGS.

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

import TestGyp

# CPPFLAGS works in ninja but not make; CFLAGS works in both
FORMATS = ('make', 'ninja')

test = TestGyp.TestGyp(formats=FORMATS)

# First set CFLAGS to blank in case the platform doesn't support unsetenv.
with TestGyp.LocalEnv({'CFLAGS': '',
                       'GYP_CROSSCOMPILE': '1'}):
  test.run_gyp('cflags.gyp')
  test.build('cflags.gyp')

expect = """FOO not defined\n"""
test.run_built_executable('cflags', stdout=expect)
test.run_built_executable('cflags_host', stdout=expect)

test.sleep()

with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1',
                       'GYP_CROSSCOMPILE': '1'}):
Example #12
0
# Copyright (c) 2011 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 that a failing postbuild step lets the build fail.
"""
from __future__ import print_function

import TestGyp

import sys

if sys.platform == 'darwin':
  # set |match| to ignore build stderr output.
  test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'],
                         match = lambda a, b: True)

  test.run_gyp('test.gyp', chdir='postbuild-fail')

  build_error_code = {
    'xcode': [1, 65],  # 1 for xcode 3, 65 for xcode 4 (see `man sysexits`)
    'make': 2,
    'ninja': 1,
    'xcode-ninja': [1, 65],
  }[test.format]


  # If a postbuild fails, all postbuilds should be re-run on the next build.
  # In Xcode 3, even if the first postbuild fails the other postbuilds were
  # still executed. In Xcode 4, postbuilds are stopped after the first
  # failing postbuild. This test checks for the Xcode 4 behavior.
Example #13
0
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verify handling of build variants.

TODO:  Right now, only the SCons generator supports this, so the
test case is SCons-specific.  In particular, it relise on SCons'
ability to rebuild in response to changes on the command line.  It
may be simpler to just drop this feature if the other generators
can't be made to behave the same way.
"""

import TestGyp

test = TestGyp.TestGyp(formats=['scons'])

test.run_gyp('variants.gyp', chdir='src')

test.relocate('src', 'relocate/src')

test.build('variants.gyp', chdir='relocate/src')

test.run_built_executable('variants',
                          chdir='relocate/src',
                          stdout="Hello, world!\n")

test.sleep()
test.build('variants.gyp', 'VARIANT1=1', chdir='relocate/src')

test.run_built_executable('variants',
Example #14
0
Make sure msvs_enable_winrt works correctly.
"""

import TestGyp

import os
import sys
import struct

CHDIR = 'enable-winrt'

print 'This test is not currently working on the bots: https://code.google.com/p/gyp/issues/detail?id=466'
sys.exit(0)

if (sys.platform == 'win32'
        and int(os.environ.get('GYP_MSVS_VERSION', 0)) >= 2013):
    test = TestGyp.TestGyp(formats=['msvs'])

    test.run_gyp('enable-winrt.gyp', chdir=CHDIR)

    test.build('enable-winrt.gyp', 'enable_winrt_dll', chdir=CHDIR)

    test.build('enable-winrt.gyp',
               'enable_winrt_missing_dll',
               chdir=CHDIR,
               status=1)

    test.build('enable-winrt.gyp', 'enable_winrt_winphone_dll', chdir=CHDIR)

    test.pass_test()
#!/usr/bin/env python

# Copyright 2013 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 that unicode strings in 'xcode_settings' work.
Also checks that ASCII control characters are escaped properly.
"""

import TestGyp

import sys

if sys.platform == 'darwin':
    test = TestGyp.TestGyp(formats=['xcode'])
    test.run_gyp('test.gyp', chdir='unicode-settings')
    test.build('test.gyp', test.ALL, chdir='unicode-settings')
    test.pass_test()
Example #16
0
#!/usr/bin/env python

# Copyright (c) 2012 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 simple actions when using the default build target.
"""

import TestGyp

test = TestGyp.TestGyp(workdir='workarea_default')

test.run_gyp('actions.gyp', chdir='src')

test.relocate('src', 'relocate/src')

# Some gyp files use an action that mentions an output but never
# writes it as a means to making the action run on every build.  That
# doesn't mesh well with ninja's semantics.  TODO(evan): figure out
# how to work always-run actions in to ninja.
if test.format in ['ninja', 'xcode-ninja']:
    test.build('actions.gyp', test.ALL, chdir='relocate/src')
else:
    # Test that an "always run" action increases a counter on multiple
    # invocations, and that a dependent action updates in step.
    test.build('actions.gyp', chdir='relocate/src')
    test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '1')
    test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt',
                    '1')
    test.build('actions.gyp', chdir='relocate/src')
Example #17
0
#!/usr/bin/env python

# Copyright (c) 2012 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.
"""
Verify that dependent rules are executed iff a dependency action modifies its
outputs.
"""

import TestGyp
import os

test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])

test.run_gyp('restat.gyp', chdir='src')

chdir = 'relocate/src'
test.relocate('src', chdir)

# Building 'dependent' the first time generates 'side_effect', but building it
# the second time doesn't, because 'create_intermediate' doesn't update its
# output.
test.build('restat.gyp', 'dependent', chdir=chdir)
test.built_file_must_exist('side_effect', chdir=chdir)
os.remove(test.built_file_path('side_effect', chdir=chdir))
test.build('restat.gyp', 'dependent', chdir=chdir)
test.built_file_must_not_exist('side_effect', chdir=chdir)

test.pass_test()
Example #18
0
#!/usr/bin/env python

# Copyright (c) 2012 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 simple build of a "Hello, world!" program with loadable modules. The
default for all platforms should be to output the loadable modules to the same
path as the executable.
"""

import TestGyp

# Android doesn't support loadable modules
test = TestGyp.TestGyp(formats=['!android'])

test.run_gyp('module.gyp', chdir='src')

test.build('module.gyp', test.ALL, chdir='src')

expect = """\
Hello from program.c
Hello from lib1.c
Hello from lib2.c
"""
test.run_built_executable('program', chdir='src', stdout=expect)

test.pass_test()
Example #19
0
        'CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host', 'NM_target',
        'READELF_target'
]:
    if key in os.environ:
        del os.environ[key]


def CheckCompiler(test, gypfile, check_for, run_gyp):
    if run_gyp:
        test.run_gyp(gypfile)
    test.build(gypfile)

    test.must_contain_all_lines(test.stdout(), check_for)


test = TestGyp.TestGyp(formats=['ninja'])
# Must set the test format to something with a flavor (the part after the '-')
# in order to test the desired behavior. Since we want to run a non-host
# toolchain, we have to set the flavor to something that the ninja generator
# doesn't know about, so it doesn't default to the host-specific tools (e.g.,
# 'otool' on mac to generate the .TOC).
#
# Note that we can't just pass format=['ninja-some_toolchain'] to the
# constructor above, because then this test wouldn't be recognized as a ninja
# format test.
test.formats = ['ninja-my_flavor' if f == 'ninja' else f for f in test.formats]


def TestTargetOverideSharedLib():
    # The std output from nm and readelf is redirected to files, so we can't
    # expect their output to appear. Instead, check for the files they create to
Example #20
0
#!/usr/bin/env python

# Copyright (c) 2012 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 inclusion of $HOME/.gyp/include.gypi works properly with relocation
and with regeneration.
"""

import os
import TestGyp

# Regenerating build structure when a gyp file changes is currently only supported
# by the make and Android generators.
test = TestGyp.TestGyp(formats=['make', 'android'])

os.environ['HOME'] = os.path.abspath('home')

test.run_gyp('all.gyp', chdir='src')

# After relocating, we should still be able to build (build file shouldn't
# contain relative reference to ~/.gyp/include.gypi)
test.relocate('src', 'relocate/src')

test.build('all.gyp', test.ALL, chdir='relocate/src')

test.run_built_executable('printfoo',
                          chdir='relocate/src',
                          stdout='FOO is fromhome\n')
Example #21
0
#!/usr/bin/env python

# Copyright (c) 2012 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.
"""
Make sure exception handling settings are extracted properly.
"""

import TestGyp

import sys

if sys.platform == 'win32':
    test = TestGyp.TestGyp(formats=['msvs', 'ninja'])

    CHDIR = 'compiler-flags'
    test.run_gyp('exception-handling.gyp', chdir=CHDIR)

    # Must fail.
    test.build('exception-handling.gyp', 'test_eh_off', chdir=CHDIR, status=1)

    # Must succeed.
    test.build('exception-handling.gyp', 'test_eh_s', chdir=CHDIR)
    test.build('exception-handling.gyp', 'test_eh_a', chdir=CHDIR)

    # Error code must be 1 if EHa, and 2 if EHsc.
    test.run_built_executable('test_eh_a', chdir=CHDIR, status=1)
    test.run_built_executable('test_eh_s', chdir=CHDIR, status=2)

    test.pass_test()
msbuild_configuration_attributes are applied by using
them to set the OutputDirectory.
"""

import TestGyp
import os

import sys

if sys.platform == 'win32':
  print "This test is currently disabled: https://crbug.com/483696."
  sys.exit(0)



test = TestGyp.TestGyp(workdir='workarea_all',formats=['msvs'])

vc_version = 'VC90'

if os.getenv('GYP_MSVS_VERSION'):
  vc_version = ['VC90','VC100'][int(os.getenv('GYP_MSVS_VERSION')) >= 2010]

expected_exe_file = os.path.join(test.workdir, vc_version, 'hello.exe')

test.run_gyp('hello.gyp')

test.build('hello.gyp')

test.must_exist(expected_exe_file)

test.pass_test()
Example #23
0
referred to with deeply-nested ../../.. paths.
"""

import TestGyp

# TODO(mmoss): Make only supports (theoretically) a single, global build
# directory (through GYP_GENERATOR_FLAGS 'output_dir'), rather than
# gyp-file-specific settings (e.g. the stuff in builddir.gypi) that the other
# generators support, so this doesn't work yet for make.
# TODO(mmoss) Make also has the issue that the top-level Makefile is written to
# the "--depth" location, which is one level above 'src', but then this test
# moves 'src' somewhere else, leaving the Makefile behind, so make can't find
# its sources. I'm not sure if make is wrong for writing outside the current
# directory, or if the test is wrong for assuming everything generated is under
# the current directory.
test = TestGyp.TestGyp(formats=['!make', '!ninja'])

test.run_gyp('prog1.gyp', '--depth=..', chdir='src')

test.relocate('src', 'relocate/src')

test.subdir('relocate/builddir')

# Make sure that all the built ../../etc. files only get put under builddir,
# by making all of relocate read-only and then making only builddir writable.
test.writable('relocate', False)
test.writable('relocate/builddir', True)

# Suppress the test infrastructure's setting SYMROOT on the command line.
test.build('prog1.gyp', test.ALL, SYMROOT=None, chdir='relocate/src')
Example #24
0
# Copyright (c) 2012 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.
"""
Checks that C-only targets aren't linked against libstdc++.
"""

import TestGyp

import re
import subprocess
import sys

# set |match| to ignore build stderr output.
test = TestGyp.TestGyp(match=lambda a, b: True)
if (sys.platform != 'win32'
        and not (sys.platform == 'darwin' and test.format == 'make')):
    # TODO: Does a test like this make sense with Windows?

    CHDIR = 'src'
    test.run_gyp('test.gyp', chdir=CHDIR)
    test.build('test.gyp', 'no_cpp', chdir=CHDIR)

    def LinksLibStdCpp(path):
        path = test.built_file_path(path, chdir=CHDIR)
        if sys.platform == 'darwin':
            proc = subprocess.Popen(['otool', '-L', path],
                                    stdout=subprocess.PIPE,
                                    universal_newlines=True)
        else:
Example #25
0
"""

import TestGyp

# TODO(mmoss): Make only supports (theoretically) a single, global build
# directory (through GYP_GENERATOR_FLAGS 'output_dir'), rather than
# gyp-file-specific settings (e.g. the stuff in builddir.gypi) that the other
# generators support, so this doesn't work yet for make.
# TODO(mmoss) Make also has the issue that the top-level Makefile is written to
# the "--depth" location, which is one level above 'src', but then this test
# moves 'src' somewhere else, leaving the Makefile behind, so make can't find
# its sources. I'm not sure if make is wrong for writing outside the current
# directory, or if the test is wrong for assuming everything generated is under
# the current directory.
# Android, Ninja, and CMake do not support setting the build directory.
test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android', '!cmake'])

test.run_gyp('prog1.gyp', '--depth=..', chdir='src')
if test.format == 'msvs':
    if test.uses_msbuild:
        test.must_contain('src/prog1.vcxproj',
                          '<OutDir>..\\builddir\\Default\\</OutDir>')
    else:
        test.must_contain('src/prog1.vcproj',
                          'OutputDirectory="..\\builddir\\Default\\"')

test.relocate('src', 'relocate/src')

test.subdir('relocate/builddir')

# Make sure that all the built ../../etc. files only get put under builddir,
Example #26
0
#!/usr/bin/env python

# Copyright (c) 2011 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 simplest-possible build of a "Hello, world!" program
using the default build target.
"""

import TestGyp

test = TestGyp.TestGyp(workdir='workarea_default', formats=['msvs'])

# Run from down in foo.
test.run_gyp('a.gyp', chdir='foo/a')
sln = test.workpath('foo/a/a.sln')
sln_data = open(sln, 'rb').read()
vcproj = sln_data.count('b.vcproj')
vcxproj = sln_data.count('b.vcxproj')
if (vcproj, vcxproj) not in [(1, 0), (0, 1)]:
  test.fail_test()

test.pass_test()