OLD | NEW |
1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 """Utilities for testing with real repos (e.g. git).""" | 5 """Utilities for testing with real repos (e.g. git).""" |
6 | 6 |
7 | 7 |
8 import contextlib | 8 import contextlib |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return package.PackageSpec.load_proto(package.ProtoFile(config_file)) | 82 return package.PackageSpec.load_proto(package.ProtoFile(config_file)) |
83 | 83 |
84 def create_repo(self, name, spec): | 84 def create_repo(self, name, spec): |
85 """Creates a real git repo with simple recipes.cfg.""" | 85 """Creates a real git repo with simple recipes.cfg.""" |
86 repo_dir = os.path.join(self._root_dir, name) | 86 repo_dir = os.path.join(self._root_dir, name) |
87 os.mkdir(repo_dir) | 87 os.mkdir(repo_dir) |
88 with in_directory(repo_dir): | 88 with in_directory(repo_dir): |
89 subprocess.check_output(['git', 'init']) | 89 subprocess.check_output(['git', 'init']) |
90 subprocess.check_output(['git', 'remote', 'add', 'origin', repo_dir]) | 90 subprocess.check_output(['git', 'remote', 'add', 'origin', repo_dir]) |
91 with open('recipes.py', 'w') as f: | 91 with open('recipes.py', 'w') as f: |
92 f.write('import subprocess, sys\n' | 92 f.write('\n'.join([ |
93 'sys.exit(subprocess.call(\n' | 93 'import subprocess, sys, os', |
94 ' [sys.executable, %r, "--package", %r] + sys.argv[1:]))' % ( | 94 '#### PER-REPO CONFIGURATION (editable) ####', |
95 self._recipe_tool, | 95 'REPO_ROOT = "."', |
96 os.path.join(repo_dir, 'infra', 'config', 'recipes.cfg'))) | 96 'RECIPES_CFG = os.path.join("infra", "config", "recipes.cfg")', |
| 97 '#### END PER-REPO CONFIGURATION ####', |
| 98 'if sys.argv[1] != "fetch":', |
| 99 ' sys.exit(subprocess.call(', |
| 100 ' [sys.executable, %r, "--package", %r] + sys.argv[1:]))' % ( |
| 101 self._recipe_tool, |
| 102 os.path.join(repo_dir, 'infra', 'config', 'recipes.cfg')), |
| 103 ])) |
97 subprocess.check_output(['git', 'add', 'recipes.py']) | 104 subprocess.check_output(['git', 'add', 'recipes.py']) |
98 rev = self.update_recipes_cfg(name, spec) | 105 rev = self.update_recipes_cfg(name, spec) |
99 return { | 106 return { |
100 'name': name, | 107 'name': name, |
101 'root': repo_dir, | 108 'root': repo_dir, |
102 'revision': rev, | 109 'revision': rev, |
103 'spec': spec, | 110 'spec': spec, |
104 } | 111 } |
105 | 112 |
106 def repo_setup(self, repo_deps): | 113 def repo_setup(self, repo_deps): |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 message = ' '.join( | 319 message = ' '.join( |
313 ['update %r recipe_module: ' % name] + | 320 ['update %r recipe_module: ' % name] + |
314 ['%s(%s)' % t for t in methods.iteritems()] | 321 ['%s(%s)' % t for t in methods.iteritems()] |
315 ) | 322 ) |
316 return self.commit_in_repo(repo, message) | 323 return self.commit_in_repo(repo, message) |
317 | 324 |
318 def reset_repo(self, repo, revision): | 325 def reset_repo(self, repo, revision): |
319 """Resets repo contents to given revision.""" | 326 """Resets repo contents to given revision.""" |
320 with in_directory(repo['root']): | 327 with in_directory(repo['root']): |
321 subprocess.check_output(['git', 'reset', '--hard', revision]) | 328 subprocess.check_output(['git', 'reset', '--hard', revision]) |
OLD | NEW |