2017-08-02 19:24:03 +02:00
|
|
|
package main
|
2017-05-01 03:23:03 +02:00
|
|
|
|
2017-05-01 03:34:40 +02:00
|
|
|
import (
|
2021-08-12 18:56:23 +02:00
|
|
|
"context"
|
2022-11-20 03:47:23 +01:00
|
|
|
"path/filepath"
|
2021-08-02 21:56:19 +02:00
|
|
|
"strings"
|
2018-08-03 00:30:48 +02:00
|
|
|
"sync"
|
2018-03-22 19:23:20 +01:00
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-05-02 16:17:20 +02:00
|
|
|
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/dep"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/download"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/query"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
2023-01-23 22:43:58 +01:00
|
|
|
"github.com/Jguer/yay/v11/pkg/srcinfo"
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/text"
|
2017-05-01 03:34:40 +02:00
|
|
|
)
|
2017-05-01 03:23:03 +02:00
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
// createDevelDB forces yay to create a DB of the existing development packages.
|
2021-08-12 18:56:23 +02:00
|
|
|
func createDevelDB(ctx context.Context, config *settings.Configuration, dbExecutor db.Executor) error {
|
2022-11-20 01:51:55 +01:00
|
|
|
remoteNames := dbExecutor.InstalledRemotePackageNames()
|
2021-08-12 18:56:23 +02:00
|
|
|
info, err := query.AURInfoPrint(ctx, config.Runtime.AURClient, remoteNames, config.RequestSplitN)
|
2018-03-22 19:23:20 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-25 23:31:20 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
bases := dep.GetBases(info)
|
2019-10-16 23:58:55 +02:00
|
|
|
toSkip := pkgbuildsToSkip(bases, stringset.FromSlice(remoteNames))
|
2021-08-02 21:56:19 +02:00
|
|
|
|
|
|
|
targets := make([]string, 0, len(bases))
|
2022-11-20 03:47:23 +01:00
|
|
|
pkgBuildDirsByBase := make(map[string]string, len(bases))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-02 21:56:19 +02:00
|
|
|
for _, base := range bases {
|
|
|
|
if !toSkip.Get(base.Pkgbase()) {
|
|
|
|
targets = append(targets, base.Pkgbase())
|
|
|
|
}
|
2022-11-20 03:47:23 +01:00
|
|
|
|
|
|
|
pkgBuildDirsByBase[base.Pkgbase()] = filepath.Join(config.BuildDir, base.Pkgbase())
|
2021-08-02 21:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
toSkipSlice := toSkip.ToSlice()
|
|
|
|
if len(toSkipSlice) != 0 {
|
|
|
|
text.OperationInfoln(
|
|
|
|
gotext.Get("PKGBUILD up to date, Skipping (%d/%d): %s",
|
|
|
|
len(toSkipSlice), len(bases), text.Cyan(strings.Join(toSkipSlice, ", "))))
|
|
|
|
}
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
if _, errA := download.AURPKGBUILDRepos(ctx,
|
2021-08-02 21:56:19 +02:00
|
|
|
config.Runtime.CmdBuilder, targets, config.AURURL, config.BuildDir, false); errA != nil {
|
2019-10-13 13:15:51 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-01-23 22:43:58 +01:00
|
|
|
srcinfos, err := srcinfo.ParseSrcinfoFilesByBase(pkgBuildDirsByBase, false)
|
2019-10-13 13:15:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-22 19:23:20 +01:00
|
|
|
|
2022-12-18 17:37:15 +01:00
|
|
|
var wg sync.WaitGroup
|
2020-05-02 16:17:20 +02:00
|
|
|
for i := range srcinfos {
|
|
|
|
for iP := range srcinfos[i].Packages {
|
2018-08-03 00:30:48 +02:00
|
|
|
wg.Add(1)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2022-12-18 17:37:15 +01:00
|
|
|
go func(i string, iP int) {
|
|
|
|
config.Runtime.VCSStore.Update(ctx, srcinfos[i].Packages[iP].Pkgname, srcinfos[i].Source)
|
|
|
|
wg.Done()
|
|
|
|
}(i, iP)
|
2018-03-22 19:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:30:48 +02:00
|
|
|
wg.Wait()
|
2020-05-04 09:24:32 +02:00
|
|
|
text.OperationInfoln(gotext.Get("GenDB finished. No packages were installed"))
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
return err
|
2017-05-01 03:23:03 +02:00
|
|
|
}
|