Пример #1
0
func (proj *Project) ResolvePackage(
	dfltRepo interfaces.RepoInterface, name string) (*pkg.LocalPackage, error) {
	// Trim trailing slash from name.  This is necessary when tab
	// completion is used to specify the name.
	name = strings.TrimSuffix(name, "/")

	repoName, pkgName, err := newtutil.ParsePackageString(name)
	if err != nil {
		return nil, util.FmtNewtError("invalid package name: %s (%s)", name,
			err.Error())
	}

	var repo interfaces.RepoInterface
	if repoName == "" {
		repo = dfltRepo
	} else {
		repo = proj.repos[repoName]
	}

	dep, err := pkg.NewDependency(repo, pkgName)
	if err != nil {
		return nil, util.FmtNewtError("invalid package name: %s (%s)", name,
			err.Error())
	}
	if dep == nil {
		return nil, util.NewNewtError("invalid package name: " + name)
	}
	pack := proj.ResolveDependency(dep)
	if pack == nil {
		return nil, util.NewNewtError("unknown package: " + name)
	}

	return pack.(*pkg.LocalPackage), nil
}
Пример #2
0
func (target *Target) resolvePackageName(name string) *pkg.LocalPackage {
	dep, err := pkg.NewDependency(target.basePkg.Repo(), name)
	if err != nil {
		return nil
	}

	pack, ok := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
	if !ok {
		return nil
	}

	return pack
}
Пример #3
0
// @return bool                 True if this this function changed the builder
//                                  state; another full iteration is required
//                                  in this case.
//         error                non-nil on failure.
func (r *Resolver) loadDepsForPkg(rpkg *ResolvePackage) (bool, error) {
	proj := project.GetProject()
	features := r.cfg.FeaturesForLpkg(rpkg.LocalPackage)

	changed := false

	newDeps := newtutil.GetStringSliceFeatures(rpkg.PkgV, features, "pkg.deps")
	for _, newDepStr := range newDeps {
		newDep, err := pkg.NewDependency(rpkg.Repo(), newDepStr)
		if err != nil {
			return false, err
		}

		lpkg, ok := proj.ResolveDependency(newDep).(*pkg.LocalPackage)
		if !ok {
			return false,
				util.FmtNewtError("Could not resolve package dependency: "+
					"%s; depender: %s", newDep.String(), rpkg.Name())
		}

		if r.pkgMap[lpkg] == nil {
			changed = true
			r.addPkg(lpkg)
		}
	}

	// Determine if this package supports any APIs that we haven't seen
	// yet.  If so, another full iteration is required.
	apis := newtutil.GetStringSliceFeatures(rpkg.PkgV, features, "pkg.apis")
	for _, api := range apis {
		newApi := r.addApi(api, rpkg)
		if newApi {
			changed = true
		}
	}

	return changed, nil
}
Пример #4
0
// Resolves all of a build package's dependencies and API requirements.
func (bpkg *BuildPackage) resolveDeps(
	cfg syscfg.Cfg, apiMap map[string]*BuildPackage) error {

	features := cfg.FeaturesForLpkg(bpkg.LocalPackage)

	// Match each required API with the package which implements it.
	reqApis := newtutil.GetStringSliceFeatures(bpkg.PkgV, features,
		"pkg.req_apis")
	for _, reqApi := range reqApis {
		if err := bpkg.satisfyReqApi(reqApi, apiMap[reqApi]); err != nil {
			return err
		}
	}

	proj := project.GetProject()
	newDeps := newtutil.GetStringSliceFeatures(bpkg.PkgV, features,
		"pkg.deps")
	for _, newDepStr := range newDeps {
		newDep, err := pkg.NewDependency(bpkg.Repo(), newDepStr)
		if err != nil {
			return err
		}

		_, ok := proj.ResolveDependency(newDep).(*pkg.LocalPackage)
		if !ok {
			return util.NewNewtError("Could not resolve package dependency " +
				newDep.String())
		}

		if !bpkg.HasDep(newDep) {
			bpkg.AddDep(newDep)
		}
	}

	return nil
}