Skip to content

Commit

Permalink
Merge pull request #22 from brian-bice/fix-go-rule-deps-management-wh…
Browse files Browse the repository at this point in the history
…en-rule-requires-no-deps

Fix go rule deps management when rule requires no deps
  • Loading branch information
brian-bice authored Apr 6, 2021
2 parents 873431d + 88a1fe7 commit 4266e0d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions domain/wollemi/service_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ func (this *Service) formatDirectory(log logging.Logger, dir *Directory) {

if len(resolved) > 0 {
rule.SetAttr("deps", please.Strings(resolved...))
} else {
rule.DelAttr("deps")
}
})

Expand Down
47 changes: 47 additions & 0 deletions domain/wollemi/service_format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,53 @@ func (t *ServiceSuite) TestService_GoFormat() {
},
},
},
}, { // TEST_CASE ------------------------------------------------------------
Title: "deletes go rule deps attribute when no dependencies required",
Data: &GoFormatTestData{
Gosrc: gosrc,
Gopkg: gopkg,
Paths: []string{"app/server"},
Parse: t.WithThirdPartyGoModules(map[string]*please.BuildFile{
"app/server/BUILD.plz": &please.BuildFile{
Stmt: []please.Expr{
please.NewCallExpr("go_library", []please.Expr{
please.NewAssignExpr("=", "name", "server"),
please.NewAssignExpr("=", "srcs", []string{"server.go"}),
please.NewAssignExpr("=", "visibility", []string{"PUBLIC"}),
please.NewAssignExpr("=", "deps", []string{
"//app/protos",
"//third_party/go/github.com/golang:protobuf",
"//third_party/go/google.golang.org:grpc",
}),
}),
},
},
}),
ImportDir: map[string]*golang.Package{
"app/server": &golang.Package{
GoFiles: []string{"server.go"},
GoFileImports: map[string][]string{
"server.go": []string{
"database/sql",
"encoding/json",
"strconv",
"strings",
},
},
},
},
Write: map[string]*please.BuildFile{
"app/server/BUILD.plz": &please.BuildFile{
Stmt: []please.Expr{
please.NewCallExpr("go_library", []please.Expr{
please.NewAssignExpr("=", "name", "server"),
please.NewAssignExpr("=", "srcs", []string{"server.go"}),
please.NewAssignExpr("=", "visibility", []string{"PUBLIC"}),
}),
},
},
},
},
}} {
focus := ""

Expand Down

0 comments on commit 4266e0d

Please sign in to comment.