Esempio n. 1
0
// @return bool                 true if a new dependency was detected as a
//                                  result of satisfying an API for this
//                                  package.
func (r *Resolver) satisfyApis(rpkg *ResolvePackage) bool {
	// Assume all this package's APIs are satisfied and that no new
	// dependencies will be detected.
	rpkg.apisSatisfied = true
	newDeps := false

	features := r.cfg.FeaturesForLpkg(rpkg.LocalPackage)

	// Determine if any of the package's API requirements can now be satisfied.
	// If so, another full iteration is required.
	reqApis := newtutil.GetStringSliceFeatures(rpkg.PkgV, features,
		"pkg.req_apis")
	for _, reqApi := range reqApis {
		reqStatus := rpkg.reqApiMap[reqApi]
		if !reqStatus {
			apiSatisfied := r.satisfyReqApi(rpkg, reqApi)
			if apiSatisfied {
				// An API was satisfied; the package now has a new dependency
				// that needs to be resolved.
				newDeps = true
				reqStatus = true
			} else {
				rpkg.reqApiMap[reqApi] = false
			}
		}
		if reqStatus {
			rpkg.apisSatisfied = false
		}
	}

	return newDeps
}
Esempio n. 2
0
func loadFlags(v *viper.Viper, features map[string]bool,
	key string) []string {

	flags := []string{}

	rawFlags := newtutil.GetStringSliceFeatures(v, features, key)
	for _, rawFlag := range rawFlags {
		if strings.HasPrefix(rawFlag, key) {
			expandedFlags := newtutil.GetStringSliceFeatures(v, features,
				rawFlag)

			flags = append(flags, expandedFlags...)
		} else {
			flags = append(flags, strings.Trim(rawFlag, "\n"))
		}
	}

	return flags
}
Esempio n. 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
}
// 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
}
func (bpkg *BuildPackage) CompilerInfo(
	b *Builder) (*toolchain.CompilerInfo, error) {

	// If this package's compiler info has already been generated, returned the
	// cached copy.
	if bpkg.ci != nil {
		return bpkg.ci, nil
	}

	ci := toolchain.NewCompilerInfo()
	features := b.cfg.FeaturesForLpkg(bpkg.LocalPackage)
	ci.Cflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features,
		"pkg.cflags")
	ci.Lflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features,
		"pkg.lflags")
	ci.Aflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features,
		"pkg.aflags")

	// Package-specific injected settings get specified as C flags on the
	// command line.
	for k, _ := range bpkg.InjectedSettings() {
		ci.Cflags = append(ci.Cflags, syscfg.FeatureToCflag(k))
	}

	ci.IgnoreFiles = []*regexp.Regexp{}
	ignPats := newtutil.GetStringSliceFeatures(bpkg.PkgV,
		features, "pkg.ign_files")
	for _, str := range ignPats {
		re, err := regexp.Compile(str)
		if err != nil {
			return nil, util.NewNewtError(
				"Ignore files, unable to compile re: " + err.Error())
		}
		ci.IgnoreFiles = append(ci.IgnoreFiles, re)
	}

	ci.IgnoreDirs = []*regexp.Regexp{}
	ignPats = newtutil.GetStringSliceFeatures(bpkg.PkgV,
		features, "pkg.ign_dirs")
	for _, str := range ignPats {
		re, err := regexp.Compile(str)
		if err != nil {
			return nil, util.NewNewtError(
				"Ignore dirs, unable to compile re: " + err.Error())
		}
		ci.IgnoreDirs = append(ci.IgnoreDirs, re)
	}

	bpkg.SourceDirectories = newtutil.GetStringSliceFeatures(bpkg.PkgV,
		features, "pkg.src_dirs")

	includePaths, err := bpkg.recursiveIncludePaths(b)
	if err != nil {
		return nil, err
	}

	ci.Includes = append(bpkg.privateIncludeDirs(b), includePaths...)
	bpkg.ci = ci

	return bpkg.ci, nil
}