1#!/usr/bin/env python
2
3# Copyright (c) 2010 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"""
8Tests the use of the NO_LOAD flag which makes loading sub .mk files
9optional.
10"""
11
12# Python 2.5 needs this for the with statement.
13from __future__ import with_statement
14
15import os
16import TestGyp
17
18test = TestGyp.TestGyp(formats=['make'])
19
20test.run_gyp('all.gyp', chdir='noload')
21
22test.relocate('noload', 'relocate/noload')
23
24test.build('build/all.gyp', test.ALL, chdir='relocate/noload')
25test.run_built_executable('exe', chdir='relocate/noload',
26                          stdout='Hello from shared.c.\n')
27
28# Just sanity test that NO_LOAD=lib doesn't break anything.
29test.build('build/all.gyp', test.ALL, chdir='relocate/noload',
30           arguments=['NO_LOAD=lib'])
31test.run_built_executable('exe', chdir='relocate/noload',
32                          stdout='Hello from shared.c.\n')
33test.build('build/all.gyp', test.ALL, chdir='relocate/noload',
34           arguments=['NO_LOAD=z'])
35test.run_built_executable('exe', chdir='relocate/noload',
36                          stdout='Hello from shared.c.\n')
37
38# Make sure we can rebuild without reloading the sub .mk file.
39with open('relocate/noload/main.c', 'a') as src_file:
40  src_file.write("\n")
41test.build('build/all.gyp', test.ALL, chdir='relocate/noload',
42           arguments=['NO_LOAD=lib'])
43test.run_built_executable('exe', chdir='relocate/noload',
44                          stdout='Hello from shared.c.\n')
45
46# Change shared.c, but verify that it doesn't get rebuild if we don't load it.
47with open('relocate/noload/lib/shared.c', 'w') as shared_file:
48  shared_file.write(
49      '#include "shared.h"\n'
50      'const char kSharedStr[] = "modified";\n'
51  )
52test.build('build/all.gyp', test.ALL, chdir='relocate/noload',
53           arguments=['NO_LOAD=lib'])
54test.run_built_executable('exe', chdir='relocate/noload',
55                          stdout='Hello from shared.c.\n')
56
57test.pass_test()
58