def _fetch_pkg(self, gopath, pkg, rev):
    """Fetch the package and setup symlinks."""
    fetcher = self._get_fetcher(pkg)
    root = fetcher.root()
    root_dir = os.path.join(self.workdir, 'fetches', root, rev)

    # Only fetch each remote root once.
    if not os.path.exists(root_dir):
      with temporary_dir() as tmp_fetch_root:
        with self.context.new_workunit('fetch {}'.format(pkg)):
          fetcher.fetch(dest=tmp_fetch_root, rev=rev)
          safe_mkdir(root_dir)
          for path in os.listdir(tmp_fetch_root):
            shutil.move(os.path.join(tmp_fetch_root, path), os.path.join(root_dir, path))

    # TODO(John Sirois): Circle back and get get rid of this symlink tree.
    # GoWorkspaceTask will further symlink a single package from the tree below into a
    # target's workspace when it could just be linking from the fetch_dir.  The only thing
    # standing in the way is a determination of what we want to artifact cache.  If we don't
    # want to cache fetched zips, linking straight from the fetch_dir works simply.  Otherwise
    # thought needs to be applied to using the artifact cache directly or synthesizing a
    # canonical owner target for the fetched files that 'child' targets (subpackages) can
    # depend on and share the fetch from.
    dest_dir = os.path.join(gopath, 'src', root)
    # We may have been `invalidate`d and not `clean-all`ed so we need a new empty symlink
    # chroot to avoid collision; thus `clean=True`.
    safe_mkdir(dest_dir, clean=True)
    for path in os.listdir(root_dir):
      os.symlink(os.path.join(root_dir, path), os.path.join(dest_dir, path))
def _fetch_pkg ( self , gopath , pkg , rev ) : fetcher = self . _get_fetcher ( pkg ) root = fetcher . root ( ) root_dir = os . path . join ( self . workdir , 'fetches' , root , rev ) if not os . path . exists ( root_dir ) : with temporary_dir ( ) as tmp_fetch_root : with self . context . new_workunit ( 'fetch {}' . format ( pkg ) ) : fetcher . fetch ( dest = tmp_fetch_root , rev = rev ) safe_mkdir ( root_dir ) for path in os . listdir ( tmp_fetch_root ) : shutil . move ( os . path . join ( tmp_fetch_root , path ) , os . path . join ( root_dir , path ) ) dest_dir = os . path . join ( gopath , 'src' , root ) safe_mkdir ( dest_dir , clean = True ) for path in os . listdir ( root_dir ) : os . symlink ( os . path . join ( root_dir , path ) , os . path . join ( dest_dir , path ) )
Fetch the package and setup symlinks.