Skip to content

Commit 70a450e

Browse files
committed
Add prune command and update README
Signed-off-by: Roman Mohr <[email protected]>
1 parent c6d3007 commit 70a450e

File tree

6 files changed

+59
-37
lines changed

6 files changed

+59
-37
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ rpmtree(
3333
"@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm",
3434
"@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm",
3535
],
36-
include_dir = "/usr/include",
37-
lib_dir = "/usr/lib64",
3836
)
3937
```
4038

@@ -52,17 +50,20 @@ container_layer(
5250

5351
## Libraries and Headers
5452

53+
**Not yet implemented!**
54+
5555
`rpmtree` can also be used to satisvy C and C++ dependencies like this:
5656

5757
```python
5858
cc_library(
5959
name = "rpmlibs",
6060
srcs = [
61-
":rpmarchive/libs.tar",
61+
":rpmarchive/usr/lib64",
6262
],
6363
hdrs = [
64-
":rpmarchive/hdrs.tar",
64+
":rpmarchive/usr/include/libvirt",
6565
],
66+
prefix= "libvirt",
6667
)
6768
```
6869

@@ -91,19 +92,19 @@ bazeldnf init --fc 32 # write a repo.yaml file containing the usual release and
9192
Then write a `rpmtree` rule called `libvirttree` to your BUILD file and all
9293
corresponding RPM dependencies into your WORKSPACE for libvirt:
9394
```bash
94-
bazeldnf resolve --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --rpmtree libvirttree libvirt
95+
bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name libvirttree libvirt
9596
```
9697

9798
Do the same for bash with a `bashrpmtree` target:
9899

99100
```bash
100-
bazeldnf resolve --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --rpmtree bashtree bash
101+
bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name bashtree bash
101102
```
102103

103104
Finally prune all unreferenced old RPM files:
104105

105106
```bash
106-
bazeldnf prune --workspace /my/WORKSPACE
107+
bazeldnf prune --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel
107108
```
108109

109110
### Dependency resolution limitations

cmd/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go_library(
66
"bazeldnf.go",
77
"fetch.go",
88
"init.go",
9+
"prune.go",
910
"reduce.go",
1011
"resolve.go",
1112
"root.go",

cmd/prune.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"github.com/rmohr/bazeldnf/pkg/bazel"
5+
"github.com/sirupsen/logrus"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
type pruneOpts struct {
10+
workspace string
11+
buildfile string
12+
}
13+
14+
var pruneopts = pruneOpts{}
15+
16+
func NewpruneCmd() *cobra.Command {
17+
18+
pruneCmd := &cobra.Command{
19+
Use: "prune",
20+
Short: "prunes unused RPM dependencies",
21+
RunE: func(cmd *cobra.Command, required []string) error {
22+
workspace, err := bazel.LoadWorkspace(pruneopts.workspace)
23+
if err != nil {
24+
return err
25+
}
26+
build, err := bazel.LoadBuild(pruneopts.buildfile)
27+
if err != nil {
28+
return err
29+
}
30+
bazel.PruneRPMs(build, workspace)
31+
err = bazel.WriteWorkspace(false, workspace, pruneopts.workspace)
32+
if err != nil {
33+
return err
34+
}
35+
err = bazel.WriteBuild(false, build, pruneopts.buildfile)
36+
if err != nil {
37+
return err
38+
}
39+
logrus.Info("Done.")
40+
return nil
41+
},
42+
}
43+
44+
pruneCmd.PersistentFlags().StringVarP(&pruneopts.workspace, "workspace", "w", "WORKSPACE", "Bazel workspace file")
45+
pruneCmd.PersistentFlags().StringVarP(&pruneopts.buildfile, "buildfile", "b", "rpm/BUILD.bazel", "Build file for RPMs")
46+
pruneCmd.MarkFlagRequired("name")
47+
return pruneCmd
48+
}

cmd/resolve.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"path/filepath"
6-
"strings"
75

8-
"github.com/rmohr/bazeldnf/pkg/api"
96
"github.com/rmohr/bazeldnf/pkg/api/bazeldnf"
107
"github.com/rmohr/bazeldnf/pkg/reducer"
118
"github.com/rmohr/bazeldnf/pkg/repo"
@@ -41,7 +38,6 @@ func NewResolveCmd() *cobra.Command {
4138
return err
4239
}
4340
}
44-
helper := repo.CacheHelper{CacheDir: ".bazeldnf"}
4541
repo := reducer.NewRepoReducer(repos, resolveopts.in, resolveopts.lang, resolveopts.fedoraBaseSystem, resolveopts.arch, ".bazeldnf")
4642
logrus.Info("Loading packages.")
4743
if err := repo.Load(); err != nil {
@@ -71,30 +67,6 @@ func NewResolveCmd() *cobra.Command {
7167
fmt.Println(install)
7268
fmt.Println(len(install))
7369
logrus.Info("Done.")
74-
remaining := install
75-
hdrs := map[string]string{}
76-
libs := map[string]string{}
77-
for _, r := range repos.Repositories {
78-
found := []*api.FileListPackage{}
79-
found, remaining, err = helper.CurrentFilelistsForPackages(&r, remaining)
80-
if err != nil {
81-
return err
82-
}
83-
for _, pkg := range found {
84-
for _, file := range pkg.File {
85-
if file.Type != "dir" {
86-
if strings.HasPrefix(file.Text, "/usr/include") {
87-
hdrs[file.Text] = filepath.Dir(file.Text)
88-
}
89-
if strings.HasPrefix(file.Text, "/usr/lib64") {
90-
libs[file.Text] = filepath.Dir(file.Text)
91-
}
92-
}
93-
}
94-
}
95-
}
96-
fmt.Println(hdrs)
97-
fmt.Println(libs)
9870
return nil
9971
},
10072
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func Execute() {
2222
rootCmd.AddCommand(NewResolveCmd())
2323
rootCmd.AddCommand(NewReduceCmd())
2424
rootCmd.AddCommand(NewRPMCmd())
25+
rootCmd.AddCommand(NewpruneCmd())
2526
if err := rootCmd.Execute(); err != nil {
2627
fmt.Println(err)
2728
os.Exit(1)

cmd/rpmtree.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ func NewrpmtreeCmd() *cobra.Command {
2626

2727
rpmtreeCmd := &cobra.Command{
2828
Use: "rpmtree",
29-
Short: "rpmtrees depencencies of the given packages",
30-
Long: `rpmtrees dependencies of the given packages with the assumption of a SCRATCH container as install target`,
29+
Short: "Writes a rpmtree rule and its rpmdependencies to bazel files",
3130
Args: cobra.MinimumNArgs(1),
3231
RunE: func(cmd *cobra.Command, required []string) error {
3332
repos, err := repo.LoadRepoFile(reduceopts.repofile)

0 commit comments

Comments
 (0)