diff options
| -rw-r--r-- | bitbake/lib/bb/cache.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py index ab18dd5eaa..233f994279 100644 --- a/bitbake/lib/bb/cache.py +++ b/bitbake/lib/bb/cache.py | |||
| @@ -883,3 +883,56 @@ class MultiProcessCache(object): | |||
| 883 | p.dump([data, self.__class__.CACHE_VERSION]) | 883 | p.dump([data, self.__class__.CACHE_VERSION]) |
| 884 | 884 | ||
| 885 | bb.utils.unlockfile(glf) | 885 | bb.utils.unlockfile(glf) |
| 886 | |||
| 887 | |||
| 888 | class SimpleCache(object): | ||
| 889 | """ | ||
| 890 | BitBake multi-process cache implementation | ||
| 891 | |||
| 892 | Used by the codeparser & file checksum caches | ||
| 893 | """ | ||
| 894 | |||
| 895 | def __init__(self, version): | ||
| 896 | self.cachefile = None | ||
| 897 | self.cachedata = None | ||
| 898 | self.cacheversion = version | ||
| 899 | |||
| 900 | def init_cache(self, d, cache_file_name=None, defaultdata=None): | ||
| 901 | cachedir = (d.getVar("PERSISTENT_DIR") or | ||
| 902 | d.getVar("CACHE")) | ||
| 903 | if not cachedir: | ||
| 904 | return defaultdata | ||
| 905 | |||
| 906 | bb.utils.mkdirhier(cachedir) | ||
| 907 | self.cachefile = os.path.join(cachedir, | ||
| 908 | cache_file_name or self.__class__.cache_file_name) | ||
| 909 | logger.debug(1, "Using cache in '%s'", self.cachefile) | ||
| 910 | |||
| 911 | glf = bb.utils.lockfile(self.cachefile + ".lock") | ||
| 912 | |||
| 913 | try: | ||
| 914 | with open(self.cachefile, "rb") as f: | ||
| 915 | p = pickle.Unpickler(f) | ||
| 916 | data, version = p.load() | ||
| 917 | except: | ||
| 918 | bb.utils.unlockfile(glf) | ||
| 919 | return defaultdata | ||
| 920 | |||
| 921 | bb.utils.unlockfile(glf) | ||
| 922 | |||
| 923 | if version != self.cacheversion: | ||
| 924 | return defaultdata | ||
| 925 | |||
| 926 | return data | ||
| 927 | |||
| 928 | def save(self, data): | ||
| 929 | if not self.cachefile: | ||
| 930 | return | ||
| 931 | |||
| 932 | glf = bb.utils.lockfile(self.cachefile + ".lock") | ||
| 933 | |||
| 934 | with open(self.cachefile, "wb") as f: | ||
| 935 | p = pickle.Pickler(f, -1) | ||
| 936 | p.dump([data, self.cacheversion]) | ||
| 937 | |||
| 938 | bb.utils.unlockfile(glf) | ||
