微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何获取为给定目标计算的所有源依赖项 SCons?

如何解决如何获取为给定目标计算的所有源依赖项 SCons?

我想在构建给定目标后立即以编程方式执行此操作,在 SCons 构建运行期间,而不是使用 --tree 或任何其他命令来执行 scons。我有一个目标节点。它可能有一些明确的依赖项、使用过的扫描仪、基于文件扩展名的扫描仪,以及其他任何 SCons 计算出来的东西。所以喜欢:

all_source_nodes = tgt_node.get_all_sources(...)

搜索了文档和 API。只在 FS 节点上看到 get_stored_implicit。我得到了 None 和 .prerequisites.implicit 节点成员。

我还发现 .sources 节点成员显示了传递给构建器的直接源。当然,这还不够,因为我基本上需要依赖子树的所有节点,还有很多。

解决方法

在处理 SConstruct/SConscript 时,您不会获得大部分信息。

之后依赖关系图被完全填充。

,

尤里卡! :) 构建信息数据和递归扫描器应用程序的组合为我提供了所有 scons --tree=prune 报告。下面的完整代码,以及一些信息性消息。

deps = set()
_find_deps(tgt,None,env,deps)
dep_paths = set(map(str,deps))    # Some nodes refer to the same paths    
print ("'{}' - got {} source dependencies:\n\t{}".format(
        name_str,len(dep_paths),"\n\t".join(sorted(map(str,deps)))))


def _find_deps(node,children_func,visited):
    """Recursively traverses children dependencies from build info and by applying 
    children_func (scanner) to collect the full set of all dependencies ('visited') 
    starting with node as the dependency tree root.
    :Parameters:
        - node          the current target we check (root node of the sub-tree)
        - children_func the function called to get the children of a node
        - env           the current environment
        - visited:      the set of visited nodes since we started - the final result
    """
    build_info = node.get_binfo()  # current build info
    children = set(build_info.bsources + build_info.bdepends + build_info.bimplicit)
    binfo_deps = set(build_info.bsources + build_info.bdepends + build_info.bimplicit)
    
    # Apply children func,if available and merge in the results
    scanned_deps = set()
    if children_func:
        scanned_deps = set(children_func(node))
        children |= scanned_deps

    total = len(binfo_deps) + len(scanned_deps)
    total_unique = len(children)
    n_prev_visited = len(visited)
    if total == 0:
        print("'{}' initial   - 0 deps!".format(str(node)))
    else:
        print("'{}' initial   - {} deps ({} unique): {} from build info,{} from child func"
            .format(str(node),total,total_unique,len(binfo_deps),len (scanned_deps)))
    
    # Iterate all the unvisited children and recursively call _find_deps with children_func 
    # specific to each child
    for child in children:
        if child and child not in visited:
            visited.add(child)              # record the dependency
            scanner = node.get_source_scanner(child)
                        # Note: get_build_scanner_path fails on nodes without executor
            path = node.get_build_scanner_path(scanner) if scanner and node.get_executor() else None
            def children_func(node,env=env,scanner=scanner,path=path):
                return node.get_found_includes(env,scanner,path)
            
            _find_deps(child,visited)

    if len(visited) != n_prev_visited:
        print("'{}' traversed - {} additional deps found.".format(str(node),len(visited) - n_prev_visited))

在高性能机器上大约一秒钟内获得 700 多个依赖项。这应该在后期操作中调用,即在构建节点之后。在构建节点之前调用时可能仍然可以正常工作。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。