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

Side by Side Diff: scripts/slave/recipe_modules/git/api.py

Issue 24737002: Add Paths as first-class types in configs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 from slave import recipe_api 5 from slave import recipe_api
6 6
7 class GitApi(recipe_api.RecipeApi): 7 class GitApi(recipe_api.RecipeApi):
8 def __call__(self, *args, **kwargs): 8 def __call__(self, *args, **kwargs):
9 """Return a git command step.""" 9 """Return a git command step."""
10 name = 'git '+args[0] 10 name = 'git '+args[0]
11 # Distinguish 'git config' commands by the variable they are setting. 11 # Distinguish 'git config' commands by the variable they are setting.
12 if args[0] == 'config' and not args[1].startswith('-'): 12 if args[0] == 'config' and not args[1].startswith('-'):
13 name += ' ' + args[1] 13 name += ' ' + args[1]
14 if 'cwd' not in kwargs: 14 if 'cwd' not in kwargs:
15 kwargs.setdefault('cwd', self.m.path.checkout()) 15 kwargs.setdefault('cwd', self.m.path.checkout())
16 git_cmd = 'git' 16 git_cmd = 'git'
17 if self.m.platform.is_win: 17 if self.m.platform.is_win:
18 git_cmd = self.m.path.depot_tools('git.bat') 18 git_cmd = self.m.path.depot_tools('git.bat')
19 return self.m.step(name, [git_cmd] + list(args), **kwargs) 19 return self.m.step(name, [git_cmd] + list(args), **kwargs)
20 20
21 def checkout(self, url, ref='master', dir_path=None, recursive=False, 21 def checkout(self, url, ref='master', dir_path=None, recursive=False,
22 keep_paths=None): 22 keep_paths=None):
23 """Returns an iterable of steps to perform a full git checkout. 23 """Returns an iterable of steps to perform a full git checkout.
24 Args: 24 Args:
25 url (string): url of remote repo to use as upstream 25 url (string): url of remote repo to use as upstream
26 ref (string): ref to check out after fetching 26 ref (string): ref to check out after fetching
27 dir_path (string): optional directory to clone into 27 dir_path (Path): optional directory to clone into
28 recursive (bool): whether to recursively fetch submodules or not 28 recursive (bool): whether to recursively fetch submodules or not
29 keep_paths (iterable of strings): paths to ignore during git-clean; 29 keep_paths (iterable of strings): paths to ignore during git-clean;
30 paths are gitignore-style patterns relative to checkout_path. 30 paths are gitignore-style patterns relative to checkout_path.
31 """ 31 """
32 if not dir_path: 32 if not dir_path:
33 dir_path = url.rsplit('/', 1)[-1] 33 dir_path = url.rsplit('/', 1)[-1]
34 if dir_path.endswith('.git'): # ex: https://host/foobar.git 34 if dir_path.endswith('.git'): # ex: https://host/foobar.git
35 dir_path = dir_path[:-len('.git')] 35 dir_path = dir_path[:-len('.git')]
36 36
37 # ex: ssh://host:repo/foobar/.git 37 # ex: ssh://host:repo/foobar/.git
38 dir_path = dir_path or dir_path.rsplit('/', 1)[-1] 38 dir_path = dir_path or dir_path.rsplit('/', 1)[-1]
39 39
40 dir_path = self.m.path.slave_build(dir_path) 40 dir_path = self.m.path.slave_build(dir_path)
41 assert self.m.path.pardir not in dir_path 41 self.m.path.set_dynamic_path('checkout', dir_path, default=True)
42 self.m.path.add_checkout(dir_path)
43 42
44 full_ref = 'refs/heads/%s' % ref if '/' not in ref else ref 43 full_ref = 'refs/heads/%s' % ref if '/' not in ref else ref
45 44
46 recursive_args = ['--recurse-submodules'] if recursive else [] 45 recursive_args = ['--recurse-submodules'] if recursive else []
47 clean_args = list(self.m.itertools.chain( 46 clean_args = list(self.m.itertools.chain(
48 *[('-e', path) for path in keep_paths or []])) 47 *[('-e', path) for path in keep_paths or []]))
49 48
50 git_setup_args = ['--path', dir_path, '--url', url] 49 git_setup_args = ['--path', dir_path, '--url', url]
51 if self.m.platform.is_win: 50 if self.m.platform.is_win:
52 git_setup_args += ['--git_cmd_path', self.m.path.depot_tools('git.bat')] 51 git_setup_args += ['--git_cmd_path', self.m.path.depot_tools('git.bat')]
53 52
54 return [ 53 return [
55 self.m.python('git setup', 54 self.m.python('git setup',
56 self.m.path.build('scripts', 'slave', 'git_setup.py'), 55 self.m.path.build('scripts', 'slave', 'git_setup.py'),
57 git_setup_args), 56 git_setup_args),
58 # git_setup.py always sets the repo at the given url as remote 'origin'. 57 # git_setup.py always sets the repo at the given url as remote 'origin'.
59 self('fetch', 'origin', *recursive_args), 58 self('fetch', 'origin', *recursive_args),
60 self('update-ref', full_ref, 'origin/' + ref), 59 self('update-ref', full_ref, 'origin/' + ref),
61 self('clean', '-f', '-d', '-x', *clean_args), 60 self('clean', '-f', '-d', '-x', *clean_args),
62 self('checkout', '-f', ref), 61 self('checkout', '-f', ref),
63 self('submodule', 'update', '--init', '--recursive', 62 self('submodule', 'update', '--init', '--recursive',
64 cwd=dir_path), 63 cwd=dir_path),
65 ] 64 ]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698