For paring back build tag variant CI runs' set of packages to test.
Updates tailscale/corp#28679
Change-Id: Iba46fd1f58c1eaee1f7888ef573bc8b14fa73208
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
withTagsAllStr=flag.String("with-tags-all","","if non-empty, a comma-separated list of builds tags to require (a package will only be listed if it contains all of these build tags)")
withoutTagsAnyStr=flag.String("without-tags-any","","if non-empty, a comma-separated list of build constraints to exclude (a package will be omitted if it contains any of these build tags)")
shard=flag.String("shard","","if non-empty, a string of the form 'N/M' to only print packages in shard N of M (e.g. '1/3', '2/3', '3/3/' for different thirds of the list)")
affectedByTag=flag.String("affected-by-tag","","if non-empty, only list packages whose test binary would be affected by the presence or absence of this build tag")
)
funcmain(){
@ -41,6 +42,10 @@ func main() {
Mode:packages.LoadFiles,
Env:os.Environ(),
}
if*affectedByTag!=""{
cfg.Mode|=packages.NeedImports
cfg.Tests=true
}
if*goos!=""{
cfg.Env=append(cfg.Env,"GOOS="+*goos)
}
@ -62,6 +67,11 @@ func main() {
withAll=strings.Split(*withTagsAllStr,",")
}
varaffectedmap[string]bool// PkgPath → true
if*affectedByTag!=""{
affected=computeAffected(pkgs,*affectedByTag)
}
seen:=map[string]bool{}
matches:=0
Pkg:
@ -69,6 +79,17 @@ Pkg:
ifpkg.PkgPath==""{// malformed (shouldn’t happen)
continue
}
ifaffected!=nil{
// Skip synthetic packages created by Tests: true:
// - for-test variants like "foo [foo.test]" (ID != PkgPath)
// - test binary packages like "foo.test" (PkgPath ends in ".test")