| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import hashlib | 5 import hashlib |
| 6 | 6 |
| 7 from recipe_engine import recipe_test_api | 7 from recipe_engine import recipe_test_api |
| 8 | 8 |
| 9 class GclientTestApi(recipe_test_api.RecipeTestApi): | 9 class GclientTestApi(recipe_test_api.RecipeTestApi): |
| 10 def output_json(self, projects, git_mode=False): | 10 def output_json(self, projects): |
| 11 """Deterministically synthesize json.output test data for gclient's | 11 """Deterministically synthesize json.output test data for gclient's |
| 12 --output-json option. | 12 --output-json option. |
| 13 | 13 |
| 14 Args: | 14 Args: |
| 15 projects - a list of project paths (e.g. ['src', 'src/dependency']) | 15 projects - a list of project paths (e.g. ['src', 'src/dependency']) |
| 16 git_mode - Return git hashes instead of svn revs. | |
| 17 """ | 16 """ |
| 18 # TODO(iannucci): Account for parent_got_revision_mapping. Right now the | 17 # TODO(iannucci): Account for parent_got_revision_mapping. Right now the |
| 19 # synthesized json output from this method will always use | 18 # synthesized json output from this method will always use |
| 20 # gen_revision(project), but if parent_got_revision and its ilk are | 19 # gen_revision(project), but if parent_got_revision and its ilk are |
| 21 # specified, we should use those values instead. | 20 # specified, we should use those values instead. |
| 22 return self.m.json.output({ | 21 return self.m.json.output({ |
| 23 'solutions': dict( | 22 'solutions': dict( |
| 24 (p+'/', {'revision': self.gen_revision(p, git_mode)}) | 23 (p+'/', {'revision': self.gen_revision(p)}) |
| 25 for p in projects | 24 for p in projects |
| 26 ) | 25 ) |
| 27 }) | 26 }) |
| 28 | 27 |
| 29 @staticmethod | 28 @staticmethod |
| 30 def gen_revision(project, GIT_MODE): | 29 def gen_revision(project): |
| 31 """Hash project to bogus deterministic revision values.""" | 30 """Hash project to bogus deterministic revision values.""" |
| 32 h = hashlib.sha1(project) | 31 h = hashlib.sha1(project) |
| 33 if GIT_MODE: | 32 return h.hexdigest() |
| 34 return h.hexdigest() | |
| 35 else: # pragma: no cover | |
| 36 import struct | |
| 37 return struct.unpack('!I', h.digest()[:4])[0] % 300000 | |
| OLD | NEW |