From a880f4389f4c10abd89dac2f6563940041626fb0 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 2 Aug 2021 15:29:17 -0700 Subject: [PATCH] Add "--arch-filter" flag that mimics "--skip-constraints" but without printed warnings and without applying Constraints --- cmd/bashbrew/cmd-deps.go | 12 +++++++++++- cmd/bashbrew/cmd-from.go | 6 +++++- cmd/bashbrew/cmd-list.go | 4 ++++ cmd/bashbrew/main.go | 10 +++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cmd/bashbrew/cmd-deps.go b/cmd/bashbrew/cmd-deps.go index dd99a47b..1eb9f5cc 100644 --- a/cmd/bashbrew/cmd-deps.go +++ b/cmd/bashbrew/cmd-deps.go @@ -32,6 +32,7 @@ func cmdFamily(parents bool, c *cli.Context) error { uniq := c.Bool("uniq") applyConstraints := c.Bool("apply-constraints") + archFilter := c.Bool("arch-filter") depth := c.Int("depth") allRepos, err := repos(true) @@ -53,6 +54,9 @@ func cmdFamily(parents bool, c *cli.Context) error { if applyConstraints && r.SkipConstraints(entry) { continue } + if archFilter && !entry.HasArchitecture(arch) { + continue + } for _, tag := range r.Tags(namespace, false, entry) { network.AddNode(tag, entry) @@ -70,9 +74,12 @@ func cmdFamily(parents bool, c *cli.Context) error { if applyConstraints && r.SkipConstraints(entry) { continue } + if archFilter && !entry.HasArchitecture(arch) { + continue + } entryArches := []string{arch} - if !applyConstraints { + if !applyConstraints && !archFilter { entryArches = entry.Architectures } @@ -102,6 +109,9 @@ func cmdFamily(parents bool, c *cli.Context) error { if applyConstraints && r.SkipConstraints(entry) { continue } + if archFilter && !entry.HasArchitecture(arch) { + continue + } // we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them tagRepo := path.Join(namespace, r.RepoName) diff --git a/cmd/bashbrew/cmd-from.go b/cmd/bashbrew/cmd-from.go index a3990f6c..042c608d 100644 --- a/cmd/bashbrew/cmd-from.go +++ b/cmd/bashbrew/cmd-from.go @@ -15,6 +15,7 @@ func cmdFrom(c *cli.Context) error { uniq := c.Bool("uniq") applyConstraints := c.Bool("apply-constraints") + archFilter := c.Bool("arch-filter") for _, repo := range repos { r, err := fetch(repo) @@ -26,9 +27,12 @@ func cmdFrom(c *cli.Context) error { if applyConstraints && r.SkipConstraints(entry) { continue } + if archFilter && !entry.HasArchitecture(arch) { + continue + } entryArches := []string{arch} - if !applyConstraints { + if !applyConstraints && !archFilter { entryArches = entry.Architectures } diff --git a/cmd/bashbrew/cmd-list.go b/cmd/bashbrew/cmd-list.go index 398a77e4..0c5f5a3b 100644 --- a/cmd/bashbrew/cmd-list.go +++ b/cmd/bashbrew/cmd-list.go @@ -16,6 +16,7 @@ func cmdList(c *cli.Context) error { uniq := c.Bool("uniq") applyConstraints := c.Bool("apply-constraints") + archFilter := c.Bool("arch-filter") onlyRepos := c.Bool("repos") buildOrder := c.Bool("build-order") @@ -57,6 +58,9 @@ func cmdList(c *cli.Context) error { if applyConstraints && r.SkipConstraints(entry) { continue } + if archFilter && !entry.HasArchitecture(arch) { + continue + } for _, tag := range r.Tags(namespace, uniq, entry) { fmt.Printf("%s\n", tag) diff --git a/cmd/bashbrew/main.go b/cmd/bashbrew/main.go index d8cd88af..76893492 100644 --- a/cmd/bashbrew/main.go +++ b/cmd/bashbrew/main.go @@ -210,7 +210,11 @@ func main() { }, "apply-constraints": cli.BoolFlag{ Name: "apply-constraints", - Usage: "apply Constraints as if repos were building", + Usage: "apply all Constraints (including Architectures) as if repos were building", + }, + "arch-filter": cli.BoolFlag{ + Name: "arch-filter", + Usage: "like apply-constraints, but only for Architectures", }, "depth": cli.IntFlag{ Name: "depth", @@ -240,6 +244,7 @@ func main() { commonFlags["all"], commonFlags["uniq"], commonFlags["apply-constraints"], + commonFlags["arch-filter"], cli.BoolFlag{ Name: "build-order", Usage: "sort by the order repos would need to build (topsort)", @@ -321,6 +326,7 @@ func main() { Usage: `print the repos built FROM a given repo or repo:tag`, Flags: []cli.Flag{ commonFlags["apply-constraints"], + commonFlags["arch-filter"], commonFlags["depth"], commonFlags["uniq"], }, @@ -338,6 +344,7 @@ func main() { Usage: `print the repos this repo or repo:tag is FROM`, Flags: []cli.Flag{ commonFlags["apply-constraints"], + commonFlags["arch-filter"], commonFlags["depth"], commonFlags["uniq"], }, @@ -375,6 +382,7 @@ func main() { commonFlags["all"], commonFlags["uniq"], commonFlags["apply-constraints"], + commonFlags["arch-filter"], }, Before: subcommandBeforeFactory("from"), Action: cmdFrom,