Home | History | Annotate | Download | only in library
      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 """
      8 Verifies simple build of a "Hello, world!" program with shared libraries,
      9 including verifying that libraries are rebuilt correctly when functions
     10 move between libraries.
     11 """
     12 
     13 import TestGyp
     14 
     15 test = TestGyp.TestGyp()
     16 
     17 if test.format == 'android':
     18   # This test currently fails on android. Investigate why, fix the issues
     19   # responsible, and reenable this test on android. See bug:
     20   # https://code.google.com/p/gyp/issues/detail?id=436
     21   test.skip_test(message='Test fails on android. Fix and reenable.\n')
     22 
     23 test.run_gyp('library.gyp',
     24              '-Dlibrary=shared_library',
     25              '-Dmoveable_function=lib1',
     26              chdir='src')
     27 
     28 test.relocate('src', 'relocate/src')
     29 
     30 test.build('library.gyp', test.ALL, chdir='relocate/src')
     31 
     32 expect = """\
     33 Hello from program.c
     34 Hello from lib1.c
     35 Hello from lib2.c
     36 Hello from lib1_moveable.c
     37 """
     38 test.run_built_executable('program', chdir='relocate/src', stdout=expect)
     39 
     40 
     41 test.run_gyp('library.gyp',
     42              '-Dlibrary=shared_library',
     43              '-Dmoveable_function=lib2',
     44              chdir='relocate/src')
     45 
     46 # Update program.c to force a rebuild.
     47 test.sleep()
     48 contents = test.read('relocate/src/program.c')
     49 contents = contents.replace('Hello', 'Hello again')
     50 test.write('relocate/src/program.c', contents)
     51 
     52 test.build('library.gyp', test.ALL, chdir='relocate/src')
     53 
     54 expect = """\
     55 Hello again from program.c
     56 Hello from lib1.c
     57 Hello from lib2.c
     58 Hello from lib2_moveable.c
     59 """
     60 test.run_built_executable('program', chdir='relocate/src', stdout=expect)
     61 
     62 
     63 test.run_gyp('library.gyp',
     64              '-Dlibrary=shared_library',
     65              '-Dmoveable_function=lib1',
     66              chdir='relocate/src')
     67 
     68 # Update program.c to force a rebuild.
     69 test.sleep()
     70 contents = test.read('relocate/src/program.c')
     71 contents = contents.replace('again', 'again again')
     72 test.write('relocate/src/program.c', contents)
     73 
     74 # TODO(sgk):  we have to force a rebuild of lib2 so that it weeds out
     75 # the "moved" module.  This should be done in gyp by adding a dependency
     76 # on the generated .vcproj file itself.
     77 test.touch('relocate/src/lib2.c')
     78 
     79 test.build('library.gyp', test.ALL, chdir='relocate/src')
     80 
     81 expect = """\
     82 Hello again again from program.c
     83 Hello from lib1.c
     84 Hello from lib2.c
     85 Hello from lib1_moveable.c
     86 """
     87 test.run_built_executable('program', chdir='relocate/src', stdout=expect)
     88 
     89 
     90 test.pass_test()
     91