diff --git a/pkg/tree/builder.go b/pkg/tree/builder.go new file mode 100644 index 00000000..590b7e9a --- /dev/null +++ b/pkg/tree/builder.go @@ -0,0 +1,28 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package tree + +import ( + pkg "github.com/mudler/luet/pkg/package" +) + +// reads a luet tree and generates the package lists +type Builder interface { + Scan(string) error // compiles a tree + Load(string) error // pre-scanned tree + + Generate() (pkg.PackageSet, error) // generates world +} diff --git a/pkg/tree/builder/gentoo/builder_suite_test.go b/pkg/tree/builder/gentoo/builder_suite_test.go new file mode 100644 index 00000000..d2b6319b --- /dev/null +++ b/pkg/tree/builder/gentoo/builder_suite_test.go @@ -0,0 +1,28 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package gentoo_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestGentooBuilder(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Gentoo Suite") +} diff --git a/pkg/tree/builder/gentoo/gentoo.go b/pkg/tree/builder/gentoo/gentoo.go new file mode 100644 index 00000000..161462b4 --- /dev/null +++ b/pkg/tree/builder/gentoo/gentoo.go @@ -0,0 +1,71 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package gentoo + +// NOTE: Look here as an example of the builder definition executor +// https://gist.github.com/adnaan/6ca68c7985c6f851def3 + +import ( + "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 } + +type GentooTree struct{ Packages pkg.PackageSet } + +type EbuildParser interface { + ScanEbuild(path string) ([]pkg.Package, error) +} + +func (gt *GentooTree) GetPackageSet() pkg.PackageSet { + return gt.Packages +} + +func (gb *GentooBuilder) Generate(dir string) (pkg.Tree, error) { + tree := &GentooTree{Packages: pkg.NewPackages([]pkg.Package{})} + + err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + if strings.Contains(info.Name(), "ebuild") { + pkgs, err := gb.EbuildParser.ScanEbuild(path) + if err != nil { + return err + } + tree.Packages.AddPackages(pkgs) + + } + return nil + }) + if err != nil { + return tree, err + } + return tree, nil +} diff --git a/pkg/tree/builder/gentoo/gentoo_test.go b/pkg/tree/builder/gentoo/gentoo_test.go new file mode 100644 index 00000000..48571e7e --- /dev/null +++ b/pkg/tree/builder/gentoo/gentoo_test.go @@ -0,0 +1,44 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package gentoo_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + pkg "github.com/mudler/luet/pkg/package" + . "github.com/mudler/luet/pkg/tree/builder/gentoo" +) + +type FakeParser struct { +} + +func (f *FakeParser) ScanEbuild(path string) ([]pkg.Package, error) { + return []pkg.Package{&pkg.DefaultPackage{Name: "Fake"}}, nil +} + +var _ = Describe("GentooBuilder", func() { + + Context("Simple test", func() { + It("parses correctly deps", func() { + gb := NewGentooBuilder(&FakeParser{}) + tree, err := gb.Generate("../../../../tests/fixtures/overlay") + Expect(err).ToNot(HaveOccurred()) + Expect(len(tree.GetPackageSet().GetPackages())).To(Equal(11)) + }) + }) + +}) diff --git a/pkg/tree/parser.go b/pkg/tree/parser.go new file mode 100644 index 00000000..2689af1c --- /dev/null +++ b/pkg/tree/parser.go @@ -0,0 +1,23 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package tree + +import pkg "github.com/mudler/luet/pkg/package" + +// parses ebuilds (?) and generates data which is readable by the builder +type Parser interface { + Generate(string) (pkg.Tree, error) // Generate scannable luet tree (by builder) +} diff --git a/pkg/tree/tree_suite_test.go b/pkg/tree/tree_suite_test.go new file mode 100644 index 00000000..d75ebaf3 --- /dev/null +++ b/pkg/tree/tree_suite_test.go @@ -0,0 +1,28 @@ +// Copyright © 2019 Ettore Di Giacinto +// +// 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 . + +package tree_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestTree(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Tree Suite") +}