def getCompiled(self, fileId, variants, optimize, format=False): fileEntry = self._classes[fileId] filePath = fileEntry["path"] variantsId = util.generateId(variants) optimizeId = self.generateOptimizeId(optimize) cacheId = "%s-compiled-%s-%s-%s" % (fileId, variantsId, optimizeId, format) compiled = self._cache.read(cacheId, filePath) if compiled != None: return compiled tree = copy.deepcopy(self._treeLoader.getVariantsTree(fileId, variants)) if len(optimize) > 0: self._console.debug("Optimizing tree: %s..." % fileId) self._console.indent() self._optimizeHelper(tree, fileId, variants, optimize) self._console.outdent() self._console.debug("Compiling tree: %s..." % fileId) compiled = self.compileTree(tree, format) self._cache.write(cacheId, compiled) return compiled
def getVariantsTree(self, fileId, variants=None): if variants == None or len(variants) == 0: return self.getTree(fileId) fileEntry = self._classes[fileId] filePath = fileEntry["path"] cacheId = "%s-tree-%s" % (fileId, util.generateId(variants)) tree = self._cache.read(cacheId, filePath) if tree != None: if tree == "unmodified": return self.getTree(fileId) return tree tree = self.getTree(fileId) self._console.debug("Select variants: %s..." % fileId) self._console.indent() # Call variant optimizer modified = variantoptimizer.search(tree, variants, fileId) if not modified: self._console.debug("Store unmodified hint.") self._console.outdent() # Store result into cache if modified: self._cache.write(cacheId, tree) else: self._cache.write(cacheId, "unmodified") return tree
def getCompiledSize(self, fileId, variants): fileEntry = self._classes[fileId] filePath = fileEntry["path"] variantsId = util.generateId(variants) cacheId = "%s-compiled-size-%s" % (fileId, variantsId) size = self._cache.read(cacheId, filePath) if size != None: return size tree = self._treeLoader.getVariantsTree(fileId, variants) self._console.debug("Computing compiled size: %s..." % fileId) compiled = self.compileTree(tree) size = len(compiled) self._cache.write(cacheId, size) return size
def getStrings(self, fileId, variants): fileEntry = self._classes[fileId] filePath = fileEntry["path"] variantsId = util.generateId(variants) cacheId = "%s-locale-%s" % (fileId, variantsId) strings = self._cache.read(cacheId, filePath) if strings != None: return strings self._console.debug("Looking for localizable strings: %s..." % fileId) self._console.indent() tree = self._treeLoader.getVariantsTree(fileId, variants) try: strings = self._findStrings(tree, []) except NameError, detail: self._console.error("Could not extract localizable strings from %s!" % fileId) self._console.error("%s" % detail) sys.exit(1)
def getDeps(self, fileId, variants): if not self._classes.has_key(fileId): raise NameError("Could not find class to fulfil dependency: %s" % fileId) filePath = self._classes[fileId]["path"] cacheId = "%s-deps-%s" % (fileId, util.generateId(variants)) # print "Read from cache: %s" % fileId deps = self._cache.read(cacheId, filePath, True) if deps != None: return deps # Notes: # load time = before class = require # runtime = after class = use load = [] run = [] self._console.debug("Gathering dependencies: %s" % fileId) self._console.indent() # Read meta data meta = self.getMeta(fileId) metaLoad = self._readDictKey(meta, "loadtimeDeps", []) metaRun = self._readDictKey(meta, "runtimeDeps", []) metaOptional = self._readDictKey(meta, "optionalDeps", []) metaIgnore = self._readDictKey(meta, "ignoreDeps", []) # Process meta data load.extend(metaLoad) run.extend(metaRun) # Read content data (autoLoad, autoRun) = self._analyzeClassDeps(fileId, variants) # Process content data if not "auto-require" in metaIgnore: for item in autoLoad: if item in metaOptional: pass elif item in load: self._console.warn("#require(%s) is auto-detected" % item) else: load.append(item) if not "auto-use" in metaIgnore: for item in autoRun: if item in metaOptional: pass elif item in load: pass elif item in run: self._console.warn("#use(%s) is auto-detected" % item) else: run.append(item) self._console.outdent() # Build data structure deps = { "load" : load, "run" : run } self._cache.write(cacheId, deps, True) return deps