Add "--arch-filter" flag that mimics "--skip-constraints" but without printed warnings and without applying Constraints

This commit is contained in:
Tianon Gravi 2021-08-02 15:29:17 -07:00
parent 6b94cffe46
commit a880f4389f
4 changed files with 29 additions and 3 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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,