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

Side by Side Diff: gclient_utils.py

Issue 1477033002: Make gclient_utils.GetBuildtoolsPath() work in a build-spec checkout (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """Generic utils.""" 5 """Generic utils."""
6 6
7 import codecs 7 import codecs
8 import cStringIO 8 import cStringIO
9 import datetime 9 import datetime
10 import logging 10 import logging
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 CheckCallAndFilter(["git", "rev-parse", "--show-toplevel"], 676 CheckCallAndFilter(["git", "rev-parse", "--show-toplevel"],
677 print_stdout=False, filter_fn=filter_fn) 677 print_stdout=False, filter_fn=filter_fn)
678 except Exception: 678 except Exception:
679 pass 679 pass
680 top_dir = top_dir[0] 680 top_dir = top_dir[0]
681 if os.path.exists(os.path.join(top_dir, 'buildtools')): 681 if os.path.exists(os.path.join(top_dir, 'buildtools')):
682 return top_dir 682 return top_dir
683 return None 683 return None
684 684
685 # Some projects' top directory is not named 'src'. 685 # Some projects' top directory is not named 'src'.
686 source_dir_name = GetGClientPrimarySolutionName(gclient_root) or 'src' 686 solution_dict = _GetGClientPrimarySolution(gclient_root)
687 source_dir_name = solution_dict.get('name', 'src')
687 return os.path.join(gclient_root, source_dir_name) 688 return os.path.join(gclient_root, source_dir_name)
688 689
689 690
690 def GetBuildtoolsPath(): 691 def GetBuildtoolsPath():
691 """Returns the full path to the buildtools directory. 692 """Returns the full path to the buildtools directory.
692 This is based on the root of the checkout containing the current directory.""" 693 This is based on the root of the checkout containing the current directory."""
693 694
694 # Overriding the build tools path by environment is highly unsupported and may 695 # Overriding the build tools path by environment is highly unsupported and may
695 # break without warning. Do not rely on this for anything important. 696 # break without warning. Do not rely on this for anything important.
696 override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH') 697 override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
697 if override is not None: 698 if override is not None:
698 return override 699 return override
699 700
701 # Attempt to find buildtools/ by reading the DEPS file.
702 gclient_root = FindGclientRoot(os.getcwd())
703 if gclient_root:
704 solution_dict = _GetGClientPrimarySolution(gclient_root)
705 deps_dict = _ReadDepsFileForSolution(gclient_root, solution_dict) or {}
706 for sub_path in deps_dict.get('deps', {}):
707 if sub_path.endswith('/buildtools'):
708 return os.path.join(gclient_root, sub_path)
709
710 # Fall-back to heuristics.
700 primary_solution = GetPrimarySolutionPath() 711 primary_solution = GetPrimarySolutionPath()
701 if not primary_solution: 712 if not primary_solution:
702 return None 713 return None
703 buildtools_path = os.path.join(primary_solution, 'buildtools') 714 buildtools_path = os.path.join(primary_solution, 'buildtools')
704 if not os.path.exists(buildtools_path): 715 if not os.path.exists(buildtools_path):
705 # Buildtools may be in the gclient root. 716 # Buildtools may be in the gclient root.
706 gclient_root = FindGclientRoot(os.getcwd())
707 buildtools_path = os.path.join(gclient_root, 'buildtools') 717 buildtools_path = os.path.join(gclient_root, 'buildtools')
708 return buildtools_path 718 return buildtools_path
709 719
710 720
711 def GetBuildtoolsPlatformBinaryPath(): 721 def GetBuildtoolsPlatformBinaryPath():
712 """Returns the full path to the binary directory for the current platform.""" 722 """Returns the full path to the binary directory for the current platform."""
713 buildtools_path = GetBuildtoolsPath() 723 buildtools_path = GetBuildtoolsPath()
714 if not buildtools_path: 724 if not buildtools_path:
715 return None 725 return None
716 726
717 if sys.platform.startswith(('cygwin', 'win')): 727 if sys.platform.startswith(('cygwin', 'win')):
718 subdir = 'win' 728 subdir = 'win'
719 elif sys.platform == 'darwin': 729 elif sys.platform == 'darwin':
720 subdir = 'mac' 730 subdir = 'mac'
721 elif sys.platform.startswith('linux'): 731 elif sys.platform.startswith('linux'):
722 subdir = 'linux64' 732 subdir = 'linux64'
723 else: 733 else:
724 raise Error('Unknown platform: ' + sys.platform) 734 raise Error('Unknown platform: ' + sys.platform)
725 return os.path.join(buildtools_path, subdir) 735 return os.path.join(buildtools_path, subdir)
726 736
727 737
728 def GetExeSuffix(): 738 def GetExeSuffix():
729 """Returns '' or '.exe' depending on how executables work on this platform.""" 739 """Returns '' or '.exe' depending on how executables work on this platform."""
730 if sys.platform.startswith(('cygwin', 'win')): 740 if sys.platform.startswith(('cygwin', 'win')):
731 return '.exe' 741 return '.exe'
732 return '' 742 return ''
733 743
734 744
735 def GetGClientPrimarySolutionName(gclient_root_dir_path): 745 def _ReadDepsFileForSolution(gclient_root, solution_dict):
736 """Returns the name of the primary solution in the .gclient file specified.""" 746 """Reads the DEPS file for the given solution.
737 gclient_config_file = os.path.join(gclient_root_dir_path, '.gclient') 747
748 This stubs out Var(), as it's not currently required.
749 """
750 env = {}
751 if 'name' in solution_dict:
752 deps_file = solution_dict.get('deps_file', 'DEPS')
753 deps_path = os.path.join(gclient_root, solution_dict['name'], deps_file)
754 global_scope = {
755 '__builtins__': {'None': None},
756 'Var': lambda x: '',
757 'deps_os': {},
758 }
759 execfile(deps_path, global_scope, env)
760 return env
761
762
763 def _GetGClientPrimarySolution(gclient_root):
764 """Returns the dict for the primary solution in the given gclient path."""
765 gclient_config_file = os.path.join(gclient_root, '.gclient')
738 env = {} 766 env = {}
739 execfile(gclient_config_file, env) 767 execfile(gclient_config_file, env)
740 solutions = env.get('solutions', []) 768 solutions = env.get('solutions', [])
741 if solutions: 769 if solutions:
742 return solutions[0].get('name') 770 return solutions[0]
743 return None 771 return {}
744 772
745 773
746 def GetGClientRootAndEntries(path=None): 774 def GetGClientRootAndEntries(path=None):
747 """Returns the gclient root and the dict of entries.""" 775 """Returns the gclient root and the dict of entries."""
748 config_file = '.gclient_entries' 776 config_file = '.gclient_entries'
749 root = FindFileUpwards(config_file, path) 777 root = FindFileUpwards(config_file, path)
750 if not root: 778 if not root:
751 print "Can't find %s" % config_file 779 print "Can't find %s" % config_file
752 return None 780 return None
753 config_path = os.path.join(root, config_file) 781 config_path = os.path.join(root, config_file)
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 # Just incase we have some ~/blah paths. 1236 # Just incase we have some ~/blah paths.
1209 target = os.path.abspath(os.path.expanduser(target)) 1237 target = os.path.abspath(os.path.expanduser(target))
1210 if os.path.isfile(target) and os.access(target, os.X_OK): 1238 if os.path.isfile(target) and os.access(target, os.X_OK):
1211 return target 1239 return target
1212 if sys.platform.startswith('win'): 1240 if sys.platform.startswith('win'):
1213 for suffix in ('.bat', '.cmd', '.exe'): 1241 for suffix in ('.bat', '.cmd', '.exe'):
1214 alt_target = target + suffix 1242 alt_target = target + suffix
1215 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): 1243 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK):
1216 return alt_target 1244 return alt_target
1217 return None 1245 return None
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698