コード例 #1
0
ファイル: build.go プロジェクト: apache/incubator-mynewt-newt
func (b *Builder) Test(p *pkg.LocalPackage) error {
	// Build the packages alphabetically to ensure a consistent order.
	bpkgs := b.sortedBuildPackages()
	for _, bpkg := range bpkgs {
		if err := b.buildPackage(bpkg); err != nil {
			return err
		}
	}

	testBpkg := b.PkgMap[p]
	testFilename := b.TestExePath(testBpkg)
	if err := b.link(testFilename, nil, nil); err != nil {
		return err
	}

	// Run the tests.
	if err := os.Chdir(filepath.Dir(testFilename)); err != nil {
		return err
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Executing test: %s\n",
		testFilename)
	if _, err := util.ShellCommand(testFilename); err != nil {
		newtError := err.(*util.NewtError)
		newtError.Text = fmt.Sprintf("Test failure (%s):\n%s", p.Name(),
			newtError.Text)
		return newtError
	}

	return nil
}
コード例 #2
0
func (target *Target) Load(basePkg *pkg.LocalPackage) error {
	v, err := util.ReadConfig(basePkg.BasePath(),
		strings.TrimSuffix(TARGET_FILENAME, ".yml"))
	if err != nil {
		return err
	}

	target.Vars = map[string]string{}

	settings := v.AllSettings()
	for k, v := range settings {
		target.Vars[k] = v.(string)
	}

	target.BspName = target.Vars["target.bsp"]
	target.AppName = target.Vars["target.app"]
	target.LoaderName = target.Vars["target.loader"]
	target.BuildProfile = target.Vars["target.build_profile"]

	if target.BuildProfile == "" {
		target.BuildProfile = DEFAULT_BUILD_PROFILE
	}

	// Note: App not required in the case of unit tests.

	// Remember the name of the configuration file so that it can be specified
	// as a dependency to the compiler.
	target.basePkg.AddCfgFilename(basePkg.BasePath() + TARGET_FILENAME)

	return nil
}
コード例 #3
0
func (cfg *Cfg) readDefsOnce(lpkg *pkg.LocalPackage,
	features map[string]bool) error {
	v := lpkg.SyscfgV

	lfeatures := cfg.FeaturesForLpkg(lpkg)
	for k, _ := range features {
		lfeatures[k] = true
	}

	settings := newtutil.GetStringMapFeatures(v, lfeatures, "syscfg.defs")
	if settings != nil {
		for k, v := range settings {
			vals := v.(map[interface{}]interface{})
			entry, err := readSetting(k, lpkg, vals)
			if err != nil {
				return util.FmtNewtError("Config for package %s: %s",
					lpkg.Name(), err.Error())
			}

			if _, exists := cfg.Settings[k]; exists {
				// XXX: Better error message.
				return util.FmtNewtError("setting %s redefined", k)
			}
			cfg.Settings[k] = entry
		}
	}

	return nil
}
コード例 #4
0
func (cfg *Cfg) FeaturesForLpkg(lpkg *pkg.LocalPackage) map[string]bool {
	features := cfg.Features()

	for k, v := range lpkg.InjectedSettings() {
		_, ok := features[k]
		if ok {
			log.Warnf("Attempt to override syscfg setting %s with "+
				"injected feature from package %s", k, lpkg.Name())
		} else {
			if ValueIsTrue(v) {
				features[k] = true
			}
		}
	}

	return features
}
コード例 #5
0
func pkgToUnitTests(pack *pkg.LocalPackage) []*pkg.LocalPackage {
	// If the user specified a unittest package, just test that one.
	if pack.Type() == pkg.PACKAGE_TYPE_UNITTEST {
		return []*pkg.LocalPackage{pack}
	}

	// Otherwise, return all the package's direct descendants that are unit
	// test packages.
	result := []*pkg.LocalPackage{}
	srcPath := pack.BasePath()
	for p, _ := range testablePkgs() {
		if p.Type() == pkg.PACKAGE_TYPE_UNITTEST &&
			filepath.Dir(p.BasePath()) == srcPath {

			result = append(result, p)
		}
	}

	return result
}
コード例 #6
0
func (cfg *Cfg) readValsOnce(lpkg *pkg.LocalPackage,
	features map[string]bool) error {
	v := lpkg.SyscfgV

	lfeatures := cfg.FeaturesForLpkg(lpkg)
	for k, _ := range features {
		lfeatures[k] = true
	}

	values := newtutil.GetStringMapFeatures(v, lfeatures, "syscfg.vals")
	for k, v := range values {
		if normalizePkgType(lpkg.Type()) == pkg.PACKAGE_TYPE_LIB {
			// A library package is overriding a setting; this is disallowed.
			// Overrides must come from a higher priority package.
			lateral := CfgLateral{
				PkgName:     lpkg.Name(),
				SettingName: k,
			}
			cfg.Laterals = append(cfg.Laterals, lateral)
		} else {
			entry, ok := cfg.Settings[k]
			if ok {
				entry.appendValue(lpkg, v)
				cfg.Settings[k] = entry
			} else {
				orphan := CfgPoint{
					Value:  stringValue(v),
					Source: lpkg,
				}
				cfg.Orphans[k] = append(cfg.Orphans[k], orphan)
			}
		}
	}

	return nil
}
コード例 #7
0
ファイル: load.go プロジェクト: apache/incubator-mynewt-newt
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
}