Skip to content

Commit

Permalink
Merge pull request #31 from infosiftr/arch-filter
Browse files Browse the repository at this point in the history
Add "--arch-filter" flag that mimics "--skip-constraints"
  • Loading branch information
yosifkit authored Aug 4, 2021
2 parents 6b94cff + a880f43 commit 7d4279f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
12 changes: 11 additions & 1 deletion cmd/bashbrew/cmd-deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion cmd/bashbrew/cmd-from.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/bashbrew/cmd-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion cmd/bashbrew/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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"],
},
Expand All @@ -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"],
},
Expand Down Expand Up @@ -375,6 +382,7 @@ func main() {
commonFlags["all"],
commonFlags["uniq"],
commonFlags["apply-constraints"],
commonFlags["arch-filter"],
},
Before: subcommandBeforeFactory("from"),
Action: cmdFrom,
Expand Down

0 comments on commit 7d4279f

Please sign in to comment.