summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/__init__.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2012-05-23 00:23:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-23 11:35:04 +0100
commit8b8be74ed21b878b2fe30d5b76ff0648e6e48c18 (patch)
treef1facae6d6803b450185811ca08bf215d6963530 /bitbake/lib/bb/fetch2/__init__.py
parentd7b818b51f3e6dded0c0885cdfed5a24cda3b428 (diff)
downloadpoky-8b8be74ed21b878b2fe30d5b76ff0648e6e48c18.tar.gz
bitbake: implement checksums for local files in SRC_URI
Gathers a list of paths to have checksums calculated at parse time, and processes these when calculating task hashes. Checksums are cached with the file's current mtime. Thus, changing any local file in SRC_URI will now cause the do_fetch taskhash to change, thus forcing a rebuild. This change adds very roughly about an 8% increase in parse time (a few seconds) and maybe a few seconds during runqueue generation, so a fairly moderate performance hit. Note that since paths are resolved at parse time, this will not force a rebuild when files are introduced which would cause that resolved path to be different - for example, where a machine-specific version of a file was added without otherwise changing the recipe. This will need to be handled in a future update. Code to hook this into the signature generator was courtesy of Richard Purdie <richard.purdie@linuxfoundation.org>. Implements [YOCTO #2044]. (Bitbake rev: c993b7c457f8b7776e8a5dff253bfa0724bc2cae) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/__init__.py')
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py85
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
30import logging 31import logging
31import urllib 32import urllib
32import bb.persist_data, bb.utils 33import bb.persist_data, bb.utils
34import bb.checksum
33from bb import data 35from bb import data
34 36
35__version__ = "2" 37__version__ = "2"
38_checksum_cache = bb.checksum.FileChecksumCache()
36 39
37logger = logging.getLogger("BitBake.Fetcher") 40logger = 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
245def fetcher_parse_save(d):
246 _checksum_cache.save_extras(d)
247
248def fetcher_parse_done(d):
249 _checksum_cache.save_merge(d)
250
240def fetcher_compare_revisions(d): 251def 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
568def 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
596def 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
556class FetchData(object): 641class 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.