Mercurial > hg > truffle
comparison mxtool/mx.py @ 14133:d2e4b81fd8f0
mx: support sha1 digest for dependencies
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Tue, 11 Mar 2014 18:36:20 +0100 |
parents | 9d8aaa3200a3 |
children | e71d421370f3 |
comparison
equal
deleted
inserted
replaced
14132:5bf75c95ed56 | 14133:d2e4b81fd8f0 |
---|---|
34 """ | 34 """ |
35 | 35 |
36 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch | 36 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch |
37 import textwrap | 37 import textwrap |
38 import socket | 38 import socket |
39 import hashlib | |
39 import xml.parsers.expat | 40 import xml.parsers.expat |
40 import shutil, re, xml.dom.minidom | 41 import shutil, re, xml.dom.minidom |
41 import pipes | 42 import pipes |
42 from collections import Callable | 43 from collections import Callable |
43 from threading import Thread | 44 from threading import Thread |
339 with open(currentApsFile, 'w') as fp: | 340 with open(currentApsFile, 'w') as fp: |
340 for ap in aps: | 341 for ap in aps: |
341 print >> fp, ap | 342 print >> fp, ap |
342 return outOfDate | 343 return outOfDate |
343 | 344 |
345 def _download_file_with_sha1(name, path, urls, sha1, sha1path, resolve, mustExist, sources=False): | |
346 def _download_lib(): | |
347 print 'Downloading ' + ("Sources " if sources else "") + name + ' from ' + str(urls) | |
348 download(path, urls) | |
349 | |
350 def _sha1Cached(): | |
351 with open(sha1path, 'r') as f: | |
352 return f.readline()[0:40] | |
353 | |
354 def _writesha1Cached(): | |
355 with open(sha1path, 'w') as f: | |
356 f.write(_sha1OfFile()) | |
357 | |
358 def _sha1OfFile(): | |
359 with open(path, 'r') as f: | |
360 return hashlib.sha1(f.read()).hexdigest() | |
361 | |
362 | |
363 if resolve and mustExist and not exists(path): | |
364 assert not len(urls) == 0, 'cannot find required library ' + name + ' ' + path | |
365 _download_lib() | |
366 | |
367 if sha1 and not exists(sha1path): | |
368 _writesha1Cached() | |
369 | |
370 if sha1 and sha1 != _sha1Cached(): | |
371 _download_lib() | |
372 if sha1 != _sha1OfFile(): | |
373 abort("SHA1 does not match for " + name + ". Broken download? SHA1 not updated in projects file?") | |
374 _writesha1Cached() | |
375 | |
376 return path | |
344 | 377 |
345 class Library(Dependency): | 378 class Library(Dependency): |
346 def __init__(self, suite, name, path, mustExist, urls, sourcePath, sourceUrls): | 379 def __init__(self, suite, name, path, mustExist, urls, sha1, sourcePath, sourceUrls, sourceSha1): |
347 Dependency.__init__(self, suite, name) | 380 Dependency.__init__(self, suite, name) |
348 self.path = path.replace('/', os.sep) | 381 self.path = path.replace('/', os.sep) |
349 self.urls = urls | 382 self.urls = urls |
383 self.sha1 = sha1 | |
350 self.mustExist = mustExist | 384 self.mustExist = mustExist |
351 self.sourcePath = sourcePath | 385 self.sourcePath = sourcePath |
352 self.sourceUrls = sourceUrls | 386 self.sourceUrls = sourceUrls |
387 self.sourceSha1 = sourceSha1 | |
353 for url in urls: | 388 for url in urls: |
354 if url.endswith('/') != self.path.endswith(os.sep): | 389 if url.endswith('/') != self.path.endswith(os.sep): |
355 abort('Path for dependency directory must have a URL ending with "/": path=' + self.path + ' url=' + url) | 390 abort('Path for dependency directory must have a URL ending with "/": path=' + self.path + ' url=' + url) |
356 | 391 |
357 def __eq__(self, other): | 392 def __eq__(self, other): |
373 | 408 |
374 def get_path(self, resolve): | 409 def get_path(self, resolve): |
375 path = self.path | 410 path = self.path |
376 if not isabs(path): | 411 if not isabs(path): |
377 path = join(self.suite.dir, path) | 412 path = join(self.suite.dir, path) |
413 sha1path = path + '.sha1' | |
414 | |
378 includedInJDK = getattr(self, 'includedInJDK', None) | 415 includedInJDK = getattr(self, 'includedInJDK', None) |
379 if includedInJDK and java().javaCompliance >= JavaCompliance(includedInJDK): | 416 if includedInJDK and java().javaCompliance >= JavaCompliance(includedInJDK): |
380 return None | 417 return None |
381 if resolve and self.mustExist and not exists(path): | 418 |
382 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + ' ' + path | 419 return _download_file_with_sha1(self.name, path, self.urls, self.sha1, sha1path, resolve, self.mustExist) |
383 print 'Downloading ' + self.name + ' from ' + str(self.urls) | 420 |
384 download(path, self.urls) | |
385 return path | |
386 | 421 |
387 def get_source_path(self, resolve): | 422 def get_source_path(self, resolve): |
388 path = self.sourcePath | 423 path = self.sourcePath |
389 if path is None: | 424 if path is None: |
390 return None | 425 return None |
391 if not isabs(path): | 426 if not isabs(path): |
392 path = join(self.suite.dir, path) | 427 path = join(self.suite.dir, path) |
393 if resolve and len(self.sourceUrls) != 0 and not exists(path): | 428 sha1path = path + '.sha1' |
394 print 'Downloading sources for ' + self.name + ' from ' + str(self.sourceUrls) | 429 |
395 download(path, self.sourceUrls) | 430 return _download_file_with_sha1(self.name, path, self.sourceUrls, self.sha1, sha1path, resolve, len(self.sourceUrls) != 0, sources=True) |
396 return path | |
397 | 431 |
398 def append_to_classpath(self, cp, resolve): | 432 def append_to_classpath(self, cp, resolve): |
399 path = self.get_path(resolve) | 433 path = self.get_path(resolve) |
400 if path and (exists(path) or not resolve): | 434 if path and (exists(path) or not resolve): |
401 cp.append(path) | 435 cp.append(path) |
554 | 588 |
555 for name, attrs in libsMap.iteritems(): | 589 for name, attrs in libsMap.iteritems(): |
556 path = attrs.pop('path') | 590 path = attrs.pop('path') |
557 mustExist = attrs.pop('optional', 'false') != 'true' | 591 mustExist = attrs.pop('optional', 'false') != 'true' |
558 urls = pop_list(attrs, 'urls') | 592 urls = pop_list(attrs, 'urls') |
593 sha1 = attrs.pop('sha1', None) | |
559 sourcePath = attrs.pop('sourcePath', None) | 594 sourcePath = attrs.pop('sourcePath', None) |
560 sourceUrls = pop_list(attrs, 'sourceUrls') | 595 sourceUrls = pop_list(attrs, 'sourceUrls') |
561 l = Library(self, name, path, mustExist, urls, sourcePath, sourceUrls) | 596 sourceSha1 = attrs.pop('sourceSha1', None) |
597 l = Library(self, name, path, mustExist, urls, sha1, sourcePath, sourceUrls, sourceSha1) | |
562 l.__dict__.update(attrs) | 598 l.__dict__.update(attrs) |
563 self.libs.append(l) | 599 self.libs.append(l) |
564 | 600 |
565 for name, attrs in distsMap.iteritems(): | 601 for name, attrs in distsMap.iteritems(): |
566 path = attrs.pop('path') | 602 path = attrs.pop('path') |