Commit e7273d25 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

Reland "gclient: Get rid of parsed_url."

This is a reland of e877b177

Original change's description:
> gclient: Get rid of parsed_url.
>
> There is no reason I can see to set parsed_url so late.
> Also, the tests are misleading, since relative URLs don't behave the way
> the tests led you to believe.
>
> Bug: 839925
> Change-Id: I08d92b7b7847bdc406f003d4a4139d968cc662b1
> Reviewed-on: https://chromium-review.googlesource.com/1047797
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
> Reviewed-by: Marc-Antoine Ruel <maruel@chromium.org>

TBR=agable@chromium.org

Bug: 839925
Change-Id: I9200ec5fbe7289022e9754f0c78676dc931fcaeb
Reviewed-on: https://chromium-review.googlesource.com/1054567
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarJohn Budorick <jbudorick@chromium.org>
parent 3d894aa4
...@@ -278,14 +278,15 @@ class DependencySettings(object): ...@@ -278,14 +278,15 @@ class DependencySettings(object):
self._custom_hooks = custom_hooks or [] self._custom_hooks = custom_hooks or []
# Post process the url to remove trailing slashes. # Post process the url to remove trailing slashes.
if isinstance(self._url, basestring): if isinstance(self.url, basestring):
# urls are sometime incorrectly written as proto://host/path/@rev. Replace # urls are sometime incorrectly written as proto://host/path/@rev. Replace
# it to proto://host/path@rev. # it to proto://host/path@rev.
self._url = self._url.replace('/@', '@') self.set_url(self.url.replace('/@', '@'))
elif not isinstance(self._url, (None.__class__)): elif not isinstance(self.url, (None.__class__)):
raise gclient_utils.Error( raise gclient_utils.Error(
('dependency url must be either string or None, ' ('dependency url must be either string or None, '
'instead of %s') % self._url.__class__.__name__) 'instead of %s') % self.url.__class__.__name__)
# Make any deps_file path platform-appropriate. # Make any deps_file path platform-appropriate.
if self._deps_file: if self._deps_file:
for sep in ['/', '\\']: for sep in ['/', '\\']:
...@@ -357,6 +358,12 @@ class DependencySettings(object): ...@@ -357,6 +358,12 @@ class DependencySettings(object):
def target_cpu(self): def target_cpu(self):
return self.parent.target_cpu return self.parent.target_cpu
def set_url(self, url):
self._url = url
def set_raw_url(self, url):
self._raw_url = url
def get_custom_deps(self, name, url): def get_custom_deps(self, name, url):
"""Returns a custom deps if applicable.""" """Returns a custom deps if applicable."""
if self.parent: if self.parent:
...@@ -383,7 +390,6 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -383,7 +390,6 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
self._pre_deps_hooks = [] self._pre_deps_hooks = []
# Calculates properties: # Calculates properties:
self._parsed_url = None
self._dependencies = [] self._dependencies = []
self._vars = {} self._vars = {}
self._os_dependencies = {} self._os_dependencies = {}
...@@ -429,11 +435,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -429,11 +435,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# It will be a dictionary of {deps_name: {"deps_file": depfile_name}} or # It will be a dictionary of {deps_name: {"deps_file": depfile_name}} or
# None. # None.
self.recursedeps = None self.recursedeps = None
self._OverrideUrl()
# This is inherited from WorkItem. We want the URL to be a resource. # This is inherited from WorkItem. We want the URL to be a resource.
if url and isinstance(url, basestring): if self.url and isinstance(self.url, basestring):
# The url is usually given to gclient either as https://blah@123 # The url is usually given to gclient either as https://blah@123
# or just https://blah. The @123 portion is irrelevant. # or just https://blah. The @123 portion is irrelevant.
self.resources.append(url.split('@')[0]) self.resources.append(self.url.split('@')[0])
# Controls whether we want to print git's output when we first clone the # Controls whether we want to print git's output when we first clone the
# dependency # dependency
...@@ -442,6 +450,50 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -442,6 +450,50 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if not self.name and self.parent: if not self.name and self.parent:
raise gclient_utils.Error('Dependency without name') raise gclient_utils.Error('Dependency without name')
def _OverrideUrl(self):
"""Resolves the parsed url from the parent hierarchy."""
parsed_url = self.get_custom_deps(self._name, self.url)
if parsed_url != self.url:
logging.info('Dependency(%s)._OverrideUrl(%s) -> %s', self._name,
self.url, parsed_url)
self.set_url(parsed_url)
elif isinstance(self.url, basestring):
parsed_url = urlparse.urlparse(self.url)
if (not parsed_url[0] and
not re.match(r'^\w+\@[\w\.-]+\:[\w\/]+', parsed_url[2])):
path = parsed_url[2]
if not path.startswith('/'):
raise gclient_utils.Error(
'relative DEPS entry \'%s\' must begin with a slash' % self.url)
# A relative url. Get the parent url, strip from the last '/'
# (equivalent to unix basename), and append the relative url.
parent_url = self.parent.url
parsed_url = parent_url[:parent_url.rfind('/')] + self.url
logging.info('Dependency(%s)._OverrideUrl(%s) -> %s', self.name,
self.url, parsed_url)
self.set_url(parsed_url)
elif self.url is None:
logging.info('Dependency(%s)._OverrideUrl(None) -> None', self._name)
else:
raise gclient_utils.Error('Unknown url type')
def PinToActualRevision(self):
"""Updates self.url and self.raw_url to the revision checked out on disk."""
if self.url is None:
return
url = raw_url = None
scm = self.CreateSCM(self.url, self.root.root_dir, self.name, self.outbuf)
if os.path.isdir(scm.checkout_path):
revision = scm.revinfo(None, None, None)
url = '%s@%s' % (gclient_utils.SplitUrlRevision(self.url)[0], revision)
raw_url = '%s@%s' % (
gclient_utils.SplitUrlRevision(self.raw_url)[0], revision)
self.set_url(url)
self.set_raw_url(raw_url)
def ToLines(self): def ToLines(self):
s = [] s = []
condition_part = ([' "condition": %r,' % self.condition] condition_part = ([' "condition": %r,' % self.condition]
...@@ -527,10 +579,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -527,10 +579,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# This require a full tree traversal with locks. # This require a full tree traversal with locks.
siblings = [d for d in self.root.subtree(False) if d.name == self.name] siblings = [d for d in self.root.subtree(False) if d.name == self.name]
for sibling in siblings: for sibling in siblings:
self_url = self.LateOverride(self.url)
sibling_url = sibling.LateOverride(sibling.url)
# Allow to have only one to be None or ''. # Allow to have only one to be None or ''.
if self_url != sibling_url and bool(self_url) == bool(sibling_url): if self.url != sibling.url and bool(self.url) == bool(sibling.url):
raise gclient_utils.Error( raise gclient_utils.Error(
('Dependency %s specified more than once:\n' ('Dependency %s specified more than once:\n'
' %s [%s]\n' ' %s [%s]\n'
...@@ -538,53 +588,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -538,53 +588,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
' %s [%s]') % ( ' %s [%s]') % (
self.name, self.name,
sibling.hierarchy(), sibling.hierarchy(),
sibling_url, sibling.url,
self.hierarchy(), self.hierarchy(),
self_url)) self.url))
# In theory we could keep it as a shadow of the other one. In # In theory we could keep it as a shadow of the other one. In
# practice, simply ignore it. # practice, simply ignore it.
logging.warn('Won\'t process duplicate dependency %s' % sibling) logging.warn('Won\'t process duplicate dependency %s' % sibling)
return False return False
return True return True
def LateOverride(self, url):
"""Resolves the parsed url from url."""
assert self.parsed_url == None or not self.should_process, self.parsed_url
parsed_url = self.get_custom_deps(self.name, url)
if parsed_url != url:
logging.info(
'Dependency(%s).LateOverride(%s) -> %s' %
(self.name, url, parsed_url))
return parsed_url
if isinstance(url, basestring):
parsed_url = urlparse.urlparse(url)
if (not parsed_url[0] and
not re.match(r'^\w+\@[\w\.-]+\:[\w\/]+', parsed_url[2])):
# A relative url. Fetch the real base.
path = parsed_url[2]
if not path.startswith('/'):
raise gclient_utils.Error(
'relative DEPS entry \'%s\' must begin with a slash' % url)
# Create a scm just to query the full url.
parent_url = self.parent.parsed_url
scm = self.CreateSCM(
parent_url, self.root.root_dir, None, self.outbuf)
parsed_url = scm.FullUrlForRelativeUrl(url)
else:
parsed_url = url
logging.info(
'Dependency(%s).LateOverride(%s) -> %s' %
(self.name, url, parsed_url))
return parsed_url
if url is None:
logging.info(
'Dependency(%s).LateOverride(%s) -> %s' % (self.name, url, url))
return url
raise gclient_utils.Error('Unknown url type')
@staticmethod @staticmethod
def MergeWithOsDeps(deps, deps_os, target_os_list, process_all_deps): def MergeWithOsDeps(deps, deps_os, target_os_list, process_all_deps):
"""Returns a new "deps" structure that is the deps sent in updated """Returns a new "deps" structure that is the deps sent in updated
...@@ -934,17 +946,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -934,17 +946,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
bad_deps.append(dep) bad_deps.append(dep)
return bad_deps return bad_deps
def FuzzyMatchUrl(self, parsed_url, candidates): def FuzzyMatchUrl(self, candidates):
"""Attempts to find this dependency in the list of candidates. """Attempts to find this dependency in the list of candidates.
It looks first for the URL of this dependency (parsed_url) in the list of It looks first for the URL of this dependency in the list of
candidates. If it doesn't succeed, and the URL ends in '.git', it will try candidates. If it doesn't succeed, and the URL ends in '.git', it will try
looking for the URL minus '.git'. Finally it will try to look for the name looking for the URL minus '.git'. Finally it will try to look for the name
of the dependency. of the dependency.
Args: Args:
parsed_url: str. The parsed URL for this dependency. Something like
"https://example.com/src.git@revision"
candidates: list, dict. The list of candidates in which to look for this candidates: list, dict. The list of candidates in which to look for this
dependency. It can contain URLs as above, or dependency names like dependency. It can contain URLs as above, or dependency names like
"src/some/dep". "src/some/dep".
...@@ -956,8 +966,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -956,8 +966,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
- Its parsed url minus '.git': "https://example.com/src" - Its parsed url minus '.git': "https://example.com/src"
- Its name: "src" - Its name: "src"
""" """
if parsed_url: if self.url:
origin, _ = gclient_utils.SplitUrlRevision(parsed_url) origin, _ = gclient_utils.SplitUrlRevision(self.url)
if origin in candidates: if origin in candidates:
return origin return origin
if origin.endswith('.git') and origin[:-len('.git')] in candidates: if origin.endswith('.git') and origin[:-len('.git')] in candidates:
...@@ -982,24 +992,22 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -982,24 +992,22 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# copy state, so skip the SCM status check. # copy state, so skip the SCM status check.
run_scm = command not in ( run_scm = command not in (
'flatten', 'runhooks', 'recurse', 'validate', None) 'flatten', 'runhooks', 'recurse', 'validate', None)
parsed_url = self.LateOverride(self.url)
file_list = [] if not options.nohooks else None file_list = [] if not options.nohooks else None
revision_override = revision_overrides.pop( revision_override = revision_overrides.pop(
self.FuzzyMatchUrl(parsed_url, revision_overrides), None) self.FuzzyMatchUrl(revision_overrides), None)
if run_scm and parsed_url: if run_scm and self.url:
# Create a shallow copy to mutate revision. # Create a shallow copy to mutate revision.
options = copy.copy(options) options = copy.copy(options)
options.revision = revision_override options.revision = revision_override
self._used_revision = options.revision self._used_revision = options.revision
self._used_scm = self.CreateSCM( self._used_scm = self.CreateSCM(
parsed_url, self.root.root_dir, self.name, self.outbuf, self.url, self.root.root_dir, self.name, self.outbuf,
out_cb=work_queue.out_cb) out_cb=work_queue.out_cb)
self._got_revision = self._used_scm.RunCommand(command, options, args, self._got_revision = self._used_scm.RunCommand(command, options, args,
file_list) file_list)
patch_repo = parsed_url.split('@')[0] patch_repo = self.url.split('@')[0]
patch_ref = patch_refs.pop( patch_ref = patch_refs.pop(self.FuzzyMatchUrl(patch_refs), None)
self.FuzzyMatchUrl(parsed_url, patch_refs), None)
if command == 'update' and patch_ref is not None: if command == 'update' and patch_ref is not None:
self._used_scm.apply_patch_ref(patch_repo, patch_ref, options, self._used_scm.apply_patch_ref(patch_repo, patch_ref, options,
file_list) file_list)
...@@ -1023,7 +1031,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1023,7 +1031,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if self.recursion_limit: if self.recursion_limit:
self.ParseDepsFile(expand_vars=(command != 'flatten')) self.ParseDepsFile(expand_vars=(command != 'flatten'))
self._run_is_done(file_list or [], parsed_url) self._run_is_done(file_list or [])
if self.recursion_limit: if self.recursion_limit:
if command in ('update', 'revert') and not options.noprehooks: if command in ('update', 'revert') and not options.noprehooks:
...@@ -1035,7 +1043,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1035,7 +1043,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if command == 'recurse': if command == 'recurse':
# Skip file only checkout. # Skip file only checkout.
scm = self.GetScmName(parsed_url) scm = self.GetScmName(self.url)
if not options.scm or scm in options.scm: if not options.scm or scm in options.scm:
cwd = os.path.normpath(os.path.join(self.root.root_dir, self.name)) cwd = os.path.normpath(os.path.join(self.root.root_dir, self.name))
# Pass in the SCM type as an env variable. Make sure we don't put # Pass in the SCM type as an env variable. Make sure we don't put
...@@ -1043,8 +1051,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1043,8 +1051,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
env = os.environ.copy() env = os.environ.copy()
if scm: if scm:
env['GCLIENT_SCM'] = str(scm) env['GCLIENT_SCM'] = str(scm)
if parsed_url: if self.url:
env['GCLIENT_URL'] = str(parsed_url) env['GCLIENT_URL'] = str(self.url)
env['GCLIENT_DEP_PATH'] = str(self.name) env['GCLIENT_DEP_PATH'] = str(self.name)
if options.prepend_dir and scm == 'git': if options.prepend_dir and scm == 'git':
print_stdout = False print_stdout = False
...@@ -1075,7 +1083,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1075,7 +1083,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
print_stdout = True print_stdout = True
filter_fn = None filter_fn = None
if parsed_url is None: if self.url is None:
print('Skipped omitted dependency %s' % cwd, file=sys.stderr) print('Skipped omitted dependency %s' % cwd, file=sys.stderr)
elif os.path.isdir(cwd): elif os.path.isdir(cwd):
try: try:
...@@ -1111,10 +1119,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1111,10 +1119,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
f.write('\n'.join(lines)) f.write('\n'.join(lines))
@gclient_utils.lockedmethod @gclient_utils.lockedmethod
def _run_is_done(self, file_list, parsed_url): def _run_is_done(self, file_list):
# Both these are kept for hooks that are run as a separate tree traversal. # Both these are kept for hooks that are run as a separate tree traversal.
self._file_list = file_list self._file_list = file_list
self._parsed_url = parsed_url
self._processed = True self._processed = True
def GetHooks(self, options): def GetHooks(self, options):
...@@ -1133,7 +1140,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1133,7 +1140,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# what files have changed so we always run all hooks. It'd be nice to fix # what files have changed so we always run all hooks. It'd be nice to fix
# that. # that.
if (options.force or if (options.force or
self.GetScmName(self.parsed_url) in ('git', None) or self.GetScmName(self.url) in ('git', None) or
os.path.isdir(os.path.join(self.root.root_dir, self.name, '.git'))): os.path.isdir(os.path.join(self.root.root_dir, self.name, '.git'))):
result.extend(self.deps_hooks) result.extend(self.deps_hooks)
else: else:
...@@ -1219,11 +1226,6 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1219,11 +1226,6 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
def pre_deps_hooks(self): def pre_deps_hooks(self):
return tuple(self._pre_deps_hooks) return tuple(self._pre_deps_hooks)
@property
@gclient_utils.lockedmethod
def parsed_url(self):
return self._parsed_url
@property @property
@gclient_utils.lockedmethod @gclient_utils.lockedmethod
def deps_parsed(self): def deps_parsed(self):
...@@ -1274,7 +1276,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1274,7 +1276,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
def __str__(self): def __str__(self):
out = [] out = []
for i in ('name', 'url', 'parsed_url', 'custom_deps', for i in ('name', 'url', 'custom_deps',
'custom_vars', 'deps_hooks', 'file_list', 'should_process', 'custom_vars', 'deps_hooks', 'file_list', 'should_process',
'processed', 'hooks_ran', 'deps_parsed', 'requirements', 'processed', 'hooks_ran', 'deps_parsed', 'requirements',
'allowed_hosts'): 'allowed_hosts'):
...@@ -1593,7 +1595,7 @@ it or fix the checkout. ...@@ -1593,7 +1595,7 @@ it or fix the checkout.
result = 'entries = {\n' result = 'entries = {\n'
for entry in self.root.subtree(False): for entry in self.root.subtree(False):
result += ' %s: %s,\n' % (pprint.pformat(entry.name), result += ' %s: %s,\n' % (pprint.pformat(entry.name),
pprint.pformat(entry.parsed_url)) pprint.pformat(entry.url))
result += '}\n' result += '}\n'
file_path = os.path.join(self.root_dir, self._options.entries_filename) file_path = os.path.join(self.root_dir, self._options.entries_filename)
logging.debug(result) logging.debug(result)
...@@ -1825,20 +1827,9 @@ it or fix the checkout. ...@@ -1825,20 +1827,9 @@ it or fix the checkout.
work_queue.enqueue(s) work_queue.enqueue(s)
work_queue.flush({}, None, [], options=self._options, patch_refs=None) work_queue.flush({}, None, [], options=self._options, patch_refs=None)
def ShouldPrintRevision(dep, rev): def ShouldPrintRevision(dep):
return (not self._options.filter return (not self._options.filter
or d.FuzzyMatchUrl(rev, self._options.filter)) or dep.FuzzyMatchUrl(self._options.filter))
def GetURLAndRev(dep):
"""Returns the revision-qualified SCM url for a Dependency."""
if dep.parsed_url is None:
return None
url, _ = gclient_utils.SplitUrlRevision(dep.parsed_url)
scm = dep.CreateSCM(
dep.parsed_url, self.root_dir, dep.name, self.outbuf)
if not os.path.isdir(scm.checkout_path):
return None
return '%s@%s' % (url, scm.revinfo(self._options, [], None))
if self._options.snapshot: if self._options.snapshot:
json_output = [] json_output = []
...@@ -1848,9 +1839,9 @@ it or fix the checkout. ...@@ -1848,9 +1839,9 @@ it or fix the checkout.
def GrabDeps(dep): def GrabDeps(dep):
"""Recursively grab dependencies.""" """Recursively grab dependencies."""
for d in dep.dependencies: for d in dep.dependencies:
rev = GetURLAndRev(d) d.PinToActualRevision()
if ShouldPrintRevision(d, rev): if ShouldPrintRevision(d):
entries[d.name] = rev entries[d.name] = d.url
GrabDeps(d) GrabDeps(d)
GrabDeps(d) GrabDeps(d)
json_output.append({ json_output.append({
...@@ -1874,11 +1865,9 @@ it or fix the checkout. ...@@ -1874,11 +1865,9 @@ it or fix the checkout.
entries = {} entries = {}
for d in self.root.subtree(False): for d in self.root.subtree(False):
if self._options.actual: if self._options.actual:
rev = GetURLAndRev(d) d.PinToActualRevision()
else: if ShouldPrintRevision(d):
rev = d.parsed_url entries[d.name] = d.url
if ShouldPrintRevision(d, rev):
entries[d.name] = rev
if self._options.output_json: if self._options.output_json:
json_output = { json_output = {
name: { name: {
...@@ -2146,24 +2135,16 @@ class Flattener(object): ...@@ -2146,24 +2135,16 @@ class Flattener(object):
Arguments: Arguments:
dep (Dependency): dependency to process dep (Dependency): dependency to process
""" """
if dep.parsed_url is None: if dep.url is None:
return return
# Make sure the revision is always fully specified (a hash), # Make sure the revision is always fully specified (a hash),
# as opposed to refs or tags which might change. Similarly, # as opposed to refs or tags which might change. Similarly,
# shortened shas might become ambiguous; make sure to always # shortened shas might become ambiguous; make sure to always
# use full one for pinning. # use full one for pinning.
url, revision = gclient_utils.SplitUrlRevision(dep.parsed_url) revision = gclient_utils.SplitUrlRevision(dep.url)[1]
if revision and gclient_utils.IsFullGitSha(revision): if not revision or not gclient_utils.IsFullGitSha(revision):
return dep.PinToActualRevision()
scm = dep.CreateSCM(
dep.parsed_url, self._client.root_dir, dep.name, dep.outbuf)
revinfo = scm.revinfo(self._client._options, [], None)
dep._parsed_url = dep._url = '%s@%s' % (url, revinfo)
raw_url, _ = gclient_utils.SplitUrlRevision(dep._raw_url)
dep._raw_url = '%s@%s' % (raw_url, revinfo)
def _flatten(self, pin_all_deps=False): def _flatten(self, pin_all_deps=False):
"""Runs the flattener. Saves resulting DEPS string. """Runs the flattener. Saves resulting DEPS string.
...@@ -2198,8 +2179,8 @@ class Flattener(object): ...@@ -2198,8 +2179,8 @@ class Flattener(object):
deps_path = os.path.join(self._client.root_dir, dep.name, deps_file) deps_path = os.path.join(self._client.root_dir, dep.name, deps_file)
if not os.path.exists(deps_path): if not os.path.exists(deps_path):
return return
assert dep.parsed_url assert dep.url
self._deps_files.add((dep.parsed_url, deps_file, dep.hierarchy_data())) self._deps_files.add((dep.url, deps_file, dep.hierarchy_data()))
for dep in self._deps.itervalues(): for dep in self._deps.itervalues():
add_deps_file(dep) add_deps_file(dep)
for os_deps in self._deps_os.itervalues(): for os_deps in self._deps_os.itervalues():
...@@ -2244,10 +2225,6 @@ class Flattener(object): ...@@ -2244,10 +2225,6 @@ class Flattener(object):
self._deps_os.get(dep_os, {}).get(os_dep.name) == os_dep), ( self._deps_os.get(dep_os, {}).get(os_dep.name) == os_dep), (
os_dep.name, self._deps_os.get(dep_os, {}).get(os_dep.name)) os_dep.name, self._deps_os.get(dep_os, {}).get(os_dep.name))
if os_dep.url: if os_dep.url:
# OS-specific deps need to have their full URL resolved manually.
assert not os_dep.parsed_url, (os_dep, os_dep.parsed_url)
os_dep._parsed_url = os_dep.LateOverride(os_dep.url)
self._deps_os.setdefault(dep_os, {})[os_dep.name] = os_dep self._deps_os.setdefault(dep_os, {})[os_dep.name] = os_dep
def _flatten_dep(self, dep, dep_os=None): def _flatten_dep(self, dep, dep_os=None):
......
...@@ -824,12 +824,6 @@ class GitWrapper(SCMWrapper): ...@@ -824,12 +824,6 @@ class GitWrapper(SCMWrapper):
return sha1 return sha1
def FullUrlForRelativeUrl(self, url):
# Strip from last '/'
# Equivalent to unix basename
base_url = self.url
return base_url[:base_url.rfind('/')] + url
def GetGitBackupDirPath(self): def GetGitBackupDirPath(self):
"""Returns the path where the .git folder for the current project can be """Returns the path where the .git folder for the current project can be
staged/restored. Use case: subproject moved from DEPS <-> outer project.""" staged/restored. Use case: subproject moved from DEPS <-> outer project."""
......
...@@ -5,8 +5,4 @@ Once upon a time, a budding web browser dev team needed a CI system. ...@@ -5,8 +5,4 @@ Once upon a time, a budding web browser dev team needed a CI system.
All they had was one poor machine under a desk, and its name was Batty, All they had was one poor machine under a desk, and its name was Batty,
the Build and Test Yeti. the Build and Test Yeti.
One day, an engineer named
😒😒
The End The End
...@@ -843,6 +843,7 @@ class FakeReposTestBase(trial_dir.TestCase): ...@@ -843,6 +843,7 @@ class FakeReposTestBase(trial_dir.TestCase):
def checkString(self, expected, result, msg=None): def checkString(self, expected, result, msg=None):
"""Prints the diffs to ease debugging.""" """Prints the diffs to ease debugging."""
self.assertEquals(expected.splitlines(), result.splitlines(), msg)
if expected != result: if expected != result:
# Strip the begining # Strip the begining
while expected and result and expected[0] == result[0]: while expected and result and expected[0] == result[0]:
......
...@@ -205,12 +205,12 @@ class GClientSmoke(GClientSmokeBase): ...@@ -205,12 +205,12 @@ class GClientSmoke(GClientSmokeBase):
']\n' ']\n'
'cache_dir = None\n') % self.git_base) 'cache_dir = None\n') % self.git_base)
test(['config', 'foo', 'faa'], test(['config', 'https://example.com/foo', 'faa'],
'solutions = [\n' 'solutions = [\n'
' { "name" : "foo",\n' ' { "name" : "foo",\n'
' "url" : "foo",\n' ' "url" : "https://example.com/foo",\n'
' "deps_file" : "DEPS",\n' ' "deps_file" : "DEPS",\n'
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "custom_vars": {},\n' ' "custom_vars": {},\n'
...@@ -218,10 +218,10 @@ class GClientSmoke(GClientSmokeBase): ...@@ -218,10 +218,10 @@ class GClientSmoke(GClientSmokeBase):
']\n' ']\n'
'cache_dir = None\n') 'cache_dir = None\n')
test(['config', 'foo', '--deps', 'blah'], test(['config', 'https://example.com/foo', '--deps', 'blah'],
'solutions = [\n' 'solutions = [\n'
' { "name" : "foo",\n' ' { "name" : "foo",\n'
' "url" : "foo",\n' ' "url" : "https://example.com/foo",\n'
' "deps_file" : "blah",\n' ' "deps_file" : "blah",\n'
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
...@@ -384,7 +384,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -384,7 +384,7 @@ class GClientSmokeGIT(GClientSmokeBase):
}, },
'src/repo2/repo_renamed/': { 'src/repo2/repo_renamed/': {
'scm': 'git', 'scm': 'git',
'url': '/repo_3', 'url': self.git_base + 'repo_3',
'revision': self.githash('repo_3', 2), 'revision': self.githash('repo_3', 2),
}, },
}, },
...@@ -1316,14 +1316,14 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1316,14 +1316,14 @@ class GClientSmokeGIT(GClientSmokeBase):
self.assertEqual([ self.assertEqual([
{'url': 'git://127.0.0.1:20000/git/repo_11', 'deps_file': 'DEPS', {'url': 'git://127.0.0.1:20000/git/repo_11', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'],
['src/repo11', '/repo_11']]}, ['src/repo11', 'git://127.0.0.1:20000/git/repo_11']]},
{'url': 'git://127.0.0.1:20000/git/repo_8', 'deps_file': 'DEPS', {'url': 'git://127.0.0.1:20000/git/repo_8', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'],
['src/repo9', '/repo_9'], ['src/repo9', 'git://127.0.0.1:20000/git/repo_9'],
['src/repo8', '/repo_8']]}, ['src/repo8', 'git://127.0.0.1:20000/git/repo_8']]},
{'url': 'git://127.0.0.1:20000/git/repo_9', 'deps_file': 'DEPS', {'url': 'git://127.0.0.1:20000/git/repo_9', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'],
['src/repo9', '/repo_9']]}, ['src/repo9', 'git://127.0.0.1:20000/git/repo_9']]},
], deps_files_contents) ], deps_files_contents)
def testFlattenCipd(self): def testFlattenCipd(self):
......
...@@ -43,9 +43,6 @@ class SCMMock(object): ...@@ -43,9 +43,6 @@ class SCMMock(object):
self.unit_test.assertEquals('None', command) self.unit_test.assertEquals('None', command)
self.unit_test.processed.put((self.name, self.url)) self.unit_test.processed.put((self.name, self.url))
def FullUrlForRelativeUrl(self, url):
return self.url + url
# pylint: disable=no-self-use # pylint: disable=no-self-use
def DoesRemoteURLMatch(self, _): def DoesRemoteURLMatch(self, _):
return True return True
...@@ -143,11 +140,11 @@ class GclientTest(trial_dir.TestCase): ...@@ -143,11 +140,11 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals(first_3, actual[0:3]) self.assertEquals(first_3, actual[0:3])
self.assertEquals( self.assertEquals(
[ [
('foo/dir1', 'svn://example.com/foo/dir1'), ('foo/dir1', 'svn://example.com/dir1'),
('foo/dir1/dir2', 'svn://example.com/bar/dir1/dir2'), ('foo/dir1/dir2', 'svn://example.com/dir1/dir2'),
('foo/dir1/dir2/dir3', 'svn://example.com/foo/dir1/dir2/dir3'), ('foo/dir1/dir2/dir3', 'svn://example.com/dir1/dir2/dir3'),
('foo/dir1/dir2/dir3/dir4', ('foo/dir1/dir2/dir3/dir4',
'svn://example.com/foo/dir1/dir2/dir3/dir4'), 'svn://example.com/dir1/dir2/dir3/dir4'),
], ],
actual[3:]) actual[3:])
...@@ -214,25 +211,27 @@ class GclientTest(trial_dir.TestCase): ...@@ -214,25 +211,27 @@ class GclientTest(trial_dir.TestCase):
obj.add_dependencies_and_close( obj.add_dependencies_and_close(
[ [
gclient.Dependency( gclient.Dependency(
obj, 'foo', 'raw_url', 'url', None, None, None, None, 'DEPS', True, obj, 'foo', 'svn://example.com/foo', 'svn://example.com/foo', None,
False, None, True), None, None, None, 'DEPS', True, False, None, True),
gclient.Dependency( gclient.Dependency(
obj, 'bar', 'raw_url', 'url', None, None, None, None, 'DEPS', True, obj, 'bar', 'svn://example.com/bar', 'svn://example.com/bar', None,
False, None, True), None, None, None, 'DEPS', True, False, None, True),
], ],
[]) [])
obj.dependencies[0].add_dependencies_and_close( obj.dependencies[0].add_dependencies_and_close(
[ [
gclient.Dependency( gclient.Dependency(
obj.dependencies[0], 'foo/dir1', 'raw_url', 'url', None, None, None, obj.dependencies[0], 'foo/dir1', 'svn://example.com/foo/dir1',
None, 'DEPS', True, False, None, True), 'svn://example.com/foo/dir1', None, None, None, None, 'DEPS', True,
False, None, True),
], ],
[]) [])
# TODO(ehmaldonado): Improve this test.
# Make sure __str__() works fine. # Make sure __str__() works fine.
# pylint: disable=protected-access # pylint: disable=protected-access
obj.dependencies[0]._file_list.append('foo') obj.dependencies[0]._file_list.append('foo')
str_obj = str(obj) str_obj = str(obj)
self.assertEquals(263, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) self.assertEquals(322, len(str_obj), '%d\n%s' % (len(str_obj), str_obj))
def testHooks(self): def testHooks(self):
topdir = self.root_dir topdir = self.root_dir
...@@ -460,10 +459,10 @@ class GclientTest(trial_dir.TestCase): ...@@ -460,10 +459,10 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('bar', 'svn://example.com/bar'), ('bar', 'svn://example.com/bar'),
('bar/unix', 'svn://example.com/bar/unix'), ('bar/unix', 'svn://example.com/unix'),
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/baz', 'svn://example.com/foo/baz'), ('foo/baz', 'svn://example.com/baz'),
('foo/unix', 'svn://example.com/foo/unix'), ('foo/unix', 'svn://example.com/unix'),
], ],
sorted(self._get_processed())) sorted(self._get_processed()))
...@@ -620,13 +619,12 @@ class GclientTest(trial_dir.TestCase): ...@@ -620,13 +619,12 @@ class GclientTest(trial_dir.TestCase):
with self.assertRaises(gclient_utils.Error): with self.assertRaises(gclient_utils.Error):
gclient.Dependency.MergeWithOsDeps(deps, deps_os, target_os_list, False) gclient.Dependency.MergeWithOsDeps(deps, deps_os, target_os_list, False)
def testLateOverride(self): def testOverride(self):
"""Verifies expected behavior of LateOverride.""" """Verifies expected behavior of OverrideURL."""
url = "git@github.com:dart-lang/spark.git" url = "git@github.com:dart-lang/spark.git"
d = gclient.Dependency(None, 'name', 'raw_url', 'url', d = gclient.Dependency(None, 'name', url, url,
None, None, None, None, '', True, False, None, True) None, None, None, None, '', True, False, None, True)
late_url = d.LateOverride(url) self.assertEquals(url, d.url)
self.assertEquals(url, late_url)
def testDepsOsOverrideDepsInDepsFile(self): def testDepsOsOverrideDepsInDepsFile(self):
"""Verifies that a 'deps_os' path cannot override a 'deps' path. Also """Verifies that a 'deps_os' path cannot override a 'deps' path. Also
...@@ -712,9 +710,9 @@ class GclientTest(trial_dir.TestCase): ...@@ -712,9 +710,9 @@ class GclientTest(trial_dir.TestCase):
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/bar', 'svn://example.com/bar'), ('foo/bar', 'svn://example.com/bar'),
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
('baz', 'svn://example.com/foo/bar/baz'), ('baz', 'svn://example.com/baz'),
('fizz', 'svn://example.com/foo/bar/baz/fizz'), ('fizz', 'svn://example.com/fizz'),
], ],
self._get_processed()) self._get_processed())
...@@ -769,9 +767,9 @@ class GclientTest(trial_dir.TestCase): ...@@ -769,9 +767,9 @@ class GclientTest(trial_dir.TestCase):
obj.RunOnDeps('None', []) obj.RunOnDeps('None', [])
self.assertEquals( self.assertEquals(
[ [
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
('baz', 'svn://example.com/foo/bar/baz'), ('baz', 'svn://example.com/baz'),
('fizz', 'svn://example.com/foo/bar/baz/fizz'), ('fizz', 'svn://example.com/fizz'),
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/bar', 'svn://example.com/bar'), ('foo/bar', 'svn://example.com/bar'),
('foo/tar', 'svn://example.com/tar'), ('foo/tar', 'svn://example.com/tar'),
...@@ -810,8 +808,8 @@ class GclientTest(trial_dir.TestCase): ...@@ -810,8 +808,8 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/bar', 'svn://example.com/foo/bar'), ('foo/bar', 'svn://example.com/bar'),
('foo/baz', 'svn://example.com/foo/bar/baz'), ('foo/baz', 'svn://example.com/baz'),
], ],
self._get_processed()) self._get_processed())
...@@ -847,8 +845,8 @@ class GclientTest(trial_dir.TestCase): ...@@ -847,8 +845,8 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/bar', 'svn://example.com/foo/bar'), ('foo/bar', 'svn://example.com/bar'),
('foo/bar/baz', 'svn://example.com/foo/bar/baz'), ('foo/bar/baz', 'svn://example.com/baz'),
], ],
self._get_processed()) self._get_processed())
...@@ -930,11 +928,11 @@ class GclientTest(trial_dir.TestCase): ...@@ -930,11 +928,11 @@ class GclientTest(trial_dir.TestCase):
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('foo/bar', 'svn://example.com/bar'), ('foo/bar', 'svn://example.com/bar'),
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
# Deps after this would have been skipped if we were obeying # Deps after this would have been skipped if we were obeying
# |recursedeps|. # |recursedeps|.
('baz', 'svn://example.com/foo/bar/baz'), ('baz', 'svn://example.com/baz'),
('fizz', 'svn://example.com/foo/bar/baz/fizz'), ('fizz', 'svn://example.com/fizz'),
# And this dep would have been picked up if we were obeying # And this dep would have been picked up if we were obeying
# |recursedeps|. # |recursedeps|.
# 'svn://example.com/foo/bar/baz/fuzz', # 'svn://example.com/foo/bar/baz/fuzz',
...@@ -972,8 +970,8 @@ class GclientTest(trial_dir.TestCase): ...@@ -972,8 +970,8 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
('baz', 'svn://example.com/foo/bar/baz'), ('baz', 'svn://example.com/baz'),
], ],
self._get_processed()) self._get_processed())
...@@ -1008,7 +1006,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -1008,7 +1006,7 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
], ],
self._get_processed()) self._get_processed())
...@@ -1033,7 +1031,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -1033,7 +1031,7 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals( self.assertEquals(
[ [
('foo', 'svn://example.com/foo'), ('foo', 'svn://example.com/foo'),
('bar', 'svn://example.com/foo/bar'), ('bar', 'svn://example.com/bar'),
], ],
self._get_processed()) self._get_processed())
...@@ -1205,8 +1203,9 @@ class GclientTest(trial_dir.TestCase): ...@@ -1205,8 +1203,9 @@ class GclientTest(trial_dir.TestCase):
obj.add_dependencies_and_close( obj.add_dependencies_and_close(
[ [
gclient.Dependency( gclient.Dependency(
obj, 'foo', 'raw_url', 'url', None, None, None, None, 'DEPS', True, obj, 'foo', 'svn://example.com/foo', 'svn://example.com/foo', None,
False, None, True), None, None, None, 'DEPS', True,
False, None, True),
], ],
[]) [])
obj.dependencies[0].add_dependencies_and_close( obj.dependencies[0].add_dependencies_and_close(
...@@ -1246,8 +1245,8 @@ class GclientTest(trial_dir.TestCase): ...@@ -1246,8 +1245,8 @@ class GclientTest(trial_dir.TestCase):
foo_sol = obj.dependencies[0] foo_sol = obj.dependencies[0]
self.assertEqual( self.assertEqual(
'https://example.com/foo.git', 'https://example.com/foo.git',
foo_sol.FuzzyMatchUrl('https://example.com/foo.git', foo_sol.FuzzyMatchUrl(['https://example.com/foo.git', 'foo'])
['https://example.com/foo.git', 'foo'])) )
def testFuzzyMatchUrlByURLNoGit(self): def testFuzzyMatchUrlByURLNoGit(self):
write( write(
...@@ -1267,8 +1266,8 @@ class GclientTest(trial_dir.TestCase): ...@@ -1267,8 +1266,8 @@ class GclientTest(trial_dir.TestCase):
foo_sol = obj.dependencies[0] foo_sol = obj.dependencies[0]
self.assertEqual( self.assertEqual(
'https://example.com/foo', 'https://example.com/foo',
foo_sol.FuzzyMatchUrl('https://example.com/foo.git', foo_sol.FuzzyMatchUrl(['https://example.com/foo', 'foo'])
['https://example.com/foo', 'foo'])) )
def testFuzzyMatchUrlByName(self): def testFuzzyMatchUrlByName(self):
write( write(
...@@ -1286,9 +1285,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -1286,9 +1285,7 @@ class GclientTest(trial_dir.TestCase):
options, _ = gclient.OptionParser().parse_args([]) options, _ = gclient.OptionParser().parse_args([])
obj = gclient.GClient.LoadCurrentConfig(options) obj = gclient.GClient.LoadCurrentConfig(options)
foo_sol = obj.dependencies[0] foo_sol = obj.dependencies[0]
self.assertEqual( self.assertEqual('foo', foo_sol.FuzzyMatchUrl(['foo']))
'foo',
foo_sol.FuzzyMatchUrl('https://example.com/foo.git', ['foo']))
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment