| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 Verifies build of an executable with C++ define specified by a gyp define, and | 8 Verifies build of an executable with C++ define specified by a gyp define, and |
| 9 the use of the environment during regeneration when the gyp file changes. | 9 the use of the environment during regeneration when the gyp file changes. |
| 10 """ | 10 """ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 formats = ['make'] | 27 formats = ['make'] |
| 28 if sys.platform.startswith('linux'): | 28 if sys.platform.startswith('linux'): |
| 29 # Only Linux ninja generator supports CFLAGS. | 29 # Only Linux ninja generator supports CFLAGS. |
| 30 formats.append('ninja') | 30 formats.append('ninja') |
| 31 | 31 |
| 32 test = TestGyp.TestGyp(formats=formats) | 32 test = TestGyp.TestGyp(formats=formats) |
| 33 | 33 |
| 34 try: | 34 try: |
| 35 PushEnv() | 35 PushEnv() |
| 36 os.environ['CFLAGS'] = '-O0' | 36 os.environ['CFLAGS'] = '' |
| 37 os.environ['GYP_CROSSCOMPILE'] = '1' | 37 os.environ['GYP_CROSSCOMPILE'] = '1' |
| 38 test.run_gyp('cflags.gyp') | 38 test.run_gyp('cflags.gyp') |
| 39 test.build('cflags.gyp') | 39 test.build('cflags.gyp') |
| 40 finally: | 40 finally: |
| 41 # We clear the environ after calling gyp. When the auto-regeneration happens, | 41 # We clear the environ after calling gyp. When the auto-regeneration happens, |
| 42 # the same define should be reused anyway. Reset to empty string first in | 42 # the same define should be reused anyway. Reset to empty string first in |
| 43 # case the platform doesn't support unsetenv. | 43 # case the platform doesn't support unsetenv. |
| 44 PopEnv() | 44 PopEnv() |
| 45 | 45 |
| 46 | 46 |
| 47 expect = """\ | 47 expect = """FOO not defined\n""" |
| 48 Using no optimization flag | |
| 49 """ | |
| 50 test.run_built_executable('cflags', stdout=expect) | 48 test.run_built_executable('cflags', stdout=expect) |
| 51 test.run_built_executable('cflags_host', stdout=expect) | 49 test.run_built_executable('cflags_host', stdout=expect) |
| 52 | 50 |
| 53 test.sleep() | 51 test.sleep() |
| 54 | 52 |
| 55 try: | 53 try: |
| 56 PushEnv() | 54 PushEnv() |
| 57 os.environ['CFLAGS'] = '-O2' | 55 os.environ['CFLAGS'] = '-DFOO=1' |
| 58 os.environ['GYP_CROSSCOMPILE'] = '1' | 56 os.environ['GYP_CROSSCOMPILE'] = '1' |
| 59 test.run_gyp('cflags.gyp') | 57 test.run_gyp('cflags.gyp') |
| 60 test.build('cflags.gyp') | 58 test.build('cflags.gyp') |
| 61 finally: | 59 finally: |
| 62 # We clear the environ after calling gyp. When the auto-regeneration happens, | 60 # We clear the environ after calling gyp. When the auto-regeneration happens, |
| 63 # the same define should be reused anyway. Reset to empty string first in | 61 # the same define should be reused anyway. Reset to empty string first in |
| 64 # case the platform doesn't support unsetenv. | 62 # case the platform doesn't support unsetenv. |
| 65 PopEnv() | 63 PopEnv() |
| 66 | 64 |
| 67 | 65 |
| 68 expect = """\ | 66 expect = """FOO defined\n""" |
| 69 Using an optimization flag | |
| 70 """ | |
| 71 test.run_built_executable('cflags', stdout=expect) | 67 test.run_built_executable('cflags', stdout=expect) |
| 72 | 68 |
| 73 # Environment variables shouldn't influence the flags for the host. | 69 # Environment variables shouldn't influence the flags for the host. |
| 74 expect = """\ | 70 expect = """FOO not defined\n""" |
| 75 Using no optimization flag | |
| 76 """ | |
| 77 test.run_built_executable('cflags_host', stdout=expect) | 71 test.run_built_executable('cflags_host', stdout=expect) |
| 78 | 72 |
| 79 test.sleep() | 73 test.sleep() |
| 80 | 74 |
| 81 try: | 75 try: |
| 82 PushEnv() | 76 PushEnv() |
| 83 os.environ['CFLAGS'] = '-O0' | 77 os.environ['CFLAGS'] = '' |
| 84 test.run_gyp('cflags.gyp') | 78 test.run_gyp('cflags.gyp') |
| 85 test.build('cflags.gyp') | 79 test.build('cflags.gyp') |
| 86 finally: | 80 finally: |
| 87 # We clear the environ after calling gyp. When the auto-regeneration happens, | 81 # We clear the environ after calling gyp. When the auto-regeneration happens, |
| 88 # the same define should be reused anyway. Reset to empty string first in | 82 # the same define should be reused anyway. Reset to empty string first in |
| 89 # case the platform doesn't support unsetenv. | 83 # case the platform doesn't support unsetenv. |
| 90 PopEnv() | 84 PopEnv() |
| 91 | 85 |
| 92 | 86 |
| 93 expect = """\ | 87 expect = """FOO not defined\n""" |
| 94 Using no optimization flag | |
| 95 """ | |
| 96 test.run_built_executable('cflags', stdout=expect) | 88 test.run_built_executable('cflags', stdout=expect) |
| 97 | 89 |
| 98 test.sleep() | 90 test.sleep() |
| 99 | 91 |
| 100 try: | 92 try: |
| 101 PushEnv() | 93 PushEnv() |
| 102 os.environ['CFLAGS'] = '-O2' | 94 os.environ['CFLAGS'] = '-DFOO=1' |
| 103 test.run_gyp('cflags.gyp') | 95 test.run_gyp('cflags.gyp') |
| 104 test.build('cflags.gyp') | 96 test.build('cflags.gyp') |
| 105 finally: | 97 finally: |
| 106 # We clear the environ after calling gyp. When the auto-regeneration happens, | 98 # We clear the environ after calling gyp. When the auto-regeneration happens, |
| 107 # the same define should be reused anyway. Reset to empty string first in | 99 # the same define should be reused anyway. Reset to empty string first in |
| 108 # case the platform doesn't support unsetenv. | 100 # case the platform doesn't support unsetenv. |
| 109 PopEnv() | 101 PopEnv() |
| 110 | 102 |
| 111 | 103 |
| 112 expect = """\ | 104 expect = """FOO defined\n""" |
| 113 Using an optimization flag | |
| 114 """ | |
| 115 test.run_built_executable('cflags', stdout=expect) | 105 test.run_built_executable('cflags', stdout=expect) |
| 116 | 106 |
| 117 test.pass_test() | 107 test.pass_test() |
| OLD | NEW |