Пример #1
0
func SbuildCommand(
	chroot,
	suite,
	arch,
	dscFile,
	repoRoot string,
	verbose bool,
) (*exec.Cmd, error) {
	repreproRepo := reprepro.NewRepo(repoRoot)
	config, err := repo.LoadConfig(repreproRepo.Basedir)
	if err != nil {
		return nil, err
	}

	suiteConfig, err := repo.LoadDistributions(repreproRepo.Basedir)
	if err != nil {
		return nil, err
	}

	distConfig, err := config.GetDistConfig(suite)
	if err != nil {
		return nil, err
	}

	suiteDistConfig, err := suiteConfig.GetDistConfig(suite)
	if err != nil {
		return nil, err
	}

	build := sbuild.NewSbuild(suite, suite)

	if verbose {
		build.Verbose()
	}

	if arch == config.Global.ArchIndepBuildArch {
		build.AddFlag("--arch-all")
	} else {
		build.AddFlag("--no-arch-all")
	}

	// build.AddArgument("build-dep-resolver", "aptitude")
	build.AddArgument("chroot-setup-commands",
		fmt.Sprintf("apt-key add /schroot/%s.asc", suiteDistConfig.SignWith))

	build.AddArgument("extra-repository",
		fmt.Sprintf("deb %s %s main",
			config.Global.PublicArchiveRoot,
			distConfig.Upstream.Dist))

	cmd, err := build.BuildCommand(dscFile)

	if verbose {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
	}
	return cmd, err
}
Пример #2
0
func (m *MinionRemote) Build(i Build, ftbfs *bool) error {
	chrootArch := "amd64" // XXX: FIX THIS LIKE SO HARD

	dsc, err := ParseDscURL(i.DSC)
	if err != nil {
		return err
	}

	cleanup, workdir, err := Tempdir()
	if err != nil {
		return err
	}
	// defer cleanup()
	log.Printf("%s\n", workdir, cleanup)

	/* We're in a tempdir, let's make it dirty */

	build := sbuild.NewSbuild(i.Chroot.Chroot, i.Chroot.Target)

	if i.Arch == "all" {
		build.Arch(chrootArch)
		build.AddFlag("--arch-all-only")
	} else {
		build.Arch(i.Arch)
	}
	build.BuildDepResolver("aptitude")

	buildVersion := dsc.Version

	if i.BinNMU.Version != "" {
		build.AddArgument("uploader", "Foo Bar <*****@*****.**>")
		build.AddArgument("maintainer", "Foo Bar <*****@*****.**>")
		build.AddArgument("make-binNMU", i.BinNMU.Changelog)
		build.AddArgument("binNMU", i.BinNMU.Version)

		/* In addition, let's fix buildVersion up */
		a := func(orig, v string) string {
			return fmt.Sprintf("%s+b%s", orig, v)
		}

		if buildVersion.IsNative() {
			buildVersion.Version = a(buildVersion.Version, i.BinNMU.Version)
		} else {
			buildVersion.Revision = a(buildVersion.Revision, i.BinNMU.Version)
		}
	}

	for _, archive := range i.Archives {
		if archive.Key != "" {
			cleanup, archiveKey, err := Download(archive.Key)
			if err != nil {
				return err
			}
			defer cleanup()
			build.AddArgument("extra-repository-key", archiveKey)
		}

		build.AddArgument("extra-repository", fmt.Sprintf(
			"deb %s %s %s",
			archive.Root,
			archive.Suite,
			strings.Join(archive.Sections, " "),
		))
	}

	build.Verbose()
	cmd, err := build.BuildCommand(i.DSC)
	attachToStdout(cmd)

	if err != nil {
		return err
	}
	log.Printf("Doing a build for %s -- waiting\n", i)

	// if i.Arch != chrootArch {
	//	/* Rename */
	// }

	changesFile := Filename(dsc.Source, buildVersion, i.Arch, "changes")
	logFile := Filename(dsc.Source, buildVersion, i.Arch, "build")

	err = cmd.Run()

	if i.Arch == "all" {
		/* We have to play fixup here */
		wrongChanges := Filename(dsc.Source, buildVersion, chrootArch, "changes")
		if _, err := os.Stat(wrongChanges); os.IsExist(err) {
			if err := os.Rename(
				wrongChanges,
				changesFile,
			); err != nil {
				return err
			}
		}

		if err := os.Rename(
			Filename(dsc.Source, buildVersion, chrootArch, "build"),
			logFile,
		); err != nil {
			return err
		}
	}
	if err != nil {
		changes, err := LogChangesFromDsc(logFile, *dsc, i.Chroot.Target, i.Arch)
		if err != nil {
			return err
		}
		fd, err := os.Create(changesFile)
		if err != nil {
			return err
		}
		defer fd.Close()
		_, err = fd.Write([]byte(changes))
		if err != nil {
			return err
		}
		err = UploadChanges(m.Config, i, changesFile)
		*ftbfs = true
		return err
	}

	/* Right, so we've got a complete upload, let's go ahead and dput
	 * this sucka. */
	log.Printf("Complete. Doing upload now")

	AppendLogToChanges(logFile, changesFile, i.Arch)

	log.Printf("Uploading: %s\n", changesFile)
	err = UploadChanges(m.Config, i, changesFile)
	log.Printf("Uploaded.")
	return err
}