| OLD | NEW |
| (Empty) | |
| 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 |
| 5 """Set of utilities to work with buildspec based GClient solutions.""" |
| 6 |
| 7 import config |
| 8 import sys |
| 9 |
| 10 from master.factory import gclient_factory |
| 11 from master import gitiles_poller |
| 12 |
| 13 def GetBuildspecSolution(buildspec, name=None, custom_deps_list=None, |
| 14 managed=None): |
| 15 """Returns GClientSolution that can be used to checkout given buildspec. |
| 16 |
| 17 Args: |
| 18 buildspec: path to buildspec file relative to |
| 19 /chrome/tools/buildspec.git. |
| 20 name: Name for this solution. |
| 21 custom_deps_list: Modifications to make on the DEPS file. |
| 22 managed: Specify managed in .gclient file |
| 23 """ |
| 24 url = (config.Master.git_internal_server_url + |
| 25 '/chrome/tools/buildspec.git') |
| 26 return gclient_factory.GClientSolution( |
| 27 url, |
| 28 name, |
| 29 custom_deps_file=buildspec + '/DEPS', |
| 30 custom_deps_list=custom_deps_list, |
| 31 managed=managed |
| 32 ) |
| 33 |
| 34 def GetFileIsImportant(directory): |
| 35 """ Use FileIsImportant callable to watch changes in the |
| 36 given directory's buildspec DEPS files. |
| 37 |
| 38 Args: |
| 39 directory: the dir of the DEPS file |
| 40 for example 'build/chrome-official' |
| 41 """ |
| 42 def FileIsImportant(change): |
| 43 for fileChanged in change.files: |
| 44 if isinstance(directory, (list, tuple)): |
| 45 for d in directory: |
| 46 if fileChanged.startswith(d): |
| 47 return True |
| 48 elif fileChanged.startswith(directory): |
| 49 return True |
| 50 return False |
| 51 return FileIsImportant |
| 52 |
| 53 class BuildspecPoller(gitiles_poller.GitilesPoller): |
| 54 def __init__(self, buildspec_prefixes, *args, **kwargs): |
| 55 self.buildspec_prefixes = buildspec_prefixes |
| 56 |
| 57 if kwargs['svn_mode']: |
| 58 kwargs.setdefault('repo_url', config.Master.git_internal_server_url + |
| 59 '/chrome/tools/buildspec') |
| 60 kwargs.setdefault('revlinktmpl', 'https://uberchromegw.corp.google.com/' |
| 61 'viewvc/chrome-internal?view=rev&revision=%s') |
| 62 kwargs.setdefault('svn_mode', True) |
| 63 kwargs['svn_branch'] = self.buildspec_svn_branch |
| 64 else: |
| 65 kwargs.setdefault('repo_url', config.Master.git_internal_server_url + |
| 66 '/chrome/tools/buildspec.git') |
| 67 kwargs.setdefault('revlinktmpl', config.Master.git_internal_server_url + |
| 68 '/chrome/tools/buildspec.git/+/%s') |
| 69 |
| 70 kwargs.setdefault('branches', ['master']) |
| 71 kwargs.setdefault('pollInterval', 30) |
| 72 |
| 73 kwargs['change_filter'] = self.buildspec_change_filter |
| 74 gitiles_poller.GitilesPoller.__init__(self, *args, **kwargs) |
| 75 |
| 76 def buildspec_svn_branch(self, commit_json, git_branch): |
| 77 for tree_entry in commit_json.get('tree_diff', []): |
| 78 for prefix in self.buildspec_prefixes: |
| 79 if tree_entry['new_path'].startswith(prefix): |
| 80 return prefix.rstrip('/').split('/')[-1] |
| 81 return git_branch.rpartition('/')[2] |
| 82 |
| 83 def buildspec_change_filter(self, commit_json, git_branch): |
| 84 if 'tree_diff' not in commit_json: |
| 85 return True |
| 86 for tree_entry in commit_json['tree_diff']: |
| 87 for prefix in self.buildspec_prefixes: |
| 88 if tree_entry['new_path'].startswith(prefix): |
| 89 return True |
| 90 return False |
| OLD | NEW |