mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-28 05:00:08 +00:00
feature/featuretags: move list of omit-able features to a Go package
Updates #12614 Change-Id: I4012c33095c6a7ccf80ad36dbab5cedbae5b3d47 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
cfb2ca724b
commit
0e3d942e39
73
cmd/featuretags/featuretags.go
Normal file
73
cmd/featuretags/featuretags.go
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// The featuretags command helps other build tools select Tailscale's Go build
|
||||
// tags to use.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"tailscale.com/feature/featuretags"
|
||||
)
|
||||
|
||||
var (
|
||||
min = flag.Bool("min", false, "remove all features not mentioned in --add")
|
||||
remove = flag.String("remove", "", "a comma-separated list of features to remove from the build. (without the 'ts_omit_' prefix)")
|
||||
add = flag.String("add", "", "a comma-separated list of features or tags to add, if --min is used.")
|
||||
list = flag.Bool("list", false, "if true, list all known features and what they do")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
features := featuretags.Features
|
||||
|
||||
if *list {
|
||||
for _, f := range slices.Sorted(maps.Keys(features)) {
|
||||
fmt.Printf("%20s: %s\n", f, features[f])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var keep = map[string]bool{}
|
||||
for t := range strings.SplitSeq(*add, ",") {
|
||||
if t != "" {
|
||||
keep[t] = true
|
||||
}
|
||||
}
|
||||
var tags []string
|
||||
if keep["cli"] {
|
||||
// The "cli" --add value is special in that it's a build tag
|
||||
// that adds something, rather than removes something.
|
||||
tags = append(tags, "ts_include_cli")
|
||||
}
|
||||
if *min {
|
||||
for _, f := range slices.Sorted(maps.Keys(features)) {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if !keep[f] {
|
||||
tags = append(tags, "ts_omit_"+f)
|
||||
}
|
||||
}
|
||||
}
|
||||
for f := range strings.SplitSeq(*remove, ",") {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := features[f]; !ok {
|
||||
log.Fatalf("unknown feature %q in --remove", f)
|
||||
}
|
||||
tags = append(tags, "ts_omit_"+f)
|
||||
}
|
||||
if len(tags) != 0 {
|
||||
fmt.Println(strings.Join(tags, ","))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,17 +13,16 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"tailscale.com/util/must"
|
||||
"tailscale.com/feature/featuretags"
|
||||
)
|
||||
|
||||
var (
|
||||
cacheDir = flag.String("cachedir", "", "if non-empty, use this directory to store cached size results to speed up subsequent runs. The tool does not consider the git status when deciding whether to use the cache. It's on you to nuke it between runs if the tree changed.")
|
||||
features = flag.String("features", "", "comma-separated list of features to consider, with or without the ts_omit_ prefix (default: all detected in build_dist.sh)")
|
||||
features = flag.String("features", "", "comma-separated list of features to consider, with or without the ts_omit_ prefix")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -31,9 +30,9 @@ func main() {
|
||||
|
||||
var all []string
|
||||
if *features == "" {
|
||||
sh := must.Get(os.ReadFile("build_dist.sh"))
|
||||
omitRx := regexp.MustCompile(`\b(ts_omit_\w+)\b`)
|
||||
all = omitRx.FindAllString(string(sh), -1)
|
||||
for k := range featuretags.Features {
|
||||
all = append(all, "ts_omit_"+k)
|
||||
}
|
||||
} else {
|
||||
for v := range strings.SplitSeq(*features, ",") {
|
||||
if !strings.HasPrefix(v, "ts_omit_") {
|
||||
|
||||
Reference in New Issue
Block a user