From 6fad174aa361b1b921fa9dae801239f2fa5fa397 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Thu, 12 Apr 2012 14:54:22 +0100 Subject: cachekeycomputer: prepare build environment change CacheKeyComputer needs to know some stuff that is needed elsewhere as well. Rather than duplicate the storage, have a BuildEnvironment class to handle that. --- morphlib/cachekeycomputer.py | 4 ++-- morphlib/cachekeycomputer_tests.py | 32 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'morphlib') diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py index ade74b79..1cc377b3 100644 --- a/morphlib/cachekeycomputer.py +++ b/morphlib/cachekeycomputer.py @@ -20,9 +20,9 @@ import morphlib class CacheKeyComputer(): - def __init__(self, env): + def __init__(self, build_env): self._arch = morphlib.util.arch() - self._env = self._filterenv(env) + self._env = self._filterenv(build_env.env) self._calculated = {} def _filterenv(self, env): diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py index 5304307a..4973a948 100644 --- a/morphlib/cachekeycomputer_tests.py +++ b/morphlib/cachekeycomputer_tests.py @@ -15,22 +15,30 @@ import unittest -import json import morphlib +class DummyBuildEnvironment: + '''Fake build environment class that doesn't need + settings to pick the environment, it just gets passed + a dict representing it + ''' + def __init__(self, env, arch=None): + self.arch = morphlib.util.arch() if arch == None else arch + self.env = env class CacheKeyComputerTests(unittest.TestCase): def setUp(self): - self.env = {"USER": "foouser", - "USERNAME": "foouser", - "LOGNAME": "foouser", - "TOOLCHAIN_TARGET": "dummy-baserock-linux-gnu", - "PREFIX": "/baserock", - "BOOTSTRAP": "false", - "CFLAGS": "-O4"} - self.ckc = morphlib.cachekeycomputer.CacheKeyComputer(self.env) + self.build_env = DummyBuildEnvironment({ + "USER": "foouser", + "USERNAME": "foouser", + "LOGNAME": "foouser", + "TOOLCHAIN_TARGET": "dummy-baserock-linux-gnu", + "PREFIX": "/baserock", + "BOOTSTRAP": "false", + "CFLAGS": "-O4"}) + self.ckc = morphlib.cachekeycomputer.CacheKeyComputer(self.build_env) pool = morphlib.sourcepool.SourcePool() self.sources = {} for name, text in { @@ -82,12 +90,6 @@ class CacheKeyComputerTests(unittest.TestCase): self.assertTrue(self._valid_sha256( self.ckc.get_cache_key(self.sources['stratum.morph']))) - def test_get_cache_id_returns_dict(self): - print json.dumps(self.ckc.get_cache_id( - self.sources['stratum.morph']), - indent=2) - self.assertEqual('', ) - def test_different_env_gives_different_key(self): oldsha = self.ckc.get_cache_key(self.sources['stratum.morph']) self.ckc._env['CFLAGS'] = "-Os" -- cgit v1.2.1