1#!/usr/bin/env python
2
3# Copyright (c) 2009 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 a default gyp define can be overridden.
9"""
10
11import os
12import TestGyp
13
14test = TestGyp.TestGyp()
15
16# CMake loudly warns about passing '#' to the compiler and drops the define.
17expect_stderr = ''
18if test.format == 'cmake':
19  expect_stderr = (
20"""WARNING: Preprocessor definitions containing '#' may not be passed on the"""
21""" compiler command line because many compilers do not support it.\n"""
22"""CMake is dropping a preprocessor definition: HASH_VALUE="a#1"\n"""
23"""Consider defining the macro in a (configured) header file.\n\n""")
24
25# Command-line define
26test.run_gyp('defines.gyp', '-D', 'OS=fakeos')
27test.build('defines.gyp', stderr=expect_stderr)
28test.built_file_must_exist('fakeosprogram', type=test.EXECUTABLE)
29# Clean up the exe so subsequent tests don't find an old exe.
30os.remove(test.built_file_path('fakeosprogram', type=test.EXECUTABLE))
31
32# Without "OS" override, fokeosprogram shouldn't be built.
33test.run_gyp('defines.gyp')
34test.build('defines.gyp', stderr=expect_stderr)
35test.built_file_must_not_exist('fakeosprogram', type=test.EXECUTABLE)
36
37# Environment define
38os.environ['GYP_DEFINES'] = 'OS=fakeos'
39test.run_gyp('defines.gyp')
40test.build('defines.gyp', stderr=expect_stderr)
41test.built_file_must_exist('fakeosprogram', type=test.EXECUTABLE)
42
43test.pass_test()
44