Example #1
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
}
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
}
Example #3
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
}