gyptest-default.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 Google Inc. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """
  6. Verify the settings that cause a set of programs to be created in
  7. a specific build directory, and that no intermediate built files
  8. get created outside of that build directory hierarchy even when
  9. referred to with deeply-nested ../../.. paths.
  10. """
  11. import TestGyp
  12. # TODO(mmoss): Make only supports (theoretically) a single, global build
  13. # directory (through GYP_GENERATOR_FLAGS 'output_dir'), rather than
  14. # gyp-file-specific settings (e.g. the stuff in builddir.gypi) that the other
  15. # generators support, so this doesn't work yet for make.
  16. # TODO(mmoss) Make also has the issue that the top-level Makefile is written to
  17. # the "--depth" location, which is one level above 'src', but then this test
  18. # moves 'src' somewhere else, leaving the Makefile behind, so make can't find
  19. # its sources. I'm not sure if make is wrong for writing outside the current
  20. # directory, or if the test is wrong for assuming everything generated is under
  21. # the current directory.
  22. # Android, Ninja, and CMake do not support setting the build directory.
  23. test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android', '!cmake'])
  24. test.run_gyp('prog1.gyp', '--depth=..', chdir='src')
  25. if test.format == 'msvs':
  26. if test.uses_msbuild:
  27. test.must_contain('src/prog1.vcxproj',
  28. '<OutDir>..\\builddir\\Default\\</OutDir>')
  29. else:
  30. test.must_contain('src/prog1.vcproj',
  31. 'OutputDirectory="..\\builddir\\Default\\"')
  32. test.relocate('src', 'relocate/src')
  33. test.subdir('relocate/builddir')
  34. # Make sure that all the built ../../etc. files only get put under builddir,
  35. # by making all of relocate read-only and then making only builddir writable.
  36. test.writable('relocate', False)
  37. test.writable('relocate/builddir', True)
  38. # Suppress the test infrastructure's setting SYMROOT on the command line.
  39. test.build('prog1.gyp', SYMROOT=None, chdir='relocate/src')
  40. expect1 = """\
  41. Hello from prog1.c
  42. Hello from func1.c
  43. """
  44. expect2 = """\
  45. Hello from subdir2/prog2.c
  46. Hello from func2.c
  47. """
  48. expect3 = """\
  49. Hello from subdir2/subdir3/prog3.c
  50. Hello from func3.c
  51. """
  52. expect4 = """\
  53. Hello from subdir2/subdir3/subdir4/prog4.c
  54. Hello from func4.c
  55. """
  56. expect5 = """\
  57. Hello from subdir2/subdir3/subdir4/subdir5/prog5.c
  58. Hello from func5.c
  59. """
  60. def run_builddir(prog, expect):
  61. dir = 'relocate/builddir/Default/'
  62. test.run(program=test.workpath(dir + prog), stdout=expect)
  63. run_builddir('prog1', expect1)
  64. run_builddir('prog2', expect2)
  65. run_builddir('prog3', expect3)
  66. run_builddir('prog4', expect4)
  67. run_builddir('prog5', expect5)
  68. test.pass_test()