Skip to content

Commit 297cdac

Browse files
Propagate licences to go_repo generated targets for stamping (#365)
* Pass licences down when generating targets in go_repo The go_repo rule generates a BUILD file with a go_library per package in the repo. If the licences are not passed to go_library, targets that depend directly on thes go_repo generated go_library targets will not have licences and accepted licences when stamped. This change introduces a new `--licence` flag to `please_go generate` so it can generate build rules for module packages that contain them. * Quote licence string Co-authored-by: Chris Novakovic <[email protected]> * More descriptive description for the licence flag Co-authored-by: Chris Novakovic <[email protected]> --------- Co-authored-by: Chris Novakovic <[email protected]>
1 parent 478ec39 commit 297cdac

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

build_defs/go.build_defs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,10 @@ def go_repo(module: str, version:str='', download:str=None, name:str=None, insta
13521352
pkg_name = package_name()
13531353
requirements = " ".join(requirements)
13541354

1355+
licence_args = ""
1356+
if licences:
1357+
licence_args = " ".join([f"--licence '{licence}'" for licence in licences])
1358+
13551359
build_tag_args = " ".join([f"--build_tag {build_tag}" for build_tag in build_tags])
13561360
label_args = " ".join([f"--label '{label}'" for label in labels])
13571361
large_package_args = " ".join([f"--large_package '{pkg}'" for pkg in large_packages])
@@ -1363,7 +1367,7 @@ def go_repo(module: str, version:str='', download:str=None, name:str=None, insta
13631367
"find $SRCS_DOWNLOAD -name BUILD -delete",
13641368
f"mkdir -p $(dirname {pkgRoot})",
13651369
f"mv $SRCS_DOWNLOAD {pkgRoot}",
1366-
f"$TOOL generate {modFileArg} --module {module} --version '{version}' {build_tag_args} {label_args} {large_package_args} --src_root={pkgRoot} --third_part_folder='{third_party_path}' --subrepo '{pkg_name}/{subrepo_name}' {install_args} {requirements}",
1370+
f"$TOOL generate {modFileArg} --module {module} --version '{version}' {build_tag_args} {label_args} {large_package_args} --src_root={pkgRoot} --third_part_folder='{third_party_path}' --subrepo '{pkg_name}/{subrepo_name}' {install_args} {requirements} {licence_args}",
13671371
f"mv {pkgRoot} $OUT",
13681372
]
13691373
cmd = " && ".join(cmds)

tools/please_go/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 1.24.0
2+
--------------
3+
* Propagate licences down to the go_library, go_binary and cgo_library go_repo generates.
4+
15
Version 1.23.0
26
--------------
37
* Be able to specify whether to add tests (#346)

tools/please_go/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.23.0
1+
1.24.0

tools/please_go/generate/generate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ type Generate struct {
3333
install []string
3434
labels []string
3535
largePackages []string
36+
licences []string
3637
}
3738

38-
func New(srcRoot, thirdPartyFolder, hostModFile, module, version, subrepo string, buildFileNames, moduleDeps, install []string, buildTags []string, labels []string, largePackages []string) *Generate {
39+
func New(srcRoot, thirdPartyFolder, hostModFile, module, version, subrepo string, buildFileNames, moduleDeps, install, buildTags, labels, largePackages, licences []string) *Generate {
3940
moduleArg := module
4041
if version != "" {
4142
moduleArg += "@" + version
@@ -58,6 +59,7 @@ func New(srcRoot, thirdPartyFolder, hostModFile, module, version, subrepo string
5859
subrepo: subrepo,
5960
labels: labels,
6061
largePackages: largePackages,
62+
licences: licences,
6163
}
6264
}
6365

@@ -320,6 +322,7 @@ func (g *Generate) matchesInstall(dir string) bool {
320322
func (g *Generate) rule(rule *Rule) *bazelbuild.Rule {
321323
r := NewRule(rule.kind, rule.name)
322324
populateRule(r, rule)
325+
r.SetAttr("licences", NewStringList(g.licences))
323326
r.SetAttr("visibility", NewStringList([]string{"PUBLIC"}))
324327
r.SetAttr("labels", NewStringList(g.labels))
325328
if rule.kind == "go_library" {

tools/please_go/please_go.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var opts = struct {
9696
Install []string `long:"install" description:"The packages to add to the :install alias"`
9797
BuildTags []string `long:"build_tag" description:"Any build tags to apply to the build"`
9898
Subrepo string `long:"subrepo" description:"The subrepo root to output into"`
99+
Licences []string `long:"licence" description:"The licences under which the module is released"`
99100
Labels []string `long:"label" description:"Additional labels to attach to subrepo targets"`
100101
LargePackages []string `long:"large_package" description:"Relative names of packages which have lots of input files (meaning the go_library target should be marked as large)"`
101102
Args struct {
@@ -170,7 +171,7 @@ var subCommands = map[string]func() int{
170171
},
171172
"generate": func() int {
172173
gen := opts.Generate
173-
g := generate.New(gen.SrcRoot, gen.ThirdPartyFolder, gen.ModFile, gen.Module, gen.Version, gen.Subrepo, []string{"BUILD", "BUILD.plz"}, gen.Args.Requirements, gen.Install, gen.BuildTags, gen.Labels, gen.LargePackages)
174+
g := generate.New(gen.SrcRoot, gen.ThirdPartyFolder, gen.ModFile, gen.Module, gen.Version, gen.Subrepo, []string{"BUILD", "BUILD.plz"}, gen.Args.Requirements, gen.Install, gen.BuildTags, gen.Labels, gen.LargePackages, gen.Licences)
174175
if err := g.Generate(); err != nil {
175176
log.Fatalf("failed to generate go rules: %v", err)
176177
}

0 commit comments

Comments
 (0)