code: def write_contents(self, root_target, reduced_dependencies, chroot):
      
      def write_target_source(target, src):
        chroot.copy(os.path.join(get_buildroot(), target.target_base, src),
                    os.path.join(self.SOURCE_ROOT, src))
        # check parent __init__.pys to see if they also need to be copied.  this is to allow
        # us to determine if they belong to regular packages or namespace packages.
        while True:
          src = os.path.dirname(src)
          if not src:
            # Do not allow the repository root to leak (i.e. '.' should not be a package in setup.py)
            break
          if os.path.exists(os.path.join(target.target_base, src, '__init__.py')):
            chroot.copy(os.path.join(target.target_base, src, '__init__.py'),
                        os.path.join(self.SOURCE_ROOT, src, '__init__.py'))
  
      def write_target(target):
        # We want to operate on the final sources target owns, so we potentially replace it with
        # the target derived from it (by a codegen task).
        subject = self.derived_by_original.get(target, target)
        for rel_source in subject.sources_relative_to_buildroot():
          abs_source_path = os.path.join(get_buildroot(), rel_source)
          abs_source_root_path = os.path.join(get_buildroot(), subject.target_base)
          source_root_relative_path = os.path.relpath(abs_source_path, abs_source_root_path)
          write_target_source(subject, source_root_relative_path)
  
      write_target(root_target)
      for dependency in reduced_dependencies:
        if self.is_python_target(dependency) and not dependency.provides:
          write_target(dependency)
        elif self.is_resources_target(dependency):
          write_target(dependency)
docs: Write contents of the target.