Example #1
0
func InitProject() *project.Project {
	var p *project.Project
	var err error

	if p, err = project.TryGetProject(); err != nil {
		NewtUsage(nil, err)
	}

	for _, w := range p.Warnings() {
		util.ErrorMessage(util.VERBOSITY_QUIET, "* Warning: %s\n", w)
	}

	return p
}
func mfgList() []string {
	names := []string{}

	proj, err := project.TryGetProject()
	if err != nil {
		return names
	}

	for _, pack := range proj.PackagesOfType(pkg.PACKAGE_TYPE_MFG) {
		names = append(names, strings.TrimPrefix(pack.Name(), "mfgs/"))
	}

	sort.Strings(names)
	return names
}
Example #3
0
// Returns a slice of valid values for the target variable with the specified
// name.  If an invalid target variable is specified, an error is returned.
func VarValues(varName string) ([]string, error) {
	_, err := project.TryGetProject()
	if err != nil {
		return nil, err
	}

	fn := varsMap[varName]
	if fn == nil {
		err := util.NewNewtError(fmt.Sprintf("Unknown setting name: \"%s\"",
			varName))
		return nil, err
	}

	values, err := fn()
	if err != nil {
		return nil, err
	}

	return values, nil
}
func targetList() []string {
	targetNames := []string{}

	if _, err := project.TryGetProject(); err != nil {
		return targetNames
	}

	for name, _ := range target.GetTargets() {
		// Don't display the special unittest target; this is used
		// internally by newt, so the user doesn't need to know about it.
		// XXX: This is a hack; come up with a better solution for unit
		// testing.
		if !strings.HasSuffix(name, "/unittest") {
			targetNames = append(targetNames,
				strings.TrimPrefix(name, "targets/"))
		}
	}

	sort.Strings(targetNames)
	return targetNames
}
func testablePkgs() map[*pkg.LocalPackage]struct{} {
	if testablePkgMap != nil {
		return testablePkgMap
	}

	testablePkgMap := map[*pkg.LocalPackage]struct{}{}

	// Create a map of path => lclPkg.
	proj, err := project.TryGetProject()
	if err != nil {
		return nil
	}

	allPkgs := proj.PackagesOfType(-1)
	pathLpkgMap := make(map[string]*pkg.LocalPackage, len(allPkgs))
	for _, p := range allPkgs {
		lpkg := p.(*pkg.LocalPackage)
		pathLpkgMap[lpkg.BasePath()] = lpkg
	}

	// Add all unit test packages to the testable package map.
	testPkgs := proj.PackagesOfType(pkg.PACKAGE_TYPE_UNITTEST)
	for _, p := range testPkgs {
		lclPack := p.(*pkg.LocalPackage)
		testablePkgMap[lclPack] = struct{}{}
	}

	// Next add first ancestor of each test package.
	for testPkg, _ := range testablePkgMap {
		for cur := filepath.Dir(testPkg.BasePath()); cur != proj.BasePath; cur = filepath.Dir(cur) {
			lpkg := pathLpkgMap[cur]
			if lpkg != nil && lpkg.Type() != pkg.PACKAGE_TYPE_UNITTEST {
				testablePkgMap[lpkg] = struct{}{}
				break
			}
		}
	}

	return testablePkgMap
}