code: def _build_tree_from_outs(outs):
      from dvc_data.hashfile.tree import Tree
  
      tree = Tree()
      for out in outs:
          if not out.use_cache:
              continue
  
          ws, key = out.index_key
  
          if not out.stage.is_partial_import:
              tree.add((ws, *key), out.meta, out.hash_info)
              continue
  
          dep = out.stage.deps[0]
          if not dep.files:
              tree.add((ws, *key), dep.meta, dep.hash_info)
              continue
  
          for okey, ometa, ohi in dep.get_obj():
              tree.add((ws, *key, *okey), ometa, ohi)
  
      tree.digest()
  
      return tree
  
imports: import logging
  import time
  from collections import defaultdict
  from functools import partial
  from itertools import chain
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Set, Tuple, Union
  from funcy.debug import format_time
  from dvc.dependency import ParamsDependency
  from dvc.fs import LocalFileSystem
  from dvc.fs.callbacks import DEFAULT_CALLBACK
  from dvc.log import logger
  from dvc.utils.objects import cached_property
label_desc: Use image node_id 7 for calling a global function with example usage: _build_tree_from_outs(outs) and returns: tree