Exemplo n.º 1
0
    def check(self, _file, stash):
        res = []

        if self.is_lone_append(stash, _file):
            return res

        _packages = list(get_valid_package_names(stash, _file))
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER)
        for i in items:
            if i.VarName == 'inherit':
                continue
            if i.VarName in self.needles:
                _machine = []
                if i.GetMachineEntry():
                    _machine = [
                        i.GetMachineEntry(),
                        expand_term(stash, _file, i.GetMachineEntry())
                    ]
                if not _machine or not any(x in _packages for x in _machine):
                    res += self.finding(i.Origin,
                                        i.InFileLine,
                                        override_msg=self.Msg.replace(
                                            '{VAR}', i.VarName),
                                        appendix=i.VarName)
        return res
Exemplo n.º 2
0
    def check(self, _file, stash):
        res = []
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR)
        _comp = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR,
                                  attributeValue='COMPATIBLE_MACHINE')
        _comp = ''.join(x.VarValueStripped for x in _comp)
        _packages = get_valid_package_names(stash, _file)
        _named_res = get_valid_named_resources(stash, _file)
        for i in items:
            _distro = []
            if i.GetDistroEntry():
                _distro = [
                    i.GetDistroEntry(),
                    expand_term(stash, _file, i.GetDistroEntry())
                ]
            if any(x in _packages for x in _distro) or any(
                    x in _named_res for x in _distro):  # pragma: no cover
                continue  # pragma: no cover
            if any(x in CONSTANTS.DistrosKnown for x in _distro):
                continue

            _machine = []
            if i.GetMachineEntry():
                _machine = [
                    i.GetMachineEntry(),
                    expand_term(stash, _file, i.GetMachineEntry())
                ]
            if not _machine:
                continue
            if any(x in _packages for x in _machine):
                continue
            if any(x in _named_res for x in _machine):
                continue
            if any(x in CONSTANTS.MachinesKnown for x in _machine):
                continue
            if _comp:
                if any(re.match(_comp, x) for x in _machine):
                    continue
            res += self.finding(i.Origin,
                                i.InFileLine,
                                override_msg=self.Msg.format(a=i.VarName,
                                                             b=_machine[0]))
        return res
Exemplo n.º 3
0
 def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR, attributeValue='inherit')
     for i in items:
         for subi in [expand_term(stash, _file, x) for x in i.get_items() if x and x != INLINE_BLOCK]:
             if not re.match(r'^[A-Za-z0-9_.-]+$', subi):
                 res += self.finding(i.Origin, i.InFileLine,
                                     self.Msg.replace('{INH}', subi))
     return res
Exemplo n.º 4
0
 def check(self, _file, stash):
     res = []
     for item in stash.GetItemsFor(filename=_file,
                                   classifier=Include.CLASSIFIER):
         if item.Statement == 'include':
             _path = expand_term(stash, _file, item.IncName)
             if not find_local_or_in_layer(_path, os.path.dirname(item.Origin)):
                 res += self.finding(item.Origin, item.InFileLine,
                                     self.Msg.replace('{FILE}', item.IncName))
     return res
    def check(self, _file, stash):
        res = []
        items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR, attributeValue='SRC_URI')

        _pv = expand_term(stash, _file, '${PV}') or guess_recipe_version(_file)

        for i in items:
            for item in [expand_term(stash, _file, x) for x in i.get_items()]:
                _scrcomp = get_scr_components(item)
                if _scrcomp.get('scheme', '') in ['https', 'http', 'ftp']:
                    _src = _scrcomp.get('src', '')
                    _dfn = _scrcomp.get('options', {}).get(
                        'downloadfilename', '')

                    if _pv not in _src:
                        if _dfn and _pv in _dfn:
                            continue
                        res += self.finding(i.Origin, i.InFileLine)
        return res
Exemplo n.º 6
0
    def __extract_info(self, path):
        _stash = Stash(quiet=True)
        _stash.AddFile(path)
        _stash.Finalize()

        name = None
        version = None
        depends = set()

        version = expand_term(_stash, path, "${PV}")
        for item in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue="GEM_NAME"):
            name = item.VarValueStripped
        depends = set()
        for item in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue="RDEPENDS_${PN}"):
            depends.update([expand_term(_stash, path, y)
                            for y in item.get_items() if y not in ["\\", "\\\n", '"']])
        for item in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue="EXTRA_RDEPENDS"):
            depends.update([expand_term(_stash, path, y)
                            for y in item.get_items() if y not in ["\\", "\\\n", '"']])

        return (name, version, depends)
Exemplo n.º 7
0
 def check(self, _file, stash):
     res = []
     if "recipes-rubygems/" not in _file:
         return []
     _pn = expand_term(stash, _file, "${PN}")
     _layer_root = get_layer_root(_file)
     _path = os.path.join(_layer_root,
                          RubygemsPackageGroup.PACKAGEGROUP_PATH)
     if os.path.exists(_path):
         with open(_path) as i:
             if _pn not in i.read():
                 res += self.finding(_file, 1)
     return res
Exemplo n.º 8
0
 def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR)
     _needles = ['S', 'B', 'T', 'D']
     for i in items:
         if i.VarName not in _needles:
             continue
         _expanded = expand_term(stash, _file, i.VarValueStripped)
         if _expanded.endswith('/'):
             res += self.finding(i.Origin, i.InFileLine,
                                 override_msg=self.Msg.format(a=i.VarName))
     return res
Exemplo n.º 9
0
def __get_info_from_stash(_filepath, name, modifiers):
    _result = set()

    _stash = Stash(quiet=True)
    _stash.AddFile(_filepath)

    for item in _stash.GetItemsFor(attribute=Variable.ATTR_VAR,
                                   attributeValue=name):
        if modifiers and not all(x in modifiers for x in item.SubItems):
            continue
        _result.update([
            expand_term(_stash, _filepath, y) for y in item.get_items()
            if y not in ["\\", "\\\n", '"']
        ])

    return _result
Exemplo n.º 10
0
 def check(self, _file, stash):
     res = []
     _items = stash.GetItemsFor(filename=_file,
                                classifier=Variable.CLASSIFIER,
                                attribute=Variable.ATTR_VAR,
                                attributeValue='LIC_FILES_CHKSUM')
     _var_whitelist = ['${WORKDIR}', '${S}', '${B}']
     for i in _items:
         components = get_scr_components(
             expand_term(stash, _file, i.VarValueStripped))
         if any(components) and components['scheme'] == 'file':
             _clean = components['src']
             for x in _var_whitelist:
                 _clean = _clean.replace(x, '')
             if '${' in _clean:
                 res += self.finding(i.Origin, i.InFileLine)
     return res
Exemplo n.º 11
0
 def check(self, _file, stash):
     res = []
     _items = stash.GetItemsFor(filename=_file,
                                classifier=Variable.CLASSIFIER,
                                attribute=Variable.ATTR_VAR,
                                attributeValue="LIC_FILES_CHKSUM")
     _var_whitelist = ["${WORKDIR}", "${S}", "${B}"]
     for i in _items:
         components = get_scr_components(
             expand_term(stash, _file, i.VarValueStripped))
         if any(components) and components["scheme"] == "file":
             _clean = components["src"]
             for x in _var_whitelist:
                 _clean = _clean.replace(x, "")
             if "${" in _clean:
                 res += self.finding(i.Origin, i.InFileLine)
     return res
Exemplo n.º 12
0
 def check(self, _file, stash):
     res = []
     if "recipes-rubygems/" not in _file:
         return []
     found = False
     _pn = expand_term(stash, _file, "${PN}")
     _layer_root = get_layer_root(_file)
     _needle = self.__needle_to_search_for(_pn)
     for root, dirs, files in os.walk(
             os.path.join(_layer_root, RubygemsTestCase.TESTCASE_DIR)):
         for f in files:
             if not f.endswith(".py"):
                 continue
             with open(os.path.join(root, f)) as i:
                 if _needle in i.read():
                     found = True
                     break
     if not found:
         res += self.finding(_file, 1)
     return res