Exemplo n.º 1
0
func (gd *GithubDownloader) DownloadRepo(commit string) (string, error) {
	// Get a temporary directory, and copy the repository into that directory.
	tmpdir, err := ioutil.TempDir("", "newt-repo")
	if err != nil {
		return "", err
	}

	// Currently only the master branch is supported.
	branch := "master"

	url := fmt.Sprintf("https://github.com/%s/%s.git", gd.User, gd.Repo)
	util.StatusMessage(util.VERBOSITY_VERBOSE, "Downloading "+
		"repository %s (branch: %s; commit: %s) at %s\n", gd.Repo, branch,
		commit, url)

	gitPath, err := exec.LookPath("git")
	if err != nil {
		os.RemoveAll(tmpdir)
		return "", util.NewNewtError(fmt.Sprintf("Can't find git binary: %s\n",
			err.Error()))
	}

	// Clone the repository.
	cmds := []string{
		gitPath,
		"clone",
		"-b",
		branch,
		url,
		tmpdir,
	}

	if util.Verbosity >= util.VERBOSITY_VERBOSE {
		if err := util.ShellInteractiveCommand(cmds, nil); err != nil {
			os.RemoveAll(tmpdir)
			return "", err
		}
	} else {
		if _, err := util.ShellCommand(strings.Join(cmds, " ")); err != nil {
			return "", err
		}
	}

	// Checkout the specified commit.
	if err := checkout(tmpdir, commit); err != nil {
		return "", err
	}

	return tmpdir, nil
}
Exemplo n.º 2
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)
}