diff options
Diffstat (limited to 'bitbake/lib/bb/cache.py')
-rw-r--r-- | bitbake/lib/bb/cache.py | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py index 47e814b577..36e6356f51 100644 --- a/bitbake/lib/bb/cache.py +++ b/bitbake/lib/bb/cache.py | |||
@@ -1,11 +1,12 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | 1 | # ex:ts=4:sw=4:sts=4:et |
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
3 | # | 3 | # |
4 | # BitBake 'Event' implementation | 4 | # BitBake Cache implementation |
5 | # | 5 | # |
6 | # Caching of bitbake variables before task execution | 6 | # Caching of bitbake variables before task execution |
7 | 7 | ||
8 | # Copyright (C) 2006 Richard Purdie | 8 | # Copyright (C) 2006 Richard Purdie |
9 | # Copyright (C) 2012 Intel Corporation | ||
9 | 10 | ||
10 | # but small sections based on code from bin/bitbake: | 11 | # but small sections based on code from bin/bitbake: |
11 | # Copyright (C) 2003, 2004 Chris Larson | 12 | # Copyright (C) 2003, 2004 Chris Larson |
@@ -703,4 +704,115 @@ class CacheData(object): | |||
703 | for info in info_array: | 704 | for info in info_array: |
704 | info.add_cacheData(self, fn) | 705 | info.add_cacheData(self, fn) |
705 | 706 | ||
706 | 707 | ||
708 | class MultiProcessCache(object): | ||
709 | """ | ||
710 | BitBake multi-process cache implementation | ||
711 | |||
712 | Used by the codeparser & file checksum caches | ||
713 | """ | ||
714 | |||
715 | def __init__(self): | ||
716 | self.cachefile = None | ||
717 | self.cachedata = self.create_cachedata() | ||
718 | self.cachedata_extras = self.create_cachedata() | ||
719 | |||
720 | def init_cache(self, d): | ||
721 | cachedir = (d.getVar("PERSISTENT_DIR", True) or | ||
722 | d.getVar("CACHE", True)) | ||
723 | if cachedir in [None, '']: | ||
724 | return | ||
725 | bb.utils.mkdirhier(cachedir) | ||
726 | self.cachefile = os.path.join(cachedir, self.__class__.cache_file_name) | ||
727 | logger.debug(1, "Using cache in '%s'", self.cachefile) | ||
728 | |||
729 | try: | ||
730 | p = pickle.Unpickler(file(self.cachefile, "rb")) | ||
731 | data, version = p.load() | ||
732 | except: | ||
733 | return | ||
734 | |||
735 | if version != self.__class__.CACHE_VERSION: | ||
736 | return | ||
737 | |||
738 | self.cachedata = data | ||
739 | |||
740 | def internSet(self, items): | ||
741 | new = set() | ||
742 | for i in items: | ||
743 | new.add(intern(i)) | ||
744 | return new | ||
745 | |||
746 | def compress_keys(self, data): | ||
747 | # Override in subclasses if desired | ||
748 | return | ||
749 | |||
750 | def create_cachedata(self): | ||
751 | data = [{}] | ||
752 | return data | ||
753 | |||
754 | def save_extras(self, d): | ||
755 | if not self.cachefile: | ||
756 | return | ||
757 | |||
758 | glf = bb.utils.lockfile(self.cachefile + ".lock", shared=True) | ||
759 | |||
760 | i = os.getpid() | ||
761 | lf = None | ||
762 | while not lf: | ||
763 | lf = bb.utils.lockfile(self.cachefile + ".lock." + str(i), retry=False) | ||
764 | if not lf or os.path.exists(self.cachefile + "-" + str(i)): | ||
765 | if lf: | ||
766 | bb.utils.unlockfile(lf) | ||
767 | lf = None | ||
768 | i = i + 1 | ||
769 | continue | ||
770 | |||
771 | p = pickle.Pickler(file(self.cachefile + "-" + str(i), "wb"), -1) | ||
772 | p.dump([self.cachedata_extras, self.__class__.CACHE_VERSION]) | ||
773 | |||
774 | bb.utils.unlockfile(lf) | ||
775 | bb.utils.unlockfile(glf) | ||
776 | |||
777 | def merge_data(self, source, dest): | ||
778 | for j in range(0,len(dest)): | ||
779 | for h in source[j]: | ||
780 | if h not in dest[j]: | ||
781 | dest[j][h] = source[j][h] | ||
782 | |||
783 | def save_merge(self, d): | ||
784 | if not self.cachefile: | ||
785 | return | ||
786 | |||
787 | glf = bb.utils.lockfile(self.cachefile + ".lock") | ||
788 | |||
789 | try: | ||
790 | p = pickle.Unpickler(file(self.cachefile, "rb")) | ||
791 | data, version = p.load() | ||
792 | except (IOError, EOFError): | ||
793 | data, version = None, None | ||
794 | |||
795 | if version != self.__class__.CACHE_VERSION: | ||
796 | data = self.create_cachedata() | ||
797 | |||
798 | for f in [y for y in os.listdir(os.path.dirname(self.cachefile)) if y.startswith(os.path.basename(self.cachefile) + '-')]: | ||
799 | f = os.path.join(os.path.dirname(self.cachefile), f) | ||
800 | try: | ||
801 | p = pickle.Unpickler(file(f, "rb")) | ||
802 | extradata, version = p.load() | ||
803 | except (IOError, EOFError): | ||
804 | extradata, version = self.create_cachedata(), None | ||
805 | |||
806 | if version != self.__class__.CACHE_VERSION: | ||
807 | continue | ||
808 | |||
809 | self.merge_data(extradata, data) | ||
810 | os.unlink(f) | ||
811 | |||
812 | self.compress_keys(data) | ||
813 | |||
814 | p = pickle.Pickler(file(self.cachefile, "wb"), -1) | ||
815 | p.dump([data, self.__class__.CACHE_VERSION]) | ||
816 | |||
817 | bb.utils.unlockfile(glf) | ||
818 | |||