func (cpm *ConnProfileMgr) Init() error {
	filename, err := connProfileCfgFilename()
	if err != nil {
		return err
	}

	// XXX: Should determine whether file exists by attempting to read it.
	if util.NodeExist(filename) {
		blob, err := ioutil.ReadFile(filename)
		if err != nil {
			return util.NewNewtError(err.Error())
		}

		var profiles []*ConnProfile
		err = json.Unmarshal(blob, &profiles)
		if err != nil {
			return util.FmtNewtError("error reading connection profile "+
				"config (%s): %s", filename, err.Error())
		}

		for _, p := range profiles {
			cpm.profiles[p.MyName] = p
		}
	}

	return nil
}
Beispiel #2
0
func (r *Repo) checkForceInstall(force bool) (error, bool) {
	// Copy the git repo into /repos/, error'ing out if the repo already exists
	if util.NodeExist(r.Path()) {
		if force {
			if err := os.RemoveAll(r.Path()); err != nil {
				return util.NewNewtError(err.Error()), true
			}
		}
		return nil, true
	}
	return nil, false
}
// Generates the following build artifacts:
//    * lst file
//    * map file
//    * bin file
//
// @param elfFilename           The filename of the elf file corresponding to
//                                  the artifacts to be generated.
// @param options               Some build options specifying which artifacts
//                                  get generated.
func (c *Compiler) generateExtras(elfFilename string,
	options map[string]bool) error {

	var cmd string

	if options["binFile"] {
		binFile := elfFilename + ".bin"
		cmd = c.ocPath + " -R .bss -R .bss.core -R .bss.core.nz -O binary " +
			elfFilename + " " + binFile
		_, err := util.ShellCommand(cmd)
		if err != nil {
			return err
		}
	}

	if options["listFile"] {
		listFile := elfFilename + ".lst"
		// if list file exists, remove it
		if util.NodeExist(listFile) {
			if err := os.RemoveAll(listFile); err != nil {
				return err
			}
		}

		cmd = c.odPath + " -wxdS " + elfFilename + " >> " + listFile
		_, err := util.ShellCommand(cmd)
		if err != nil {
			// XXX: gobjdump appears to always crash.  Until we get that sorted
			// out, don't fail the link process if lst generation fails.
			return nil
		}

		sects := []string{".text", ".rodata", ".data"}
		for _, sect := range sects {
			cmd = c.odPath + " -s -j " + sect + " " + elfFilename + " >> " +
				listFile
			util.ShellCommand(cmd)
		}

		cmd = c.osPath + " " + elfFilename + " >> " + listFile
		_, err = util.ShellCommand(cmd)
		if err != nil {
			return err
		}
	}

	return 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 findProjectDir(dir string) (string, error) {
	for {
		projFile := path.Clean(dir) + "/" + PROJECT_FILE_NAME

		log.Debugf("Searching for project file %s", projFile)
		if util.NodeExist(projFile) {
			break
		}

		// Move back one directory and continue searching
		dir = path.Clean(dir + "../../")
		if dir == "/" {
			return "", util.NewNewtError("No project file found!")
		}
	}

	return dir, nil
}
func (pw *PackageWriter) ConfigurePackage(template string, loc string) error {
	str, ok := TemplateRepoMap[template]
	if !ok {
		return util.NewNewtError(fmt.Sprintf("Cannot find matching "+
			"repository for template %s", template))
	}
	pw.repo = str

	pw.fullName = path.Clean(loc)
	path := pw.project.Path()
	path = path + "/" + pw.fullName

	if util.NodeExist(path) {
		return util.NewNewtError(fmt.Sprintf("Cannot place a new package in "+
			"%s, path already exists.", path))
	}

	pw.template = template
	pw.targetPath = path

	return nil
}
func newRunCmd(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		NewtUsage(cmd, util.NewNewtError("Must specify "+
			"a project directory to newt new"))
	}

	newDir := args[0]

	if util.NodeExist(newDir) {
		NewtUsage(cmd, util.NewNewtError("Cannot create new project, "+
			"directory already exists"))
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Downloading "+
		"project skeleton from apache/incubator-mynewt-blinky...\n")
	dl := downloader.NewGithubDownloader()
	dl.User = "******"
	dl.Repo = "incubator-mynewt-blinky"

	dir, err := dl.DownloadRepo(newtutil.NewtBlinkyTag)
	if err != nil {
		NewtUsage(cmd, err)
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Installing "+
		"skeleton in %s...\n", newDir)

	if err := util.CopyDir(dir, newDir); err != nil {
		NewtUsage(cmd, err)
	}

	if err := os.RemoveAll(newDir + "/" + "/.git/"); err != nil {
		NewtUsage(cmd, err)
	}

	util.StatusMessage(util.VERBOSITY_DEFAULT,
		"Project %s successfully created.\n", newDir)
}
Beispiel #8
0
// Recursively compiles all the .c and .s files in the specified directory.
// Architecture-specific files are also compiled.
func buildDir(srcDir string, c *toolchain.Compiler, arch string,
	ignDirs []string) error {

	// Quietly succeed if the source directory doesn't exist.
	if util.NodeNotExist(srcDir) {
		return nil
	}

	util.StatusMessage(util.VERBOSITY_VERBOSE,
		"Compiling src in base directory: %s\n", srcDir)

	// Start from the source directory.
	if err := os.Chdir(srcDir); err != nil {
		return util.NewNewtError(err.Error())
	}

	// Ignore architecture-specific source files for now.  Use a temporary
	// string slice here so that the "arch" directory is not ignored in the
	// subsequent architecture-specific compile phase.
	if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_C,
		append(ignDirs, "arch")); err != nil {

		return err
	}

	// Compile CPP files
	if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_CPP,
		append(ignDirs, "arch")); err != nil {
		return err
	}

	// Copy in pre-compiled library files
	if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ARCHIVE,
		append(ignDirs, "arch")); err != nil {
		return err
	}

	archDir := srcDir + "/arch/" + arch + "/"
	if util.NodeExist(archDir) {
		util.StatusMessage(util.VERBOSITY_VERBOSE,
			"Compiling architecture specific src pkgs in directory: %s\n",
			archDir)
		if err := os.Chdir(archDir); err != nil {
			return util.NewNewtError(err.Error())
		}

		// Compile C source.
		if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_C,
			ignDirs); err != nil {

			return err
		}

		// Compile CPP source
		if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_CPP,
			ignDirs); err != nil {
			return err
		}

		// Compile assembly source (only architecture-specific).
		if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ASM,
			ignDirs); err != nil {

			return err
		}

		// Copy in pre-compiled library files
		if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ARCHIVE,
			ignDirs); err != nil {
			return err
		}
	}

	return nil
}