diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2')
| -rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 0b976c4079..d4b6c3ec39 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
| @@ -8,6 +8,7 @@ BitBake build tools. | |||
| 8 | """ | 8 | """ |
| 9 | 9 | ||
| 10 | # Copyright (C) 2003, 2004 Chris Larson | 10 | # Copyright (C) 2003, 2004 Chris Larson |
| 11 | # Copyright (C) 2012 Intel Corporation | ||
| 11 | # | 12 | # |
| 12 | # This program is free software; you can redistribute it and/or modify | 13 | # This program is free software; you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License version 2 as | 14 | # it under the terms of the GNU General Public License version 2 as |
| @@ -30,9 +31,11 @@ import os, re | |||
| 30 | import logging | 31 | import logging |
| 31 | import urllib | 32 | import urllib |
| 32 | import bb.persist_data, bb.utils | 33 | import bb.persist_data, bb.utils |
| 34 | import bb.checksum | ||
| 33 | from bb import data | 35 | from bb import data |
| 34 | 36 | ||
| 35 | __version__ = "2" | 37 | __version__ = "2" |
| 38 | _checksum_cache = bb.checksum.FileChecksumCache() | ||
| 36 | 39 | ||
| 37 | logger = logging.getLogger("BitBake.Fetcher") | 40 | logger = logging.getLogger("BitBake.Fetcher") |
| 38 | 41 | ||
| @@ -233,10 +236,18 @@ def fetcher_init(d): | |||
| 233 | else: | 236 | else: |
| 234 | raise FetchError("Invalid SRCREV cache policy of: %s" % srcrev_policy) | 237 | raise FetchError("Invalid SRCREV cache policy of: %s" % srcrev_policy) |
| 235 | 238 | ||
| 239 | _checksum_cache.init_cache(d) | ||
| 240 | |||
| 236 | for m in methods: | 241 | for m in methods: |
| 237 | if hasattr(m, "init"): | 242 | if hasattr(m, "init"): |
| 238 | m.init(d) | 243 | m.init(d) |
| 239 | 244 | ||
| 245 | def fetcher_parse_save(d): | ||
| 246 | _checksum_cache.save_extras(d) | ||
| 247 | |||
| 248 | def fetcher_parse_done(d): | ||
| 249 | _checksum_cache.save_merge(d) | ||
| 250 | |||
| 240 | def fetcher_compare_revisions(d): | 251 | def fetcher_compare_revisions(d): |
| 241 | """ | 252 | """ |
| 242 | Compare the revisions in the persistant cache with current values and | 253 | Compare the revisions in the persistant cache with current values and |
| @@ -553,6 +564,80 @@ def srcrev_internal_helper(ud, d, name): | |||
| 553 | 564 | ||
| 554 | return rev | 565 | return rev |
| 555 | 566 | ||
| 567 | |||
| 568 | def get_checksum_file_list(d): | ||
| 569 | """ Get a list of files checksum in SRC_URI | ||
| 570 | |||
| 571 | Returns the all resolved local path of all local file entries in | ||
| 572 | SRC_URI as a space-separated string | ||
| 573 | """ | ||
| 574 | fetch = Fetch([], d) | ||
| 575 | |||
| 576 | dl_dir = d.getVar('DL_DIR', True) | ||
| 577 | filelist = [] | ||
| 578 | for u in fetch.urls: | ||
| 579 | ud = fetch.ud[u] | ||
| 580 | |||
| 581 | if isinstance(ud.method, local.Local): | ||
| 582 | ud.setup_localpath(d) | ||
| 583 | f = ud.localpath | ||
| 584 | if f.startswith(dl_dir): | ||
| 585 | # The local fetcher's behaviour is to return a path under DL_DIR if it couldn't find the file anywhere else | ||
| 586 | if os.path.exists(f): | ||
| 587 | bb.warn("Getting checksum for %s SRC_URI entry %s: file not found except in DL_DIR" % (d.getVar('PN', True), os.path.basename(f))) | ||
| 588 | else: | ||
| 589 | bb.warn("Unable to get checksum for %s SRC_URI entry %s: file could not be found" % (d.getVar('PN', True), os.path.basename(f))) | ||
| 590 | continue | ||
| 591 | filelist.append(f) | ||
| 592 | |||
| 593 | return " ".join(filelist) | ||
| 594 | |||
| 595 | |||
| 596 | def get_file_checksums(filelist, pn): | ||
| 597 | """Get a list of the checksums for a list of local files | ||
| 598 | |||
| 599 | Returns the checksums for a list of local files, caching the results as | ||
| 600 | it proceeds | ||
| 601 | |||
| 602 | """ | ||
| 603 | |||
| 604 | def checksum_file(f): | ||
| 605 | try: | ||
| 606 | checksum = _checksum_cache.get_checksum(f) | ||
| 607 | except OSError as e: | ||
| 608 | import traceback | ||
| 609 | bb.warn("Unable to get checksum for %s SRC_URI entry %s: %s" % (pn, os.path.basename(f), e)) | ||
| 610 | return None | ||
| 611 | return checksum | ||
| 612 | |||
| 613 | checksums = [] | ||
| 614 | for pth in filelist.split(): | ||
| 615 | checksum = None | ||
| 616 | if '*' in pth: | ||
| 617 | # Handle globs | ||
| 618 | import glob | ||
| 619 | for f in glob.glob(pth): | ||
| 620 | checksum = checksum_file(f) | ||
| 621 | if checksum: | ||
| 622 | checksums.append((f, checksum)) | ||
| 623 | elif os.path.isdir(pth): | ||
| 624 | # Handle directories | ||
| 625 | for root, dirs, files in os.walk(pth): | ||
| 626 | for name in files: | ||
| 627 | fullpth = os.path.join(root, name) | ||
| 628 | checksum = checksum_file(fullpth) | ||
| 629 | if checksum: | ||
| 630 | checksums.append((fullpth, checksum)) | ||
| 631 | else: | ||
| 632 | checksum = checksum_file(pth) | ||
| 633 | |||
| 634 | if checksum: | ||
| 635 | checksums.append((pth, checksum)) | ||
| 636 | |||
| 637 | checksums.sort() | ||
| 638 | return checksums | ||
| 639 | |||
| 640 | |||
| 556 | class FetchData(object): | 641 | class FetchData(object): |
| 557 | """ | 642 | """ |
| 558 | A class which represents the fetcher state for a given URI. | 643 | A class which represents the fetcher state for a given URI. |
