Bug 1216817 - Part 1: Add install_callback to artifacts. r=gps

--HG--
extra : commitid : 7Qjl1R0EAl9
extra : rebase_source : c34a581f6f513dde939e8e079e2b9676ce121f92
This commit is contained in:
Nick Alexander 2015-10-30 13:35:13 -07:00
parent a3f03c1b51
commit 137016aacb

View File

@ -332,36 +332,38 @@ class Artifacts(object):
if self._log:
self._log(*args, **kwargs)
def install_from_file(self, filename, distdir):
def install_from_file(self, filename, distdir, install_callback=None):
self.log(logging.INFO, 'artifact',
{'filename': filename},
'Installing from {filename}')
# Copy all .so files to dist/bin, avoiding modification where possible.
ensureParentDir(os.path.join(distdir, 'bin', '.dummy'))
ensureParentDir(mozpath.join(distdir, 'bin', '.dummy'))
with zipfile.ZipFile(filename) as zf:
for info in zf.infolist():
if not info.filename.endswith('.so'):
continue
n = os.path.join(distdir, 'bin', os.path.basename(info.filename))
n = mozpath.join(distdir, 'bin', os.path.basename(info.filename))
fh = FileAvoidWrite(n, mode='r')
shutil.copyfileobj(zf.open(info), fh)
file_existed, file_updated = fh.close()
self.log(logging.INFO, 'artifact',
{'updating': 'Updating' if file_updated else 'Not updating', 'filename': n},
'{updating} {filename}')
if install_callback:
install_callback(os.path.basename(info.filename), file_existed, file_updated)
return 0
def install_from_url(self, url, distdir):
def install_from_url(self, url, distdir, install_callback=None):
self.log(logging.INFO, 'artifact',
{'url': url},
'Installing from {url}')
with self._artifact_cache as artifact_cache: # The with block handles persistence.
filename = artifact_cache.fetch(url)
return self.install_from_file(filename, distdir)
return self.install_from_file(filename, distdir, install_callback=install_callback)
def install_from_hg(self, revset, distdir):
def install_from_hg(self, revset, distdir, install_callback=None):
if not revset:
revset = '.'
if len(revset) != 40:
@ -389,19 +391,27 @@ class Artifacts(object):
except ValueError:
pass
if url:
return self.install_from_url(url, distdir)
return self.install_from_url(url, distdir, install_callback=install_callback)
self.log(logging.ERROR, 'artifact',
{'revset': revset},
'No built artifacts for {revset} found.')
return 1
def install_from(self, source, distdir):
def install_from(self, source, distdir, install_callback=None):
"""Install artifacts from a ``source`` into the given ``distdir``.
If ``callback`` is given, it is called once with arguments ``(path,
existed, updated)``, where ``path`` is the file path written relative
to ``distdir``; ``existed`` is a boolean indicating whether the file
existed; and ``updated`` is a boolean indicating whether the file was
updated.
"""
if source and os.path.isfile(source):
return self.install_from_file(source, distdir)
return self.install_from_file(source, distdir, install_callback=install_callback)
elif source and urlparse.urlparse(source).scheme:
return self.install_from_url(source, distdir)
return self.install_from_url(source, distdir, install_callback=install_callback)
else:
return self.install_from_hg(source, distdir)
return self.install_from_hg(source, distdir, install_callback=install_callback)
def print_last(self):
self.log(logging.INFO, 'artifact',