yay/install.go
morganamilo 3275f8d8ac
New install algorithm
I have replaced the old install and dependancy algorithms with a new
design that attemps to be more pacaur like. Mostly in minimizing user
input. Ask every thing first then do everything with no need for more
user input.

It is not yet fully complete but is finished enough so that it works,
should not fail in most cases and provides a base for more contributors
to help address the existing problems.

The new install chain is as follows:
	Source info about the provided targets
	Fetch a list of all dependancies needed to install targets
		I put alot of effort into fetching the dependancy tree
		while making the least amount of aur requests as
		possible. I'm actually very happy with how it turned out
		and yay wil now resolve dependancies noticably faster
		than pacaur when there are many aur dependancies.
	Install repo targets by passing to pacman
	Print dependancy tree and ask to confirm
	Ask to clean build if directory already exists
	Download all pkgbuilds
	Ask to edit all pkgbuilds
	Ask to continue with the install
	Download the sources for each packagebuild
	Build and install every package
		using -s to get repo deps and -i to install
	Ask to remove make dependancies

There are still a lot of things that need to be done for a fully working
system. Here are the problems I found with this system, either new or
existing:
	Formating
		I am not so good at formatting myself, I thought best to
		leave it until last so I could get feedback on how it
		should look and help implementing it.
	Dependancy tree
		The dependancy tree is usually correct although I have
		noticed times where it doesnt detect all the
		dependancies that it should. I have only noticed this
		when there are circular dependancies so i think this
		might be the cause. It's not a big deal currently
		because makepkg -i installed repo deps for us which
		handles the repo deps for us and will get the correct
		ones. So yay might not list all the dependancies. but
		they will get installed so I consider this a visual bug.
		I have yet to see any circular dependancies in the AUR
		so I can not say what will happend but I#m guessing that
		it will break.
	Versioned packages/dependencies
		Targets and dependancies with version constriants such
		as 'linux>=4.1' will not be checked on the aur side of
		things but will be checked on the repo side.
	Ignorepkg/Ignoregroup
		Currently I do not handle this in any way but it
		shouldn't be too hard to implement.
	Conflict checking
		This is not currently implemented either
	Split Paclages
		Split packages are not Handles properly. If we only
		specify one package so install from a split package
		makepkg -i ends up installing them all anyway. If we
		specify more than one (n) package it will actually build the
		package base n times and reinstall every split package
		n times.
	Makepkg
		To get things working I decided to keep using the
		makepkg -i method. I plan to eventually replace this
		with a pacman -U based method. This should allow passing
		args such as --dbpath and --config to aur packages
		aswell as help solve some problems such as the split
		packages.
	Clean build
		I plan to improve the clean build choice to be a little
		more smart and instead of check if the directory exists,
		check if the package is already build and if so skip the
		build all together.
2018-01-20 10:00:12 +00:00

254 lines
5.1 KiB
Go

package main
import (
"fmt"
"os"
"os/exec"
"strconv"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
alpm "github.com/jguer/go-alpm"
)
// Install handles package installs
func install(parser *arguments) error {
aurs, repos, missing, err := packageSlices(parser.targets.toSlice())
if err != nil {
return err
}
if len(missing) > 0 {
fmt.Println(missing)
return fmt.Errorf("Could not find all Targets")
}
arguments := parser.copy()
arguments.delArg("u", "sysupgrade")
arguments.delArg("y", "refresh")
arguments.targets = make(stringSet)
arguments.addTarget(repos...)
if len(repos) != 0 {
err := passToPacman(arguments)
if err != nil {
fmt.Println("Error installing repo packages.")
}
}
if len(aurs) != 0 {
//todo make pretty
fmt.Println("Resolving Dependencies")
dt, err := getDepTree(aurs)
if err != nil {
return err
}
if len(dt.Missing) > 0 {
fmt.Println(dt.Missing)
return fmt.Errorf("Could not find all Deps")
}
dc, err := getDepCatagories(aurs, dt)
if err != nil {
return err
}
for _, pkg := range dc.AurMake {
if pkg.Maintainer == "" {
fmt.Printf("\x1b[1;31;40m==> Warning:\x1b[0;;40m %s is orphaned.\x1b[0m\n", pkg.Name + "-" + pkg.Version)
}
}
for _, pkg := range dc.Aur {
if pkg.Maintainer == "" {
fmt.Printf("\x1b[1;31;40m==> Warning:\x1b[0;;40m %s is orphaned.\x1b[0m\n", pkg.Name + "-" + pkg.Version)
}
}
fmt.Println()
p1 := func(a []*alpm.Package) {
for _, v := range a {
fmt.Print(" ", v.Name())
}
}
p2 := func(a []*rpc.Pkg) {
for _, v := range a {
fmt.Print(" ", v.Name)
}
}
fmt.Print("Repo (" + strconv.Itoa(len(dc.Repo)) + "):")
p1(dc.Repo)
fmt.Println()
fmt.Print("Repo Make (" + strconv.Itoa(len(dc.RepoMake)) + "):")
p1(dc.RepoMake)
fmt.Println()
fmt.Print("Aur (" + strconv.Itoa(len(dc.Aur)) + "):")
p2(dc.Aur)
fmt.Println()
fmt.Print("Aur Make (" + strconv.Itoa(len(dc.AurMake)) + "):")
p2(dc.AurMake)
fmt.Println()
fmt.Println()
askCleanBuilds(dc.AurMake)
askCleanBuilds(dc.Aur)
fmt.Println()
if !continueTask("Proceed with download?", "nN") {
return fmt.Errorf("Aborting due to user")
}
err = dowloadPkgBuilds(dc.AurMake)
if err != nil {
return err
}
err = dowloadPkgBuilds(dc.Aur)
if err != nil {
return err
}
askEditPkgBuilds(dc.AurMake)
askEditPkgBuilds(dc.Aur)
if !continueTask("Proceed with install?", "nN") {
return fmt.Errorf("Aborting due to user")
}
err = downloadPkgBuildsSources(dc.AurMake)
if err != nil {
return err
}
err = downloadPkgBuildsSources(dc.Aur)
if err != nil {
return err
}
err = buildInstallPkgBuilds(dc.AurMake, parser.targets)
if err != nil {
return err
}
err = buildInstallPkgBuilds(dc.Aur, parser.targets)
if err != nil {
return err
}
if len(dc.RepoMake) + len(dc.AurMake) > 0 {
if continueTask("Remove make dependancies?", "yY") {
return nil
}
removeArguments := makeArguments()
removeArguments.addArg("R")
for _, pkg := range dc.RepoMake {
removeArguments.addTarget(pkg.Name())
}
for _, pkg := range dc.AurMake {
removeArguments.addTarget(pkg.Name)
}
passToPacman(removeArguments)
}
return nil
}
return nil
}
func askCleanBuilds(pkgs []*rpc.Pkg) {
for _, pkg := range pkgs {
dir := config.BuildDir + pkg.PackageBase + "/"
if _, err := os.Stat(dir); !os.IsNotExist(err) {
if !continueTask(pkg.Name + " Directory exists. Clean Build?", "yY") {
_ = os.RemoveAll(config.BuildDir + pkg.PackageBase)
}
}
}
}
func askEditPkgBuilds(pkgs []*rpc.Pkg) {
for _, pkg := range pkgs {
dir := config.BuildDir + pkg.PackageBase + "/"
if !continueTask(pkg.Name + " Edit PKGBUILD?", "yY") {
editcmd := exec.Command(editor(), dir+"PKGBUILD")
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
editcmd.Run()
}
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
if err == nil {
for _, pkgsource := range pkgbuild.Source {
owner, repo := parseSource(pkgsource)
if owner != "" && repo != "" {
err = branchInfo(pkg.Name, owner, repo)
if err != nil {
fmt.Println(err)
}
}
}
}
}
}
func dowloadPkgBuilds(pkgs []*rpc.Pkg) (err error) {
for _, pkg := range pkgs {
//todo make pretty
fmt.Println("Downloading:", pkg.Name + "-" + pkg.Version)
err = downloadAndUnpack(baseURL + pkg.URLPath, config.BuildDir, false)
if err != nil{
return
}
}
return
}
func downloadPkgBuildsSources(pkgs []*rpc.Pkg) (err error) {
for _, pkg := range pkgs {
dir := config.BuildDir + pkg.PackageBase + "/"
err = passToMakepkg(dir, "-f", "--verifysource")
if err != nil {
return
}
}
return
}
func buildInstallPkgBuilds(pkgs []*rpc.Pkg, targets stringSet) (err error) {
//for n := len(pkgs) -1 ; n > 0; n-- {
for n := 0; n < len(pkgs); n++ {
pkg := pkgs[n]
dir := config.BuildDir + pkg.PackageBase + "/"
if targets.get(pkg.Name) {
err = passToMakepkg(dir, "-Cscfi", "--noconfirm")
} else {
err = passToMakepkg(dir, "-Cscfi", "--noconfirm", "--asdeps")
}
if err != nil {
return
}
}
return
}