2019-07-27 11:30:44 +02:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package gentoo
|
|
|
|
|
|
|
|
// NOTE: Look here as an example of the builder definition executor
|
|
|
|
// https://gist.github.com/adnaan/6ca68c7985c6f851def3
|
|
|
|
|
|
|
|
import (
|
2019-10-28 17:12:29 +01:00
|
|
|
"io/ioutil"
|
2019-07-27 11:30:44 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
tree "github.com/mudler/luet/pkg/tree"
|
|
|
|
|
|
|
|
pkg "github.com/mudler/luet/pkg/package"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewGentooBuilder(e EbuildParser) tree.Parser {
|
|
|
|
return &GentooBuilder{EbuildParser: e}
|
|
|
|
}
|
|
|
|
|
|
|
|
type GentooBuilder struct{ EbuildParser EbuildParser }
|
|
|
|
|
2019-10-28 17:12:29 +01:00
|
|
|
type GentooTree struct {
|
2019-10-30 17:52:57 +01:00
|
|
|
*tree.DefaultTree
|
2019-10-28 17:12:29 +01:00
|
|
|
}
|
2019-07-27 11:30:44 +02:00
|
|
|
|
|
|
|
type EbuildParser interface {
|
2019-10-30 17:52:57 +01:00
|
|
|
ScanEbuild(string, pkg.Tree) ([]pkg.Package, error)
|
2019-07-27 11:30:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 17:12:29 +01:00
|
|
|
func (gt *GentooTree) Prelude() string {
|
|
|
|
return "/usr/portage/"
|
|
|
|
}
|
|
|
|
|
2019-07-27 11:30:44 +02:00
|
|
|
func (gb *GentooBuilder) Generate(dir string) (pkg.Tree, error) {
|
2019-10-28 17:12:29 +01:00
|
|
|
tmpfile, err := ioutil.TempFile("", "boltdb")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-07-27 11:30:44 +02:00
|
|
|
|
2019-10-30 17:52:57 +01:00
|
|
|
tree := &GentooTree{DefaultTree: &tree.DefaultTree{Packages: pkg.NewBoltDatabase(tmpfile.Name())}}
|
|
|
|
// TODO: Handle cleaning after? Cleanup implemented in GetPackageSet().Clean()
|
2019-10-28 17:12:29 +01:00
|
|
|
|
|
|
|
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
2019-07-27 11:30:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if strings.Contains(info.Name(), "ebuild") {
|
2019-10-30 17:52:57 +01:00
|
|
|
pkgs, err := gb.EbuildParser.ScanEbuild(path, tree)
|
2019-07-27 11:30:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-28 17:12:29 +01:00
|
|
|
for _, p := range pkgs {
|
2019-10-31 12:35:05 +01:00
|
|
|
_, err := tree.GetPackageSet().FindPackage(p)
|
2019-10-28 17:12:29 +01:00
|
|
|
if err != nil {
|
2019-10-31 12:35:05 +01:00
|
|
|
_, err := tree.GetPackageSet().CreatePackage(p)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-10-28 17:12:29 +01:00
|
|
|
}
|
2019-10-31 12:35:05 +01:00
|
|
|
|
2019-10-28 17:12:29 +01:00
|
|
|
}
|
2019-07-27 11:30:44 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return tree, err
|
|
|
|
}
|
|
|
|
return tree, nil
|
|
|
|
}
|