Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Functions for discovering the build directory.""" | 5 """Functions for discovering the build directory.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 | 10 |
| 11 def IsFileNewerThanFile(file_a, file_b): | |
| 12 """Returns True if file_a's mtime is newer than file_b's.""" | |
| 13 file_a_stat = 0 | |
| 14 file_b_stat = 0 | |
| 15 | |
| 16 try: | |
| 17 file_a_stat = os.path.getmtime(file_a) | |
| 18 except os.error: | |
| 19 pass | |
|
M-A Ruel
2013/10/21 13:12:20
optional: You could put file_a_stat = 0 here, savi
Nico
2013/10/21 14:14:09
Done.
| |
| 20 | |
| 21 try: | |
| 22 file_b_stat = os.path.getmtime(file_b) | |
| 23 except os.error: | |
| 24 pass | |
| 25 | |
| 26 return file_a_stat > file_b_stat | |
| 27 | |
| 28 | |
| 11 def AreNinjaFilesNewerThanXcodeFiles(src_dir=None): | 29 def AreNinjaFilesNewerThanXcodeFiles(src_dir=None): |
| 12 """Returns True if the generated ninja files are newer than the generated | 30 """Returns True if the generated ninja files are newer than the generated |
| 13 xcode files. | 31 xcode files. |
| 14 | 32 |
| 15 Parameters: | 33 Parameters: |
| 16 src_dir: The path to the src directory. If None, it's assumed to be | 34 src_dir: The path to the src directory. If None, it's assumed to be |
| 17 at src/ relative to the current working directory. | 35 at src/ relative to the current working directory. |
| 18 """ | 36 """ |
| 19 xcode_stat = 0 | |
| 20 ninja_stat = 0 | |
| 21 | |
| 22 src_dir = src_dir or 'src' | 37 src_dir = src_dir or 'src' |
| 23 | |
| 24 ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja') | 38 ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja') |
| 25 try: | |
| 26 ninja_stat = os.path.getmtime(ninja_path) | |
| 27 except os.error: | |
| 28 pass | |
| 29 | |
| 30 xcode_path = os.path.join( | 39 xcode_path = os.path.join( |
| 31 src_dir, 'build', 'all.xcodeproj', 'project.pbxproj') | 40 src_dir, 'build', 'all.xcodeproj', 'project.pbxproj') |
| 32 try: | 41 return IsFileNewerThanFile(ninja_path, xcode_path) |
| 33 xcode_stat = os.path.getmtime(xcode_path) | |
| 34 except os.error: | |
| 35 pass | |
| 36 | |
| 37 return ninja_stat > xcode_stat | |
| 38 | 42 |
| 39 | 43 |
| 44 def AreNinjaFilesNewerThanMSVSFiles(src_dir=None): | |
| 45 """Returns True if the generated ninja files are newer than the generated | |
| 46 msvs files. | |
| 47 | |
| 48 Parameters: | |
| 49 src_dir: The path to the src directory. If None, it's assumed to be | |
| 50 at src/ relative to the current working directory. | |
| 51 """ | |
| 52 src_dir = src_dir or 'src' | |
| 53 ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja') | |
| 54 msvs_path = os.path.join(src_dir, 'build', 'all.sln') | |
| 55 return IsFileNewerThanFile(ninja_path, msvs_path) | |
| 56 | |
| 57 | |
| 58 # TODO(thakis): Remove parameters of this function, rename it to | |
|
M-A Ruel
2013/10/21 13:12:20
I prefer the TODO comment to be inside the functio
Nico
2013/10/21 14:14:09
Done.
| |
| 59 # GetBuildDirectory(), make it return just a path not a tuple. | |
| 40 def ConvertBuildDirToLegacy(build_dir, use_out=False): | 60 def ConvertBuildDirToLegacy(build_dir, use_out=False): |
| 41 """Returns a tuple of (build_dir<str>, legacy<bool>). | 61 """Returns the path to the build directory, relative to the checkout root. |
| 62 Assumes that the current working directory is the checkout root. | |
|
M-A Ruel
2013/10/21 13:12:20
Add an empty line above.
Nico
2013/10/21 14:14:09
Done.
| |
| 42 """ | 63 """ |
| 43 # TODO(thakis): Make this the canonical source of truth for build_dir for | 64 if sys.platform.startswith('linux'): |
| 44 # slave scripts, remove all parameters. | 65 return 'src/out', False |
| 45 legacy_paths = { | |
| 46 'darwin': 'xcodebuild', | |
| 47 } | |
| 48 bad = False | |
| 49 | 66 |
| 50 platform_key = None | 67 if sys.platform == 'darwin': |
| 51 for key in legacy_paths: | 68 if AreNinjaFilesNewerThanXcodeFiles(): |
| 52 if sys.platform.startswith(key): | 69 return 'src/out', False |
| 53 platform_key = key | 70 return 'src/xcodebuild', False |
| 54 break | |
| 55 | 71 |
| 56 if (build_dir == 'src/build' and (platform_key or use_out)): | 72 if sys.platform == 'cygwin' or sys.platform.startswith('win'): |
| 57 print >> sys.stderr, ( | 73 if AreNinjaFilesNewerThanMSVSFiles(): |
| 58 'WARNING: Passed "%s" as --build-dir option on %s. ' | 74 return 'src/out', False |
| 59 'This is almost certainly incorrect.' % (build_dir, platform_key)) | 75 return 'src/build', False |
| 60 if use_out: | |
| 61 legacy_path = 'out' | |
| 62 else: | |
| 63 legacy_path = legacy_paths[platform_key] | |
| 64 build_dir = os.path.join(os.path.dirname(build_dir), legacy_path) | |
| 65 print >> sys.stderr, ('Assuming you meant "%s"' % build_dir) | |
| 66 bad = True | |
| 67 | 76 |
| 68 return (build_dir, bad) | 77 raise Exception('Unexpected platform ' + sys.platform) |
|
M-A Ruel
2013/10/21 13:12:20
s/Exception/NotImplementedError/
and use '... %s'
Nico
2013/10/21 14:14:09
Done.
| |
| OLD | NEW |