Skip to content

Commit

Permalink
Make it possible for RPMRule.SetURLs() to fail
Browse files Browse the repository at this point in the history
This can't happen at the moment, but we're about to introduce
a possible failure state.

Signed-off-by: Andrea Bolognani <[email protected]>
  • Loading branch information
andreabolognani committed Feb 28, 2023
1 parent 32db3ee commit 5dd53c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/rpmtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func NewRpmTreeCmd() *cobra.Command {
if err != nil {
return err
}
bazel.AddRPMs(workspace, install, rpmtreeopts.arch)
err = bazel.AddRPMs(workspace, install, rpmtreeopts.arch)
if err != nil {
return err
}
bazel.AddTree(rpmtreeopts.name, build, install, rpmtreeopts.arch, rpmtreeopts.public)
bazel.PruneRPMs(build, workspace)
logrus.Info("Writing bazel files.")
Expand Down
12 changes: 9 additions & 3 deletions pkg/bazel/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func GetRPMs(workspace *build.File) (rpms []*RPMRule) {
return
}

func AddRPMs(workspace *build.File, pkgs []*api.Package, arch string) {
func AddRPMs(workspace *build.File, pkgs []*api.Package, arch string) error {

rpms := map[string]*RPMRule{}

Expand All @@ -83,7 +83,10 @@ func AddRPMs(workspace *build.File, pkgs []*api.Package, arch string) {
rule.SetSHA256(pkg.Checksum.Text)
urls := rule.URLs()
if len(urls) == 0 {
rule.SetURLs(pkg.Repository.Mirrors, pkg.Location.Href)
err := rule.SetURLs(pkg.Repository.Mirrors, pkg.Location.Href)
if err != nil {
return err
}
}
}

Expand All @@ -100,6 +103,8 @@ func AddRPMs(workspace *build.File, pkgs []*api.Package, arch string) {
for _, rule := range rules {
workspace.Stmt = edit.InsertAtEnd(workspace.Stmt, rule.Call)
}

return nil
}

func AddTar2Files(name string, rpmtree string, buildfile *build.File, files []string, public bool) {
Expand Down Expand Up @@ -231,13 +236,14 @@ func (r *RPMRule) URLs() []string {
return nil
}

func (r *RPMRule) SetURLs(urls []string, href string) {
func (r *RPMRule) SetURLs(urls []string, href string) error {
urlsAttr := []build.Expr{}
for _, url := range urls {
u := strings.TrimSuffix(url, "/") + "/" + strings.TrimSuffix(href, "/")
urlsAttr = append(urlsAttr, &build.StringExpr{Value: u})
}
r.Rule.SetAttr("urls", &build.ListExpr{List: urlsAttr})
return nil
}

func (r *RPMRule) SetName(name string) {
Expand Down

0 comments on commit 5dd53c1

Please sign in to comment.