code: func (pl *PackageLoader) resolveWithOpts(c context.Context, opts cipd.ClientOptions,
  	expander template.Expander, spec *vpython.Spec) error {
  
  	logging.Debugf(c, "Resolving CIPD packages in root [%s]:", opts.Root)
  	ef, packages := specToEnsureFile(spec)
  
  	// Log our unresolved packages. Note that "specToEnsureFile" only creates
  	// a subdir entry for the root (""), so we don't need to deterministically
  	// iterate over the full map.
  	if logging.IsLogging(c, logging.Debug) {
  		for _, pkg := range ef.PackagesBySubdir[""] {
  			logging.Debugf(c, "\tUnresolved package: %s", pkg)
  		}
  	}
  
  	client, err := cipd.NewClient(opts)
  	if err != nil {
  		return errors.Annotate(err, "failed to generate CIPD client").Err()
  	}
  
  	// Start a CIPD client batch.
  	client.BeginBatch(c)
  	defer client.EndBatch(c)
  
  	// Resolve our ensure file.
  	resolver := cipd.Resolver{Client: client}
  	resolved, err := resolver.Resolve(c, ef, expander)
  	if err != nil {
  		return err
  	}
  
  	// Write the results to "packages". All of them should have been installed
  	// into the root subdir.
  	for i, pkg := range resolved.PackagesBySubdir[""] {
  		packages[i].Name = pkg.PackageName
  		packages[i].Version = pkg.InstanceID
  	}
  	return nil
  }
docs: // resolveWithOpts resolves the specified packages.
  //
  // The supplied spec is updated with the resolved packages.