Skip to content

Commit

Permalink
Add prune command and update README
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Nov 20, 2020
1 parent c6d3007 commit 70a450e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
```

Expand All @@ -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",
)
```

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
"bazeldnf.go",
"fetch.go",
"init.go",
"prune.go",
"reduce.go",
"resolve.go",
"root.go",
Expand Down
48 changes: 48 additions & 0 deletions cmd/prune.go
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 0 additions & 28 deletions cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/rpmtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 70a450e

Please sign in to comment.