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 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 (r *Repo) ReadDesc() (*RepoDesc, []*Repo, error) { if util.NodeNotExist(r.repoFilePath() + REPO_FILE_NAME) { return nil, nil, util.NewNewtError("No configuration exists for repository " + r.name) } v, err := util.ReadConfig(r.repoFilePath(), strings.TrimSuffix(REPO_FILE_NAME, ".yml")) if err != nil { return nil, nil, err } name := v.GetString("repo.name") versMap := v.GetStringMapString("repo.versions") rdesc, err := NewRepoDesc(name, versMap) if err != nil { return nil, nil, err } r.rdesc = rdesc repos, err := r.readDepRepos(v) if err != nil { return nil, nil, err } return rdesc, repos, nil }
// Load reads everything that isn't identity specific into the // package func (pkg *LocalPackage) Load() error { // Load configuration log.Debugf("Loading configuration for package %s", pkg.basePath) var err error pkg.PkgV, err = util.ReadConfig(pkg.basePath, strings.TrimSuffix(PACKAGE_FILE_NAME, ".yml")) if err != nil { return err } pkg.AddCfgFilename(pkg.basePath + PACKAGE_FILE_NAME) // Set package name from the package pkg.name = pkg.PkgV.GetString("pkg.name") typeString := pkg.PkgV.GetString("pkg.type") pkg.packageType = PACKAGE_TYPE_LIB for t, n := range PackageTypeNames { if typeString == n { pkg.packageType = t break } } pkg.initFnName = pkg.PkgV.GetString("pkg.init_function") pkg.initStage = pkg.PkgV.GetInt("pkg.init_stage") // Read the package description from the file pkg.desc, err = pkg.readDesc(pkg.PkgV) if err != nil { return err } // Load syscfg settings. if util.NodeExist(pkg.basePath + "/" + SYSCFG_YAML_FILENAME) { pkg.SyscfgV, err = util.ReadConfig(pkg.basePath, strings.TrimSuffix(SYSCFG_YAML_FILENAME, ".yml")) if err != nil { return err } pkg.AddCfgFilename(pkg.basePath + SYSCFG_YAML_FILENAME) } return nil }
func (proj *Project) loadConfig() error { v, err := util.ReadConfig(proj.BasePath, strings.TrimSuffix(PROJECT_FILE_NAME, ".yml")) if err != nil { return util.NewNewtError(err.Error()) } // Store configuration object for access to future values, // this avoids keeping every string around as a project variable when // we need to process it later. proj.v = v proj.projState, err = LoadProjectState() if err != nil { return err } proj.name = v.GetString("project.name") // Local repository always included in initialization r, err := repo.NewLocalRepo(proj.name) if err != nil { return err } proj.repos[proj.name] = r proj.localRepo = r for _, ignDir := range ignoreSearchDirs { r.AddIgnoreDir(ignDir) } rstrs := v.GetStringSlice("project.repositories") for _, repoName := range rstrs { if err := proj.loadRepo(repoName, v); err != nil { return err } } ignoreDirs := v.GetStringSlice("project.ignore_dirs") for _, ignDir := range ignoreDirs { repoName, dirName, err := newtutil.ParsePackageString(ignDir) if err != nil { return err } if repoName == "" { r = proj.LocalRepo() } else { r = proj.FindRepo(repoName) } if r == nil { return util.NewNewtError( fmt.Sprintf("ignore_dirs: unknown repo %s", repoName)) } r.AddIgnoreDir(dirName) } return nil }
func (c *Compiler) load(compilerDir string, buildProfile string) error { v, err := util.ReadConfig(compilerDir, "compiler") if err != nil { return err } features := map[string]bool{ buildProfile: true, strings.ToUpper(runtime.GOOS): true, } c.ccPath = newtutil.GetStringFeatures(v, features, "compiler.path.cc") c.cppPath = newtutil.GetStringFeatures(v, features, "compiler.path.cpp") c.asPath = newtutil.GetStringFeatures(v, features, "compiler.path.as") c.arPath = newtutil.GetStringFeatures(v, features, "compiler.path.archive") c.odPath = newtutil.GetStringFeatures(v, features, "compiler.path.objdump") c.osPath = newtutil.GetStringFeatures(v, features, "compiler.path.objsize") c.ocPath = newtutil.GetStringFeatures(v, features, "compiler.path.objcopy") c.lclInfo.Cflags = loadFlags(v, features, "compiler.flags") c.lclInfo.Lflags = loadFlags(v, features, "compiler.ld.flags") c.lclInfo.Aflags = loadFlags(v, features, "compiler.as.flags") c.ldResolveCircularDeps, err = newtutil.GetBoolFeatures(v, features, "compiler.ld.resolve_circular_deps") if err != nil { return err } c.ldMapFile, err = newtutil.GetBoolFeatures(v, features, "compiler.ld.mapfile") if err != nil { return err } c.ldBinFile, err = newtutil.GetBoolFeaturesDflt(v, features, "compiler.ld.binfile", true) if err != nil { return err } if len(c.lclInfo.Cflags) == 0 { // Assume no Cflags implies an unsupported build profile. return util.FmtNewtError("Compiler doesn't support build profile "+ "specified by target on this OS (build_profile=\"%s\" OS=\"%s\")", buildProfile, runtime.GOOS) } return nil }
func readNewtrc() *viper.Viper { usr, err := user.Current() if err != nil { log.Warn("Failed to obtain user name") return viper.New() } dir := usr.HomeDir + "/" + NEWTRC_DIR v, err := util.ReadConfig(dir, strings.TrimSuffix(REPOS_FILENAME, ".yml")) if err != nil { log.Debugf("Failed to read %s/%s file", dir, REPOS_FILENAME) return viper.New() } return v }
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 }