def dependencies_from_envcalls(self, node):
     depsList = []
     if 'qx.core.Environment' not in ClassesAll:
         self.context['console'].warn(
             "No qx.core.Environment available to extract feature keys from"
         )
         return depsList
     qcEnvClass = ClassesAll['qx.core.Environment']
     for env_operand in variantoptimizer.findVariantNodes(node):
         call_node = env_operand.parent.parent
         env_key = call_node.getChild("arguments").children[0].get(
             "value", "")
         className, classAttribute = qcEnvClass.classNameFromEnvKey(env_key)
         if className and className in ClassesAll:
             #print className
             depsItem = DependencyItem(className, classAttribute, self.id,
                                       env_operand.get('line', -1))
             depsItem.isCall = True  # treat as if actual call, to collect recursive deps
             depsItem.node = call_node
             # .inLoadContext
             qx_idnode = treeutil.findFirstChainChild(
                 env_operand)  # 'qx' node of 'qx.core.Environment....'
             scope = qx_idnode.scope
             depsItem.isLoadDep = scope.is_load_time
             if depsItem.isLoadDep:
                 depsItem.needsRecursion = True
             depsList.append(depsItem)
     return depsList
Exemple #2
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     #config  = self.context['jobconf'] - TODO: this can yield job 'apiconf::build-resources' when running 'apiconf::build-data'!?
     config = Context.jobconf
     warn_non_literal_keys = "non-literal-keys" not in config.get(
         "config-warnings/environment", [])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.isVar():
                 if warn_non_literal_keys:
                     console.warn(
                         "qx.core.Environment call with non-literal key (%s:%s)"
                         % (self.id, variantNode.get("line", False)))
             elif firstParam.type == "map":  # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn(
                     "qx.core.Environment call with alien first argument (%s:%s)"
                     % (self.id, variantNode.get("line", False)))
     return classvariants
Exemple #3
0
 def _variantsFromTree(self, node):
     console = self.context["console"]
     config = self.context["jobconf"]
     warn_non_literal_keys = "non-literal-keys" not in config.get("config-warnings/environment", [])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.type == "variable":
                 if warn_non_literal_keys:
                     console.warn(
                         "qx.core.Environment call with non-literal key (%s:%s)"
                         % (self.id, variantNode.get("line", False))
                     )
             elif firstParam.type == "map":  # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn(
                     "qx.core.Environment call with alien first argument (%s:%s)"
                     % (self.id, variantNode.get("line", False))
                 )
     return classvariants
    def _analyzeClassDepsNode_1(self, node, depsList, inLoadContext, inDefer=False):
        if node.type in ("file", "function", "catch"):
            top_scope = node.scope
        else:
            top_scope = scopes.find_enclosing(node)  # get enclosing scope of node
        # import pydb; pydb.debugger()
        for scope in top_scope.scope_iterator():  # walk through this and all nested scopes
            for global_name, scopeVar in scope.globals().items():  # get the global symbols { sym_name: ScopeVar }
                for node in scopeVar.uses:  # create a depsItem for all its uses
                    depsItem = self.qualify_deps_item(node, scope.is_load_time, scope.is_defer)
                    depsList.append(depsItem)  # and qualify them

        # Augment with feature dependencies introduces with qx.core.Environment.get("...") calls
        for envCall in variantoptimizer.findVariantNodes(node):
            className, classAttribute = self.getClassNameFromEnvKey(
                envCall.getChild("arguments").children[0].get("value", "")
            )
            if className:
                depsItem = DependencyItem(className, classAttribute, self.id, envCall.get("line", -1))
                depsItem.isCall = True  # treat as if actual call, to collect recursive deps
                # .inLoadContext
                # get 'qx' node of 'qx.core.Environment....'
                call_operand = envCall.getChild("operand").children[0]
                qx_idnode = treeutil.findFirstChainChild(call_operand)
                scope = qx_idnode.scope
                inLoadContext = scope.is_load_time  # get its scope's .is_load_time
                depsItem.isLoadDep = inLoadContext
                if inLoadContext:
                    depsItem.needsRecursion = True
                depsList.append(depsItem)

        return
Exemple #5
0
 def environment_check_calls(self, node):
     for env_call in variantoptimizer.findVariantNodes(node):
         variantMethod = env_call.toJS(treegenerator.PackerFlags).rsplit('.',1)[1]
         callNode = treeutil.selectNode(env_call, "../..")
         if variantMethod in ["select"]:
             self.environment_check_select(callNode)
         elif variantMethod in ["get"]:
             self.environment_check_get(callNode)
         elif variantMethod in ["filter"]:
             self.environment_check_filter(callNode)
Exemple #6
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     classvariants = set([])
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam and treeutil.isStringLiteral(firstParam):
             classvariants.add(firstParam.get("value"))
         else:
             console.warn("qx.core.Environment call without literal argument (%s:%s)" % (self.id, variantNode.get("line", False)))
     return classvariants
Exemple #7
0
 def environment_check_calls(self, node):
     for env_call in variantoptimizer.findVariantNodes(node):
         variantMethod = env_call.toJS(treegenerator.PackerFlags).rsplit('.',1)[1]
         callNode = treeutil.selectNode(env_call, "../..")
         if variantMethod in ["select"]:
             self.environment_check_select(callNode)
         elif variantMethod in ["get"]:
             self.environment_check_get(callNode)
         elif variantMethod in ["filter"]:
             self.environment_check_filter(callNode)
Exemple #8
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.type == "map": # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn("qx.core.Environment call with alien first argument (%s:%s)" % (self.id, variantNode.get("line", False)))
     return classvariants
    def _analyzeClassDepsNode_2(self,
                                node,
                                depsList,
                                inLoadContext,
                                inDefer=False):
        if node.type in ('file', 'function', 'catch'):
            top_scope = node.scope
        else:
            top_scope = scopes.find_enclosing(
                node)  # get enclosing scope of node
        for scope in top_scope.scope_iterator(
        ):  # walk through this and all nested scopes
            for global_name, scopeVar in scope.globals().items(
            ):  # get the global symbols { sym_name: ScopeVar }
                for var_node in scopeVar.uses:  # create a depsItem for all its uses
                    if treeutil.hasAncestor(
                            var_node, node
                    ):  # var_node is not disconnected through optimization
                        depsItem = self.qualify_deps_item(
                            var_node, scope.is_load_time, scope.is_defer)
                        # as this also does filtering
                        if depsItem:
                            depsList.append(depsItem)  # and qualify them
                            #if depsItem.name == "qx.log.appender.Console":
                            #    import pydb; pydb.debugger()

        # Augment with feature dependencies introduces with qx.core.Environment.get("...") calls
        for env_operand in variantoptimizer.findVariantNodes(node):
            call_node = env_operand.parent.parent
            env_key = call_node.getChild("arguments").children[0].get(
                "value", "")
            className, classAttribute = self.getClassNameFromEnvKey(env_key)
            if className:
                #print className
                depsItem = DependencyItem(className, classAttribute, self.id,
                                          env_operand.get('line', -1))
                depsItem.isCall = True  # treat as if actual call, to collect recursive deps
                # .inLoadContext
                # get 'qx' node of 'qx.core.Environment....'
                qx_idnode = treeutil.findFirstChainChild(env_operand)
                scope = qx_idnode.scope
                inLoadContext = scope.is_load_time  # get its scope's .is_load_time
                depsItem.isLoadDep = inLoadContext
                if inLoadContext:
                    depsItem.needsRecursion = True
                depsList.append(depsItem)

        return
 def dependencies_from_envcalls(self, node):
     depsList = []
     qcEnvClass = ClassesAll['qx.core.Environment']
     for env_operand in variantoptimizer.findVariantNodes(node):
         call_node = env_operand.parent.parent
         env_key = call_node.getChild("arguments").children[0].get("value", "")
         className, classAttribute = qcEnvClass.classNameFromEnvKey(env_key)
         if className and className in ClassesAll:
             #print className
             depsItem = DependencyItem(className, classAttribute, self.id, env_operand.get('line', -1))
             depsItem.isCall = True  # treat as if actual call, to collect recursive deps
             # .inLoadContext
             qx_idnode = treeutil.findFirstChainChild(env_operand) # 'qx' node of 'qx.core.Environment....'
             scope = qx_idnode.scope
             depsItem.isLoadDep = scope.is_load_time
             if depsItem.isLoadDep:
                 depsItem.needsRecursion = True
             depsList.append(depsItem)
     return depsList
Exemple #11
0
    def dependencies_from_envcalls(self, node):

        depsList = []
        if 'qx.core.Environment' not in ClassesAll:
            self.context['console'].warn("No qx.core.Environment available to extract feature keys from")
            return depsList
        qcEnvClass = ClassesAll['qx.core.Environment']

        for env_operand in variantoptimizer.findVariantNodes(node):
            call_node = env_operand.parent.parent
            env_key = call_node.getChild("arguments").children[0].get("value", "")
            # Without qx.core.Environment._checksMap:
            # ---------------------------------------
            className = qcEnvClass.classNameFromEnvKeyByIndex(env_key)
            if className and className in ClassesAll:
                #print className
                depsItem = DependencyItem(className, "", self.id, env_operand.get('line', -1))
                depsItem.isCall = True  # treat as if actual call, to collect recursive deps
                depsItem.node = call_node
                # .inLoadContext
                qx_idnode = treeutil.findFirstChainChild(env_operand) # 'qx' node of 'qx.core.Environment....'
                scope = qx_idnode.scope
                depsItem.isLoadDep = scope.is_load_time
                if depsItem.isLoadDep:
                    depsItem.needsRecursion = True
                depsList.append(depsItem)
            # With qx.core.Environment._checksMap:
            # ------------------------------------
            # className, classAttribute = qcEnvClass.classNameFromEnvKey(env_key)
            # if className and className in ClassesAll:
            #     #print className
            #     depsItem = DependencyItem(className, classAttribute, self.id, env_operand.get('line', -1))
            #     depsItem.isCall = True  # treat as if actual call, to collect recursive deps
            #     depsItem.node = call_node
            #     # .inLoadContext
            #     qx_idnode = treeutil.findFirstChainChild(env_operand) # 'qx' node of 'qx.core.Environment....'
            #     scope = qx_idnode.scope
            #     depsItem.isLoadDep = scope.is_load_time
            #     if depsItem.isLoadDep:
            #         depsItem.needsRecursion = True
            #     depsList.append(depsItem)
        return depsList
 def _variantsFromTree(self, node):
     console = self.context['console']
     #config  = self.context['jobconf'] - TODO: this can yield job 'apiconf::build-resources' when running 'apiconf::build-data'!?
     config  = Context.jobconf
     warn_non_literal_keys = "non-literal-keys" not in config.get("config-warnings/environment",[])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.isVar():
                 if warn_non_literal_keys:
                     console.warn("qx.core.Environment call with non-literal key (%s:%s)" % (self.id, variantNode.get("line", False)))
             elif firstParam.type == "map": # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn("qx.core.Environment call with alien first argument (%s:%s)" % (self.id, variantNode.get("line", False)))
     return classvariants
    def _analyzeClassDepsNode_2(self, node, depsList, inLoadContext, inDefer=False):
        if node.type in ('file', 'function', 'catch'):
            top_scope = node.scope
        else:
            top_scope = scopes.find_enclosing(node)  # get enclosing scope of node
        for scope in top_scope.scope_iterator(): # walk through this and all nested scopes
            for global_name, scopeVar in scope.globals().items():  # get the global symbols { sym_name: ScopeVar }
                for var_node in scopeVar.uses:       # create a depsItem for all its uses
                    if treeutil.hasAncestor(var_node, node): # var_node is not disconnected through optimization
                        depsItem = self.qualify_deps_item(var_node, scope.is_load_time, scope.is_defer)
                        # as this also does filtering
                        if depsItem:
                            depsList.append(depsItem)    # and qualify them
                            #if depsItem.name == "qx.log.appender.Console":
                            #    import pydb; pydb.debugger()

        # Augment with feature dependencies introduces with qx.core.Environment.get("...") calls
        for env_operand in variantoptimizer.findVariantNodes(node):
            call_node = env_operand.parent.parent
            env_key = call_node.getChild("arguments").children[0].get("value", "")
            className, classAttribute = self.getClassNameFromEnvKey(env_key)
            if className:
                #print className
                depsItem = DependencyItem(className, classAttribute, self.id, env_operand.get('line', -1))
                depsItem.isCall = True  # treat as if actual call, to collect recursive deps
                # .inLoadContext
                # get 'qx' node of 'qx.core.Environment....'
                qx_idnode = treeutil.findFirstChainChild(env_operand)
                scope = qx_idnode.scope
                inLoadContext = scope.is_load_time # get its scope's .is_load_time
                depsItem.isLoadDep = inLoadContext
                if inLoadContext:
                    depsItem.needsRecursion = True
                depsList.append(depsItem)

        return