// Recursively iterates through an pkg's dependencies, adding each pkg
// encountered to the supplied set.
func (bpkg *BuildPackage) collectDepsAux(b *Builder,
	set *map[*BuildPackage]bool) error {

	if (*set)[bpkg] {
		return nil
	}

	(*set)[bpkg] = true

	for _, dep := range bpkg.Deps() {
		if dep.Name == "" {
			break
		}

		// Get pkg structure
		p := project.GetProject().ResolveDependency(dep)
		if p == nil {
			return util.FmtNewtError("Cannot resolve dependency %+v", dep)
		}
		dpkg := p.(*pkg.LocalPackage)

		dbpkg := b.PkgMap[dpkg]
		if dbpkg == nil {
			return util.FmtNewtError("Package not found %s; required by %s",
				dpkg.Name(), bpkg.Name())
		}

		if err := dbpkg.collectDepsAux(b, set); err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 2
0
func buildProfileValues() ([]string, error) {
	profileMap := map[string]struct{}{}

	packs := project.GetProject().PackagesOfType(pkg.PACKAGE_TYPE_COMPILER)
	for _, pack := range packs {
		v, err := util.ReadConfig(pack.(*pkg.LocalPackage).BasePath(),
			"compiler")
		if err != nil {
			return nil, err
		}

		settingMap := v.AllSettings()
		for k, _ := range settingMap {
			if strings.HasPrefix(k, "compiler.flags") {
				fields := strings.Split(k, ".")
				if len(fields) >= 3 {
					profileMap[fields[2]] = struct{}{}
				}
			}
		}
	}

	values := make([]string, 0, len(profileMap))
	for k, _ := range profileMap {
		values = append(values, k)
	}

	sort.Strings(values)

	return values, nil
}
func NewTargetTester(target *target.Target,
	testPkg *pkg.LocalPackage) (*TargetBuilder, error) {

	if err := target.Validate(testPkg == nil); err != nil {
		return nil, err
	}

	bspPkg, err := pkg.NewBspPackage(target.Bsp())
	if err != nil {
		return nil, err
	}

	compilerPkg, err := project.GetProject().ResolvePackage(
		bspPkg.Repo(), bspPkg.CompilerName)
	if err != nil {
		return nil, err
	}

	t := &TargetBuilder{
		target:           target,
		bspPkg:           bspPkg,
		compilerPkg:      compilerPkg,
		appPkg:           target.App(),
		loaderPkg:        target.Loader(),
		testPkg:          testPkg,
		injectedSettings: map[string]string{},
	}

	return t, nil
}
Esempio n. 4
0
func (b *Builder) Debug(extraJtagCmd string, reset bool, noGDB bool) error {
	if b.appPkg == nil {
		return util.NewNewtError("app package not specified")
	}

	/*
	 * Populate the package list and feature sets.
	 */
	err := b.targetBuilder.PrepBuild()
	if err != nil {
		return err
	}

	bspPath := b.bspPkg.BasePath()
	binBaseName := b.AppBinBasePath()
	featureString := b.FeatureString()

	coreRepo := project.GetProject().FindRepo("apache-mynewt-core")
	envSettings := []string{
		fmt.Sprintf("CORE_PATH=%s", coreRepo.Path()),
		fmt.Sprintf("BSP_PATH=%s", bspPath),
		fmt.Sprintf("BIN_BASENAME=%s", binBaseName),
		fmt.Sprintf("FEATURES=\"%s\"", featureString),
	}
	if extraJtagCmd != "" {
		envSettings = append(envSettings,
			fmt.Sprintf("EXTRA_JTAG_CMD=%s", extraJtagCmd))
	}
	if reset == true {
		envSettings = append(envSettings, fmt.Sprintf("RESET=true"))
	}
	if noGDB == true {
		envSettings = append(envSettings, fmt.Sprintf("NO_GDB=1"))
	}

	os.Chdir(project.GetProject().Path())

	// bspPath, binBaseName are passed in command line for backwards
	// compatibility
	cmdLine := []string{
		b.targetBuilder.bspPkg.DebugScript, bspPath, binBaseName,
	}

	fmt.Printf("%s\n", cmdLine)
	return util.ShellInteractiveCommand(cmdLine, envSettings)
}
Esempio n. 5
0
func ResetGlobalState() error {
	// Make sure the current working directory is at the project base.
	if err := os.Chdir(project.GetProject().Path()); err != nil {
		return util.NewNewtError("Failed to reset global state: " +
			err.Error())
	}

	target.ResetTargets()
	project.ResetProject()

	return nil
}
Esempio n. 6
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
}
Esempio n. 7
0
func buildTargetMap() error {
	globalTargetMap = map[string]*Target{}

	packs := project.GetProject().PackagesOfType(pkg.PACKAGE_TYPE_TARGET)
	for _, packItf := range packs {
		pack := packItf.(*pkg.LocalPackage)
		target, err := LoadTarget(pack)
		if err != nil {
			nerr := err.(*util.NewtError)
			util.ErrorMessage(util.VERBOSITY_QUIET,
				"Warning: failed to load target \"%s\": %s\n", pack.Name(),
				nerr.Text)
		} else {
			globalTargetMap[pack.FullName()] = target
		}
	}

	return nil
}
Esempio n. 8
0
func varsFromPackageType(
	pt interfaces.PackageType, fullPath bool) ([]string, error) {

	values := []string{}

	packs := project.GetProject().PackagesOfType(pt)
	for _, pack := range packs {
		value := pack.FullName()
		if !fullPath {
			value = filepath.Base(value)
		}

		values = append(values, value)
	}

	sort.Strings(values)

	return values, nil
}
Esempio n. 9
0
func (b *Builder) testOwner(p *BuildPackage) *BuildPackage {
	if p.Type() != pkg.PACKAGE_TYPE_UNITTEST {
		panic("Expected unittest package; got: " + p.Name())
	}

	curPath := p.BasePath()

	for {
		parentPath := filepath.Dir(curPath)
		if parentPath == project.GetProject().BasePath || parentPath == "." {
			return nil
		}

		parentPkg := b.pkgWithPath(parentPath)
		if parentPkg != nil && parentPkg.Type() != pkg.PACKAGE_TYPE_UNITTEST {
			return parentPkg
		}

		curPath = parentPath
	}
}
Esempio n. 10
0
func settingValues(settingName string) ([]string, error) {
	settingMap := map[string]struct{}{}

	packs := project.GetProject().PackagesOfType(-1)
	for _, pack := range packs {
		settings :=
			pack.(*pkg.LocalPackage).PkgV.GetStringSlice(settingName)

		for _, setting := range settings {
			settingMap[setting] = struct{}{}
		}
	}

	values := make([]string, 0, len(settingMap))
	for f, _ := range settingMap {
		values = append(values, f)
	}
	sort.Strings(values)

	return values, nil
}
Esempio n. 11
0
func Load(binBaseName string, bspPkg *pkg.BspPackage,
	extraEnvSettings map[string]string) error {

	if bspPkg.DownloadScript == "" {
		return nil
	}

	bspPath := bspPkg.BasePath()

	sortedKeys := make([]string, 0, len(extraEnvSettings))
	for k, _ := range extraEnvSettings {
		sortedKeys = append(sortedKeys, k)
	}
	sort.Strings(sortedKeys)

	envSettings := ""
	for _, key := range sortedKeys {
		envSettings += fmt.Sprintf("%s=\"%s\" ", key, extraEnvSettings[key])
	}

	coreRepo := project.GetProject().FindRepo("apache-mynewt-core")
	envSettings += fmt.Sprintf("CORE_PATH=\"%s\" ", coreRepo.Path())
	envSettings += fmt.Sprintf("BSP_PATH=\"%s\" ", bspPath)
	envSettings += fmt.Sprintf("BIN_BASENAME=\"%s\" ", binBaseName)

	// bspPath, binBaseName are passed in command line for backwards
	// compatibility
	downloadCmd := fmt.Sprintf("%s %s %s %s", envSettings,
		bspPkg.DownloadScript, bspPath, binBaseName)

	util.StatusMessage(util.VERBOSITY_VERBOSE, "Load command: %s\n",
		downloadCmd)
	_, err := util.ShellCommand(downloadCmd)
	if err != nil {
		return err
	}
	util.StatusMessage(util.VERBOSITY_VERBOSE, "Successfully loaded image.\n")

	return nil
}
Esempio n. 12
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
}
Esempio n. 13
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
}
Esempio n. 14
0
func BinRoot() string {
	return project.GetProject().Path() + "/bin"
}
Esempio n. 15
0
func Load(basePkg *pkg.LocalPackage) (*MfgImage, error) {
	v, err := util.ReadConfig(basePkg.BasePath(),
		strings.TrimSuffix(MFG_YAML_FILENAME, ".yml"))
	if err != nil {
		return nil, err
	}

	mi := &MfgImage{
		basePkg: basePkg,
	}

	bootName := v.GetString("mfg.bootloader")
	if bootName == "" {
		return nil, mi.loadError("mfg.bootloader field required")
	}
	mi.boot, err = mi.loadTarget(bootName)
	if err != nil {
		return nil, err
	}

	imgNames := v.GetStringSlice("mfg.images")
	if imgNames != nil {
		for _, imgName := range imgNames {
			imgTarget, err := mi.loadTarget(imgName)
			if err != nil {
				return nil, err
			}

			mi.images = append(mi.images, imgTarget)
		}
	}

	if len(mi.images) > 2 {
		return nil, mi.loadError("too many images (%d); maximum is 2",
			len(mi.images))
	}

	itf := v.Get("mfg.raw")
	slice := cast.ToSlice(itf)
	if slice != nil {
		for i, entryItf := range slice {
			yamlEntry := cast.ToStringMapString(entryItf)
			entry, err := mi.loadRawEntry(i, yamlEntry)
			if err != nil {
				return nil, err
			}

			mi.rawEntries = append(mi.rawEntries, entry)
		}
	}

	proj := project.GetProject()

	bspLpkg, err := proj.ResolvePackage(mi.basePkg.Repo(),
		mi.boot.BspName)
	if err != nil {
		return nil, mi.loadError(
			"could not resolve boot loader BSP package: %s",
			mi.boot.BspName)
	}
	mi.bsp, err = pkg.NewBspPackage(bspLpkg)
	if err != nil {
		return nil, mi.loadError(err.Error())
	}

	for _, imgTarget := range mi.images {
		if len(mi.images) > 1 && imgTarget.LoaderName != "" {
			return nil, mi.loadError("only one image allowed in "+
				"split image mode (%s is a split build)", imgTarget.Name())
		}

		if imgTarget.Bsp() != mi.bsp.LocalPackage {
			return nil, mi.loadError(
				"image target \"%s\" specified conflicting BSP; "+
					"boot loader uses %s, image uses %s",
				imgTarget.Name(), mi.bsp.Name(), imgTarget.BspName)
		}
	}

	if err := mi.detectInvalidDevices(); err != nil {
		return nil, err
	}

	return mi, nil
}