diff --git a/gclient.py b/gclient.py index 165ef392f..fbc16cc6d 100644 --- a/gclient.py +++ b/gclient.py @@ -103,32 +103,39 @@ For additional help on a subcommand or examples of usage, try """) -DEFAULT_CLIENT_FILE_TEXT = ("""\ -# An element of this array (a "solution") describes a repository directory -# that will be checked out into your working copy. Each solution may -# optionally define additional dependencies (via its DEPS file) to be -# checked out alongside the solution's directory. A solution may also -# specify custom dependencies (via the "custom_deps" property) that -# override or augment the dependencies specified by the DEPS file. -# If a "safesync_url" is specified, it is assumed to reference the location of -# a text file which contains nothing but the last known good SCM revision to -# sync against. It is fetched if specified and used unless --head is passed +def attr(attr, data): + """Sets an attribute on a function.""" + def hook(fn): + setattr(fn, attr, data) + return fn + return hook + +## GClient implementation. + + +class GClient(object): + """Object that represent a gclient checkout.""" + + supported_commands = [ + 'cleanup', 'diff', 'export', 'pack', 'revert', 'status', 'update', + 'runhooks' + ] + + DEPS_FILE = 'DEPS' + + DEFAULT_CLIENT_FILE_TEXT = ("""\ solutions = [ { "name" : "%(solution_name)s", "url" : "%(solution_url)s", "custom_deps" : { - # To use the trunk of a component instead of what's in DEPS: - #"component": "https://svnserver/component/trunk/", - # To exclude a component from your working copy: - #"data/really_large_component": None, }, "safesync_url": "%(safesync_url)s" }, ] """) -DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\ + DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\ { "name" : "%(solution_name)s", "url" : "%(solution_url)s", "custom_deps" : { @@ -138,34 +145,13 @@ DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\ }, """) -DEFAULT_SNAPSHOT_FILE_TEXT = ("""\ -# An element of this array (a "solution") describes a repository directory -# that will be checked out into your working copy. Each solution may -# optionally define additional dependencies (via its DEPS file) to be -# checked out alongside the solution's directory. A solution may also -# specify custom dependencies (via the "custom_deps" property) that -# override or augment the dependencies specified by the DEPS file. -# If a "safesync_url" is specified, it is assumed to reference the location of -# a text file which contains nothing but the last known good SCM revision to -# sync against. It is fetched if specified and used unless --head is passed - + DEFAULT_SNAPSHOT_FILE_TEXT = ("""\ +# Snapshot generated with gclient revinfo --snapshot solutions = [ %(solution_list)s ] """) - -## GClient implementation. - - -class GClient(object): - """Object that represent a gclient checkout.""" - - supported_commands = [ - 'cleanup', 'diff', 'export', 'pack', 'revert', 'status', 'update', - 'runhooks' - ] - def __init__(self, root_dir, options): self._root_dir = root_dir self._options = options @@ -231,7 +217,7 @@ class GClient(object): return client def SetDefaultConfig(self, solution_name, solution_url, safesync_url): - self.SetConfig(DEFAULT_CLIENT_FILE_TEXT % { + self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { 'solution_name': solution_name, 'solution_url': solution_url, 'safesync_url' : safesync_url, @@ -386,7 +372,7 @@ class GClient(object): if "all" in deps_to_include: deps_to_include = list(set(deps_os_choices.itervalues())) else: - deps_to_include = [deps_os_choices.get(self._options.platform, "unix")] + deps_to_include = [deps_os_choices.get(sys.platform, "unix")] deps_to_include = set(deps_to_include) for deps_os_key in deps_to_include: @@ -588,7 +574,7 @@ class GClient(object): # Run on the base solutions first. for solution in solutions: name = solution["name"] - deps_file = solution.get("deps_file", self._options.deps_file) + deps_file = solution.get("deps_file", self.DEPS_FILE) if '/' in deps_file or '\\' in deps_file: raise gclient_utils.Error('deps_file name must not be a path, just a ' 'filename.') @@ -647,7 +633,7 @@ class GClient(object): if isinstance(deps[d], self.FromImpl): filename = os.path.join(self._root_dir, deps[d].module_name, - self._options.deps_file) + self.DEPS_FILE) content = gclient_utils.FileRead(filename) sub_deps = self._ParseSolutionDeps(deps[d].module_name, content, {}, False) @@ -774,7 +760,7 @@ class GClient(object): (url, rev) = GetURLAndRev(name, solution["url"]) entries[name] = "%s@%s" % (url, rev) solution_names[name] = "%s@%s" % (url, rev) - deps_file = solution.get("deps_file", self._options.deps_file) + deps_file = solution.get("deps_file", DEPS_FILE) if '/' in deps_file or '\\' in deps_file: raise gclient_utils.Error('deps_file name must not be a path, just a ' 'filename.') @@ -809,7 +795,7 @@ class GClient(object): content = gclient_utils.FileRead(os.path.join( self._root_dir, deps[d].module_name, - self._options.deps_file)) + DEPS_FILE)) sub_deps = self._ParseSolutionDeps(deps[d].module_name, content, {}) (url, rev) = GetURLAndRev(d, sub_deps[d]) entries[d] = "%s@%s" % (url, rev) @@ -820,7 +806,7 @@ class GClient(object): custom_deps = ",\n ".join(["\"%s\": \"%s\"" % (x, entries[x]) for x in sorted(entries.keys())]) - new_gclient += DEFAULT_SNAPSHOT_SOLUTION_TEXT % { + new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % { 'solution_name': name, 'solution_url': url, 'safesync_url' : "", diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 5bfbaf148..7672b6823 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -52,16 +52,15 @@ class GClientBaseTestCase(BaseTestCase): class GclientTestCase(GClientBaseTestCase): class OptionsObject(object): - def __init__(self, test_case, verbose=False, spec=None, + def __init__(self, test_case, verbose=0, spec=None, config_filename='a_file_name', entries_filename='a_entry_file_name', - deps_file='a_deps_file_name', force=False, nohooks=False): + force=False, nohooks=False): self.verbose = verbose + self.config_filename = config_filename + #self.entries_filename = entries_filename self.spec = spec self.name = None - self.config_filename = config_filename - self.entries_filename = entries_filename - self.deps_file = deps_file self.force = force self.nohooks = nohooks self.revisions = [] @@ -69,13 +68,8 @@ class GclientTestCase(GClientBaseTestCase): self.deps_os = None self.head = False - # Mox - self.platform = test_case.platform - def setUp(self): GClientBaseTestCase.setUp(self) - self.platform = 'darwin' - self.args = self.Args() self.root_dir = self.Dir() self.url = self.Url() @@ -309,7 +303,7 @@ class GClientClassTestCase(GclientTestCase): solution_name = 'solution name' solution_url = 'solution url' safesync_url = 'safesync url' - default_text = gclient.DEFAULT_CLIENT_FILE_TEXT % { + default_text = gclient.Gclient.DEFAULT_CLIENT_FILE_TEXT % { 'solution_name' : solution_name, 'solution_url' : solution_url, 'safesync_url' : safesync_url @@ -1037,7 +1031,7 @@ deps = { gclient.gclient_utils.FileRead( gclient.os.path.join(self.root_dir, name, options.deps_file) ).AndReturn(deps_content) - + # base gets updated. gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn( gclient.gclient_scm.CreateSCM) @@ -1051,7 +1045,7 @@ deps = { gclient.gclient_scm.CreateSCM) gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) - # Process is done and will write an .gclient_entries. + # Process is done and will write an .gclient_entries. gclient.os.path.exists( gclient.os.path.join(self.root_dir, options.entries_filename) ).AndReturn(False) @@ -1100,7 +1094,7 @@ deps = { gclient.gclient_utils.FileRead( gclient.os.path.join(self.root_dir, name, options.deps_file) ).AndReturn(deps_content) - + # base gets updated. gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn( gclient.gclient_scm.CreateSCM) @@ -1114,7 +1108,7 @@ deps = { gclient.gclient_scm.CreateSCM) gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) - # Process is done and will write an .gclient_entries. + # Process is done and will write an .gclient_entries. gclient.os.path.exists( gclient.os.path.join(self.root_dir, options.entries_filename) ).AndReturn(False) @@ -1163,7 +1157,7 @@ deps = { gclient.gclient_utils.FileRead( gclient.os.path.join(self.root_dir, name, options.deps_file) ).AndReturn(deps_content) - + # base gets updated. gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn( gclient.gclient_scm.CreateSCM) @@ -1181,7 +1175,7 @@ deps = { 'main').AndReturn(gclient.gclient_scm.CreateSCM) gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) - # Process is done and will write an .gclient_entries. + # Process is done and will write an .gclient_entries. gclient.os.path.exists( gclient.os.path.join(self.root_dir, options.entries_filename) ).AndReturn(False)