build_directory.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. """Functions for discovering and clearing the build directory."""
  5. import os
  6. import sys
  7. def IsFileNewerThanFile(file_a, file_b):
  8. """Returns True if file_a's mtime is newer than file_b's."""
  9. def getmtime(f):
  10. try:
  11. return os.path.getmtime(f)
  12. except os.error:
  13. return 0
  14. return getmtime(file_a) >= getmtime(file_b)
  15. def AreNinjaFilesNewerThanXcodeFiles(src_dir=None):
  16. """Returns True if the generated ninja files are newer than the generated
  17. xcode files.
  18. Parameters:
  19. src_dir: The path to the src directory. If None, it's assumed to be
  20. at src/ relative to the current working directory.
  21. """
  22. src_dir = src_dir or 'src'
  23. ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja')
  24. xcode_path = os.path.join(
  25. src_dir, 'build', 'all.xcodeproj', 'project.pbxproj')
  26. return IsFileNewerThanFile(ninja_path, xcode_path)
  27. def GetBuildOutputDirectory(src_dir=None, cros_board=None):
  28. """Returns the path to the build directory, relative to the checkout root.
  29. Assumes that the current working directory is the checkout root.
  30. """
  31. # src_dir is only needed for compiling v8, which uses compile.py (but no other
  32. # of the build scripts), but its source root isn't "src" -- crbug.com/315004
  33. if src_dir is None:
  34. src_dir = 'src'
  35. if sys.platform.startswith('linux'):
  36. out_dirname = 'out'
  37. if cros_board:
  38. # Simple chrome workflow output (e.g., "out_x86-generic")
  39. out_dirname += '_%s' % (cros_board,)
  40. return os.path.join(src_dir, out_dirname)
  41. assert not cros_board, "'cros_board' not supported on this platform"
  42. if sys.platform == 'cygwin' or sys.platform.startswith('win') or (
  43. sys.platform == 'darwin'):
  44. return os.path.join(src_dir, 'out')
  45. raise NotImplementedError('Unexpected platform %s' % sys.platform)