示例#1
0
def get_comp_info(source_root, mklist, common_include_dir):
    """ Get comp infos that includes:
    comp_dir, include_dir, include_files, Config.in, dependencies
    """
    comp_info = {}
    source_root = os.path.abspath(source_root)

    for mkfile in mklist:
        mkfile = mkfile.replace("\\", "/")
        comp_name = get_comp_name(mkfile)
        if comp_name:
            if comp_name == "system_include" or comp_name == "buildsystem" or comp_name == "buildconfigs":
                continue

            comp_dir = os.path.dirname(mkfile)
            include_info = get_comp_include_info(comp_name, mkfile,
                                                 common_include_dir)
            config_file = get_comp_configin(comp_dir)
            deps = get_comp_deps(mkfile)
            comp_info[comp_name] = include_info
            comp_info[comp_name]["location"] = comp_dir.replace(
                source_root + "/", "")
            comp_info[comp_name]["config_file"] = config_file.replace(
                source_root + "/", "")
            comp_info[comp_name]["dependencies"] = deps

            # Keep a copy for board with dirname
            if comp_name.startswith("board_"):
                board_name = mkfile.split("/")[-2]
                comp_info[board_name] = comp_info[comp_name]

    return comp_info
示例#2
0
def get_app_name(mkfile):
    """ Return app dir name as app name """
    name = None
    patten = re.compile(
        r".*(application/example/example_legacy/|application/example/|application/profile/|test/develop/)(.*)/aos.mk"
    )
    match = patten.match(mkfile)
    if match:
        name = match.group(2).replace("/", ".")

    if not name:
        patten = re.compile(r".*/application/(\w*/)?(.*)/aos.mk")
        match = patten.match(mkfile)
        if match:
            name = match.group(2).replace("/", ".")

    if not name:
        name = get_comp_name(mkfile)

    return name
示例#3
0
def write_depends_topo_file(appdir, comp_deps_file, boardname, topo_file):
    """ find mandatory and optitional depends, and generate topo file """
    comp_infos = {}
    comps = []
    ftopo = []
    with open(comp_deps_file, "r") as f:
        comp_infos = json.load(f)

    # find deps in aos.mk of app and board in APPDIR
    appmkfile = os.path.join(appdir, "aos.mk")
    appname = get_comp_name(appmkfile)
    appcomps = write_comp_deps_from_mkfile(appname, appmkfile, ftopo)
    comps += appcomps
    if boardname:
        boardmkfile = os.path.join(appdir, "board", boardname, "aos.mk")
        comps += write_comp_deps_from_mkfile(boardname, boardmkfile, ftopo)
        comps = list(set(comps))

    # find deps in aos.mk of sdk components
    if comp_infos:
        comps += write_comp_mandatory_depends(comp_infos, comps, ftopo)
        comps = list(set(comps))
        write_comp_optional_depends(comp_infos, comps, ftopo)
        comps = list(set(comps))

    # find deps in source code of app in APPDIR
    if comp_infos:
        write_source_code_depends(appdir, comp_infos, appname, appcomps, ftopo)

    with open(topo_file, "w+") as f:
        ftopo = list(set(ftopo))
        ftopo.sort()
        f.write('digraph demo {\nlabel="components dependency"\n')
        for line in ftopo:
            line = line.replace("aaaaaaaa ", "")
            f.write(line)
        f.write('}\n')
示例#4
0
def write_config_file(source_root, config_file, mklist, appdir=None):
    """ Parse comps and write data to total config file """
    # contents will be wrote to config file
    conf_dict = {}
    # sort as keys
    config_keys = []
    # comp name defined by NAME
    real_names = []
    app_src_dir = [
        os.path.join(source_root, "application").replace("\\", "/"),
        os.path.join(source_root, "test", "develop").replace("\\", "/")
    ]
    board_src_dir = [
        os.path.join(source_root, "platform", "board").replace("\\", "/")
    ]
    appdir = os.environ.get("APPDIR")
    if appdir:
        appdir = appdir.replace("\\", "/")
        app_src_dir.append(appdir)
        board_src_dir.append(os.path.join(appdir, "board").replace("\\", "/"))

    for mkfile in mklist:
        comptype = "normal"
        aliasname = ""
        mkfile = mkfile.replace("\\", "/")
        name = get_comp_name(mkfile)
        if not name:
            continue

        real_names += [name]

        if any(item in mkfile for item in board_src_dir):
            comptype = "board"
            aliasname = get_board_name(mkfile)
        elif any(item in mkfile for item in app_src_dir):
            comptype = "app"
            aliasname = get_app_name(mkfile)
        else:
            pass

        if not name in conf_dict:
            conf_dict[name] = {
                "mkfile": mkfile,
                "aliasname": aliasname,
                "type": comptype
            }
            config_keys += [name]
        else:
            if appdir:
                # Override board and app component with the one from appdir
                if appdir in mkfile and "/board/" in mkfile:
                    conf_dict[name] = {
                        "mkfile": mkfile,
                        "aliasname": aliasname,
                        "type": comptype
                    }
                elif os.path.join(appdir, "aos.mk") == mkfile:
                    conf_dict[name] = {
                        "mkfile": mkfile,
                        "aliasname": aliasname,
                        "type": comptype
                    }
                else:
                    print("[WARNING]: Duplicate component found: %s" % name)
                    print("- %s: %s" % (name, conf_dict[name]))
                    print("- %s: %s" % (name, mkfile))
            else:
                print("[ERROR]: Duplicate component found: %s" % name)
                print("- %s: %s" % (name, conf_dict[name]))
                print("- %s: %s" % (name, mkfile))
                return 1

    with open(config_file, 'w') as f:
        f.write("REAL_COMPONENTS := %s\n" % " ".join(real_names))
        for compname in real_names:
            optname = get_comp_optname(compname, conf_dict[compname]["mkfile"])
            if conf_dict[compname]["type"] == "app" or conf_dict[compname][
                    "type"] == "board":
                f.write("OBJ-$(%s) += %s\n" %
                        (optname, conf_dict[compname]["aliasname"]))
            else:
                f.write("OBJ-$(%s) += %s\n" % (optname, compname))

        for key in config_keys:
            mkfile = conf_dict[key]["mkfile"]
            location = os.path.dirname(mkfile)
            aliasname = conf_dict[key]["aliasname"]
            f.write("%s_MAKEFILE := %s\n" % (key, mkfile))
            f.write("%s_LOCATION := %s\n" % (key, location))
            if aliasname and aliasname != key:
                f.write("%s_MAKEFILE := %s\n" % (aliasname, mkfile))
                f.write("%s_LOCATION := %s\n" % (aliasname, location))