From 70a450e36a7f20e31d48f287d4280119ec31b4e9 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Fri, 20 Nov 2020 10:04:55 +0100 Subject: [PATCH] Add prune command and update README Signed-off-by: Roman Mohr --- README.md | 15 ++++++++------- cmd/BUILD.bazel | 1 + cmd/prune.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ cmd/resolve.go | 28 ---------------------------- cmd/root.go | 1 + cmd/rpmtree.go | 3 +-- 6 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 cmd/prune.go diff --git a/README.md b/README.md index 6ad6206..4406aad 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ rpmtree( "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", ], - include_dir = "/usr/include", - lib_dir = "/usr/lib64", ) ``` @@ -52,17 +50,20 @@ container_layer( ## Libraries and Headers +**Not yet implemented!** + `rpmtree` can also be used to satisvy C and C++ dependencies like this: ```python cc_library( name = "rpmlibs", srcs = [ - ":rpmarchive/libs.tar", + ":rpmarchive/usr/lib64", ], hdrs = [ - ":rpmarchive/hdrs.tar", + ":rpmarchive/usr/include/libvirt", ], + prefix= "libvirt", ) ``` @@ -91,19 +92,19 @@ bazeldnf init --fc 32 # write a repo.yaml file containing the usual release and Then write a `rpmtree` rule called `libvirttree` to your BUILD file and all corresponding RPM dependencies into your WORKSPACE for libvirt: ```bash -bazeldnf resolve --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --rpmtree libvirttree libvirt +bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name libvirttree libvirt ``` Do the same for bash with a `bashrpmtree` target: ```bash -bazeldnf resolve --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --rpmtree bashtree bash +bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name bashtree bash ``` Finally prune all unreferenced old RPM files: ```bash -bazeldnf prune --workspace /my/WORKSPACE +bazeldnf prune --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel ``` ### Dependency resolution limitations diff --git a/cmd/BUILD.bazel b/cmd/BUILD.bazel index 6f70028..33ddab7 100644 --- a/cmd/BUILD.bazel +++ b/cmd/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "bazeldnf.go", "fetch.go", "init.go", + "prune.go", "reduce.go", "resolve.go", "root.go", diff --git a/cmd/prune.go b/cmd/prune.go new file mode 100644 index 0000000..3df863a --- /dev/null +++ b/cmd/prune.go @@ -0,0 +1,48 @@ +package main + +import ( + "github.com/rmohr/bazeldnf/pkg/bazel" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +type pruneOpts struct { + workspace string + buildfile string +} + +var pruneopts = pruneOpts{} + +func NewpruneCmd() *cobra.Command { + + pruneCmd := &cobra.Command{ + Use: "prune", + Short: "prunes unused RPM dependencies", + RunE: func(cmd *cobra.Command, required []string) error { + workspace, err := bazel.LoadWorkspace(pruneopts.workspace) + if err != nil { + return err + } + build, err := bazel.LoadBuild(pruneopts.buildfile) + if err != nil { + return err + } + bazel.PruneRPMs(build, workspace) + err = bazel.WriteWorkspace(false, workspace, pruneopts.workspace) + if err != nil { + return err + } + err = bazel.WriteBuild(false, build, pruneopts.buildfile) + if err != nil { + return err + } + logrus.Info("Done.") + return nil + }, + } + + pruneCmd.PersistentFlags().StringVarP(&pruneopts.workspace, "workspace", "w", "WORKSPACE", "Bazel workspace file") + pruneCmd.PersistentFlags().StringVarP(&pruneopts.buildfile, "buildfile", "b", "rpm/BUILD.bazel", "Build file for RPMs") + pruneCmd.MarkFlagRequired("name") + return pruneCmd +} diff --git a/cmd/resolve.go b/cmd/resolve.go index 4cb65ca..3881bc6 100644 --- a/cmd/resolve.go +++ b/cmd/resolve.go @@ -2,10 +2,7 @@ package main import ( "fmt" - "path/filepath" - "strings" - "github.com/rmohr/bazeldnf/pkg/api" "github.com/rmohr/bazeldnf/pkg/api/bazeldnf" "github.com/rmohr/bazeldnf/pkg/reducer" "github.com/rmohr/bazeldnf/pkg/repo" @@ -41,7 +38,6 @@ func NewResolveCmd() *cobra.Command { return err } } - helper := repo.CacheHelper{CacheDir: ".bazeldnf"} repo := reducer.NewRepoReducer(repos, resolveopts.in, resolveopts.lang, resolveopts.fedoraBaseSystem, resolveopts.arch, ".bazeldnf") logrus.Info("Loading packages.") if err := repo.Load(); err != nil { @@ -71,30 +67,6 @@ func NewResolveCmd() *cobra.Command { fmt.Println(install) fmt.Println(len(install)) logrus.Info("Done.") - remaining := install - hdrs := map[string]string{} - libs := map[string]string{} - for _, r := range repos.Repositories { - found := []*api.FileListPackage{} - found, remaining, err = helper.CurrentFilelistsForPackages(&r, remaining) - if err != nil { - return err - } - for _, pkg := range found { - for _, file := range pkg.File { - if file.Type != "dir" { - if strings.HasPrefix(file.Text, "/usr/include") { - hdrs[file.Text] = filepath.Dir(file.Text) - } - if strings.HasPrefix(file.Text, "/usr/lib64") { - libs[file.Text] = filepath.Dir(file.Text) - } - } - } - } - } - fmt.Println(hdrs) - fmt.Println(libs) return nil }, } diff --git a/cmd/root.go b/cmd/root.go index d98fa7a..4a0d8f0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,6 +22,7 @@ func Execute() { rootCmd.AddCommand(NewResolveCmd()) rootCmd.AddCommand(NewReduceCmd()) rootCmd.AddCommand(NewRPMCmd()) + rootCmd.AddCommand(NewpruneCmd()) if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) diff --git a/cmd/rpmtree.go b/cmd/rpmtree.go index fdd1c02..6e71e9c 100644 --- a/cmd/rpmtree.go +++ b/cmd/rpmtree.go @@ -26,8 +26,7 @@ func NewrpmtreeCmd() *cobra.Command { rpmtreeCmd := &cobra.Command{ Use: "rpmtree", - Short: "rpmtrees depencencies of the given packages", - Long: `rpmtrees dependencies of the given packages with the assumption of a SCRATCH container as install target`, + Short: "Writes a rpmtree rule and its rpmdependencies to bazel files", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, required []string) error { repos, err := repo.LoadRepoFile(reduceopts.repofile)