Skip to content

Commit

Permalink
Merge pull request #166 from depot/shim-bake
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Jul 26, 2023
2 parents 8a8ac6b + e8174e4 commit 9ecc148
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions cmd/depot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
binary := os.Args[0]
if strings.HasSuffix(binary, "-buildx") {
cmd, subcmd := parseCmdSubcmd()
if cmd == "buildx" && subcmd == "build" {
if cmd == "buildx" && (subcmd == "build" || subcmd == "bake") {
os.Args = append([]string{binary}, rewriteBuildxArgs()...)
} else {
err := runOriginalBuildx(os.Args[1:])
Expand Down Expand Up @@ -143,34 +143,17 @@ func parseCmdSubcmd() (string, string) {

func rewriteBuildxArgs() []string {
args := os.Args[1:]
cmd := ""
subcmd := ""

filteredArgs := []string{}
done := false
for _, arg := range args {
if !strings.HasPrefix(arg, "-") {
if cmd == "" {
cmd = arg
} else if subcmd == "" {
subcmd = arg
}
}
}

if cmd == "buildx" && subcmd == "build" {
filteredArgs := []string{}
done := false
for _, arg := range args {
if !done && arg == "buildx" {
filteredArgs = append(filteredArgs, "depot")
done = true
} else {
filteredArgs = append(filteredArgs, arg)
}
if !done && arg == "buildx" {
filteredArgs = append(filteredArgs, "depot")
done = true
} else {
filteredArgs = append(filteredArgs, arg)
}
return filteredArgs
}

return args
return filteredArgs
}

func runOriginalBuildx(args []string) error {
Expand Down

0 comments on commit 9ecc148

Please sign in to comment.