def format_var_impl(self, var_impl):
     sourcefile = kbuild.guess_source_for_target(var_impl, self.arch)
     if sourcefile:
         var_impl = kbuild.normalize_filename(sourcefile)
     else:
         logging.warning("Failed to guess source file for %s", var_impl)
     return "FILE_" + var_impl
Ejemplo n.º 2
0
 def format_var_impl(self, var_impl):
     sourcefile = guess_source_for_target(var_impl, self.arch)
     if sourcefile:
         var_impl = re.sub('[-+:,/]', '_', sourcefile)
     else:
         logging.warning("Failed to guess source file for %s", var_impl)
     return "FILE_" + var_impl
Ejemplo n.º 3
0
    def process(self, parser, line, basepath):

        line = line.processed_line

        regex_match = re.match(self.regex_obj, line)
        if not regex_match:
            return False

        rhs = regex_match.group(5)
        # First, check for match on core/lib/libs-y
        if regex_match.group(2) == "y":
            matches = [x for x in re.split("\t| ", rhs) if x]
            for match in matches:
                fullpath = basepath + "/" + match
                if os.path.isdir(fullpath):
                    parser.local_vars["dir_cond_collection"][fullpath].\
                        add_alternative(parser.local_vars["ifdef_condition"][:])
                else:
                    sourcefile = Kbuild.guess_source_for_target(fullpath)
                    if sourcefile:
                        parser.local_vars["file_features"][sourcefile].\
                            add_alternative(parser.local_vars["ifdef_condition"][:])
                    else:
                        parser.local_vars["composite_map"][fullpath].\
                            add_alternative(parser.local_vars["ifdef_condition"][:])
        else:
            # Then test obj-$(CONFIG_XY)
            config = regex_match.group(3)

            condition = Tools.get_config_string(config, self.model)

            matches = [x for x in re.split("\t| ", rhs) if x]

            parser.local_vars["ifdef_condition"].add_condition(condition)

            for match in matches:
                fullpath = basepath + "/" + match
                if os.path.isdir(fullpath):
                    parser.local_vars["dir_cond_collection"][fullpath].\
                        add_alternative(parser.local_vars["ifdef_condition"][:])
                else:
                    # Hacky bit for COMMON_FILES in this directory
                    if basepath == "archival/libarchive":
                        parser.local_vars["all_configs"].append(condition)
                    sourcefile = Kbuild.\
                        guess_source_for_target(fullpath)
                    if sourcefile:
                        parser.local_vars["file_features"][sourcefile].\
                            add_alternative(parser.local_vars["ifdef_condition"][:])
                    else:
                        parser.local_vars["composite_map"][fullpath].\
                            add_alternative(parser.local_vars["ifdef_condition"][:])

            parser.local_vars["ifdef_condition"].pop()
        return True
Ejemplo n.º 4
0
    def expand_macro(self, name, path, condition, already_expanded, parser):
        """ Expand a macro named @name. Preconditions to the folder are given
        in @condition. The input file is @path and to avoid endless
        recursion processing is aborted if the current name is already present
        in @already_expanded. To save the results, the local variables are
        accessed via the @parser parameter."""

        if name in already_expanded:
            return
        else:
            already_expanded.add(name)

        basepath = os.path.dirname(name)
        filename = os.path.basename(name)

        basename = ""

        # Extract base name from macro name
        match = self.regex_base.match(filename)
        if not match:
            return

        if match.group(1) is None:  # we have a macro
            basename = match.group(2)
            if basename.endswith("y"):
                basename = basename[:-1]
        elif match.group(2) is None:  # we have a file
            basename = match.group(1)

        scan_regex_string = ""
        if match.group(1) is None:
            scan_regex_string = r"\s*" + basename + r"(|y|\$\(" + \
                                CONFIG_FORMAT + r"\))\s*(:=|\+=|=)\s*(.*)"
        else:
            scan_regex_string = r"\s*" + basename + r"(|-y|-objs|-\$\(" + \
                                CONFIG_FORMAT + r"\))\s*(:=|\+=|=)\s*(.*)"

        scan_regex = re.compile(scan_regex_string)

        if not path in parser.file_content_cache:
            parser.read_whole_file(path)

        inputs = parser.file_content_cache[path]

        for line in inputs:
            if line.invalid:
                continue

            ifdef_condition = line.condition
            line = line.processed_line

            match = scan_regex.match(line)
            if not match:
                continue

            config_in_composite = match.group(2)
            condition_comp = ""
            if config_in_composite:
                condition_comp = Tools.get_config_string(
                    config_in_composite, self.model)

            rhs = match.group(4)

            matches = [x for x in re.split("\t| ", rhs) if x]
            for item in matches:
                fullpath = basepath + "/" + item
                passdown_condition = condition[:]
                if config_in_composite:
                    passdown_condition.append(condition_comp)

                if os.path.isdir(fullpath):
                    parser.local_vars["dir_cond_collection"]\
                        [fullpath].add_alternative(passdown_condition[:])
                else:
                    sourcefile = Kbuild.guess_source_for_target(fullpath)
                    if not sourcefile:
                        self.expand_macro(fullpath, path, passdown_condition,
                                          already_expanded, parser)
                    else:
                        full_condition = DataStructures.Precondition()
                        if len(condition) > 0:
                            full_condition = condition[:]
                        if config_in_composite:
                            full_condition.append(condition_comp)
                        if len(ifdef_condition) > 0:
                            full_condition.extend(ifdef_condition)

                        parser.local_vars["file_features"][sourcefile].\
                            add_alternative(full_condition[:])

        already_expanded.discard(name)
Ejemplo n.º 5
0
    def __process(self, parser, line, basepath):
        line = line.processed_line

        # Try obj-... +=/:=/= objfile.o
        regex_match = self.regex_obj.match(line)
        if regex_match:
            rhs = regex_match.group(5)
            # Fixes one special case in arch/mips/lib, could be extended with
            # other make-commands.
            if rhs.startswith("$(filter-out"):
                return False
            # First, check for match on obj-y or obj-m
            if regex_match.group(2) == "y" or regex_match.group(2) == "m":
                matches = [x for x in re.split("\t| ", rhs) if x]
                for match in matches:
                    fullpath = basepath + "/" + match
                    if os.path.isdir(fullpath):
                        parser.local_vars["dir_cond_collection"][fullpath].\
                            add_alternative(
                                parser.local_vars["ifdef_condition"][:]
                            )
                    else:
                        sourcefile = Kbuild.guess_source_for_target(fullpath)
                        if sourcefile:
                            parser.local_vars["file_features"][sourcefile].\
                                add_alternative(
                                    parser.local_vars["ifdef_condition"][:]
                                )
                        else:
                            parser.local_vars["composite_map"][fullpath].\
                                add_alternative(
                                    parser.local_vars["ifdef_condition"][:]
                                )
            else:
                # Then test obj-$(CONFIG_XY)
                config = regex_match.group(3)

                condition = Tools.get_config_string(config, self.model)

                matches = [x for x in re.split("\t| ", rhs) if x]

                parser.local_vars["ifdef_condition"].add_condition(condition)

                for match in matches:
                    fullpath = basepath + "/" + match
                    if os.path.isdir(fullpath):
                        # Has this directory been picked up via subdir-XY?
                        if parser.local_vars["ifdef_condition"] in \
                                parser.local_vars["dir_cond_collection"][fullpath]:
                            continue
                        parser.local_vars["dir_cond_collection"][fullpath].\
                            add_alternative(
                                parser.local_vars["ifdef_condition"][:]
                            )
                    else:
                        sourcefile = Kbuild.guess_source_for_target(fullpath)
                        if sourcefile:
                            parser.local_vars["file_features"][sourcefile].\
                                add_alternative(
                                    parser.local_vars["ifdef_condition"][:]
                                )
                        else:
                            parser.local_vars["composite_map"][fullpath].\
                                add_alternative(
                                    parser.local_vars["ifdef_condition"][:]
                                )

                parser.local_vars["ifdef_condition"].pop()
        # Up to v3.15, the security/ subdir used only subdir-$(CONFIG..) for
        # descending into subdirectories. All other directories didn't...
        else:
            match = self.regex_subdir.match(line)
            if not match:
                return False

            # If subdir is conditional, add condition to ifdef_condition
            if match.group(1) != "y":
                condition = Tools.get_config_string(match.group(2), self.model)
                parser.local_vars["ifdef_condition"].add_condition(condition)

            rhs = match.group(3)
            rhs_matches = [x.rstrip("/") for x in re.split("\t| ", rhs) if x]
            for m in rhs_matches:
                fullpath = basepath + "/" + m + "/"
                if not os.path.isdir(fullpath):
                    continue

                # Has this directory been picked up via obj-XY?
                if parser.local_vars["ifdef_condition"] in \
                        parser.local_vars["dir_cond_collection"][fullpath]:
                    continue

                parser.local_vars["dir_cond_collection"][fullpath].\
                    add_alternative(
                        parser.local_vars["ifdef_condition"][:]
                    )

            if match.group(1) != "y":
                parser.local_vars["ifdef_condition"].pop()

        return True
Ejemplo n.º 6
0
    def expand_macro(self, name, path, condition, already_expanded, parser):
        """ Expand a macro named @name. Preconditions to the folder are given
        in @condition. The path to the input file is @path and to avoid endless
        recursion processing is aborted if the current name is already present
        in @already_expanded. To save the results, the local variables are
        accessed via the @parser parameter."""

        if name in already_expanded:
            return

        already_expanded.add(name)

        basepath = os.path.dirname(name)
        filename = os.path.basename(name)

        match = re.match(self.regex_base, filename)
        if not match:
            return

        basename = match.group(1)

        scan_regex_string = r"\s*" + basename + r"\s*(:=|\+=|=)\s*(.*)"

        if not path in parser.file_content_cache:
            parser.read_whole_file(path)

        inputs = parser.file_content_cache[path]

        for line in inputs:

            if line.invalid:
                continue

            ifdef_condition = line.condition
            line = line.processed_line

            match = re.match(scan_regex_string, line)
            if not match:
                continue

            rhs = match.group(2)

            matches = [x for x in re.split("\t| ", rhs) if x]
            for item in matches:
                fullpath = basepath + "/" + item
                passdown_condition = condition[:]

                sourcefile = Kbuild.guess_source_for_target(fullpath)
                if not sourcefile:
                    self.expand_macro(fullpath, path, passdown_condition,
                                      already_expanded, parser)
                else:
                    full_condition = DataStructures.Precondition()
                    if len(condition) > 0:
                        full_condition = condition[:]
                    if len(ifdef_condition) > 0:
                        full_condition.extend(ifdef_condition)

                    parser.global_vars["file_features"][sourcefile].\
                        add_alternative(full_condition[:])

        already_expanded.discard(name)
Ejemplo n.º 7
0
    def process(self, parser, line, basepath):
        line = line.processed_line

        subdir = re.match(r"\s*subdirs-(y|\$[\{\(]" + CONFIG_FORMAT + \
                          r"[\}\)])\s*(:=|\+=|=)\s*(.*)", line)
        if subdir:
            matches = [x for x in re.split("\t| ", subdir.group(4)) if x]
            for match in matches:
                fullpath = os.path.relpath(basepath + "/" + match)
                tmp_condition = DataStructures.Precondition()

                if not subdir.group(1) == "y":
                    tmp_condition.add_condition("CONFIG_" + subdir.group(2))

                if os.path.isdir(fullpath):
                    additional_condition = []
                    # See below, this is not really Kbuild, but approximation to
                    # golem formulae
                    if basepath.startswith("src/mainboard/"):
                        (vendor_option, board_option) = \
                                self.get_vendor_and_board_options_from(basepath)

                        additional_condition = parser.local_vars[
                            "ifdef_condition"][:]
                        additional_condition.append(vendor_option)
                        additional_condition.append(board_option)

                    cond = Helper.build_precondition(
                        [tmp_condition],
                        Helper.build_precondition(
                            parser.global_vars["dir_cond_collection"]
                            [basepath], additional_condition))

                    parser.global_vars["dir_cond_collection"][fullpath].\
                        add_alternative(cond)
                    if not fullpath in parser.local_vars["dir_cond_collection"]:
                        parser.local_vars["dir_cond_collection"].append(
                            fullpath)

            return True

        cls = re.match(r"\s*classes-y\s*\+=\s*(.*)", line)
        if cls:
            parser.global_vars["classes"].extend(cls.group(1).split())

        for cls in parser.global_vars["classes"]:
            cls_match = re.match(
                cls + r"-(y|\$[\(\{]" + CONFIG_FORMAT +
                r"[\}\)]|srcs)\s*(:=|\+=|=)\s*(.*)", line)
            if not cls_match:
                continue

            matches = [x for x in re.split("\t| ", cls_match.group(4)) if x]
            for match in matches:
                fullpath = os.path.relpath(basepath + "/" + match)
                additional_condition = []

                if not cls_match.group(1) == "y" and not cls_match.group(
                        1) == "srcs":
                    additional_condition.append("CONFIG_" + cls_match.group(2))

                # SONDERFALL: src/arch/x86/Makefile.inc
                if basepath == "src/arch/x86" and \
                        cls_match.group(1) == "srcs" and \
                        "$(MAINBOARDDIR)" in match:
                    for mbdir in parser.global_vars["mainboard_dirs"]:
                        cur_fullpath = re.sub(r"\$\(MAINBOARDDIR\)", mbdir,
                                              match)
                        sourcefile = Kbuild.guess_source_for_target(
                            cur_fullpath)
                        if sourcefile:
                            # Information from directory can be converted
                            # into conditions. This is NOT in the Kbuild
                            # system but yields higher equivalence with
                            # golem.
                            (vendor_option, board_option) = \
                                    self.get_vendor_and_board_options_from(cur_fullpath)
                            condition = parser.local_vars["ifdef_condition"][:]
                            condition.append(vendor_option)
                            condition.append(board_option)

                            cond = Helper.build_precondition(
                                parser.global_vars["dir_cond_collection"]
                                [basepath], condition)

                            new_alt = DataStructures.Alternatives()
                            new_alt.add_alternative(cond)
                            parser.global_vars["file_features"][
                                cur_fullpath] = new_alt

                # Normalfall:
                additional_condition.extend(
                    parser.local_vars["ifdef_condition"][:])

                # src/mainboard has conditions we know from the path...
                # Usually this is not in the build system, but can be used
                # for higher equivalence ratings against golem
                if basepath.startswith("src/mainboard/"):
                    (vendor_option, board_option) = \
                        self.get_vendor_and_board_options_from(fullpath)

                    additional_condition.append(vendor_option)
                    additional_condition.append(board_option)

                cond = Helper.build_precondition(
                    parser.global_vars["dir_cond_collection"][basepath],
                    additional_condition)

                sourcefile = Kbuild.guess_source_for_target(fullpath)
                if sourcefile:
                    new_alt = DataStructures.Alternatives()
                    new_alt.add_alternative(cond)
                    parser.global_vars["file_features"][fullpath] = new_alt
                else:
                    parser.local_vars["composite_map"][
                        fullpath].add_alternative(cond)

            return True

        return False