Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: build/scripts/slave/build_directory.py

Issue 38873003: Reland "Dynamically pick build directory on the slave side." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/scripts/slave/unittests/telemetry_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 def getmtime(f):
14 try:
15 return os.path.getmtime(f)
16 except os.error:
17 return 0
18 return getmtime(file_a) >= getmtime(file_b)
19
20
11 def AreNinjaFilesNewerThanXcodeFiles(src_dir=None): 21 def AreNinjaFilesNewerThanXcodeFiles(src_dir=None):
12 """Returns True if the generated ninja files are newer than the generated 22 """Returns True if the generated ninja files are newer than the generated
13 xcode files. 23 xcode files.
14 24
15 Parameters: 25 Parameters:
16 src_dir: The path to the src directory. If None, it's assumed to be 26 src_dir: The path to the src directory. If None, it's assumed to be
17 at src/ relative to the current working directory. 27 at src/ relative to the current working directory.
18 """ 28 """
19 xcode_stat = 0
20 ninja_stat = 0
21
22 src_dir = src_dir or 'src' 29 src_dir = src_dir or 'src'
23
24 ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja') 30 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( 31 xcode_path = os.path.join(
31 src_dir, 'build', 'all.xcodeproj', 'project.pbxproj') 32 src_dir, 'build', 'all.xcodeproj', 'project.pbxproj')
32 try: 33 return IsFileNewerThanFile(ninja_path, xcode_path)
33 xcode_stat = os.path.getmtime(xcode_path)
34 except os.error:
35 pass
36 34
37 return ninja_stat > xcode_stat 35
36 def AreNinjaFilesNewerThanMSVSFiles(src_dir=None):
37 """Returns True if the generated ninja files are newer than the generated
38 msvs files.
39
40 Parameters:
41 src_dir: The path to the src directory. If None, it's assumed to be
42 at src/ relative to the current working directory.
43 """
44 src_dir = src_dir or 'src'
45 ninja_path = os.path.join(src_dir, 'out', 'Release', 'build.ninja')
46 msvs_path = os.path.join(src_dir, 'build', 'all.sln')
47 return IsFileNewerThanFile(ninja_path, msvs_path)
38 48
39 49
40 def ConvertBuildDirToLegacy(build_dir, use_out=False): 50 def ConvertBuildDirToLegacy(build_dir, use_out=False):
41 """Returns a tuple of (build_dir<str>, legacy<bool>). 51 """Returns the path to the build directory, relative to the checkout root.
52
53 Assumes that the current working directory is the checkout root.
42 """ 54 """
43 # TODO(thakis): Make this the canonical source of truth for build_dir for 55 # TODO(thakis): Remove parameters of this function, rename it to
44 # slave scripts, remove all parameters. 56 # GetBuildDirectory(), make it return just a path not a tuple.
45 legacy_paths = { 57 if sys.platform.startswith('linux'):
46 'darwin': 'xcodebuild', 58 return 'src/out', False
47 }
48 bad = False
49 59
50 platform_key = None 60 if sys.platform == 'darwin':
51 for key in legacy_paths: 61 if AreNinjaFilesNewerThanXcodeFiles():
52 if sys.platform.startswith(key): 62 return 'src/out', False
53 platform_key = key 63 return 'src/xcodebuild', False
54 break
55 64
56 if (build_dir == 'src/build' and (platform_key or use_out)): 65 if sys.platform == 'cygwin' or sys.platform.startswith('win'):
57 print >> sys.stderr, ( 66 if AreNinjaFilesNewerThanMSVSFiles():
58 'WARNING: Passed "%s" as --build-dir option on %s. ' 67 return 'src/out', False
59 'This is almost certainly incorrect.' % (build_dir, platform_key)) 68 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 69
68 return (build_dir, bad) 70 raise NotImplementedError('Unexpected platform %s' % sys.platform)
OLDNEW
« no previous file with comments | « no previous file | build/scripts/slave/unittests/telemetry_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698