Skip to content

Commit

Permalink
[cbuild] Fix setup list layers arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
brondani committed Jul 19, 2024
1 parent a291f0e commit 33b6a0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
20 changes: 2 additions & 18 deletions pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ func (b CSolutionBuilder) installMissingPacks() (err error) {
func (b CSolutionBuilder) generateBuildFiles() (err error) {
args := b.formulateArgs([]string{"convert"})

cbuildSetFile := b.getCbuildSetFilePath()

var selectedContexts []string
if len(b.Options.Contexts) != 0 {
selectedContexts = append(selectedContexts, b.Options.Contexts...)
}

_, err = os.Stat(cbuildSetFile)

// Read contexts to be processed from cbuild-set file
if b.Options.UseContextSet && err == nil {
selectedContexts, _ = b.getSelectedContexts(cbuildSetFile)
}

// when using "cbuild setup *.csolution.yml -S" with no existing cbuild-set file
// Select first target-type and the first build-type for first listed project
if b.Setup && b.Options.UseContextSet && (len(b.Options.Contexts) == 0) && errors.Is(err, os.ErrNotExist) {
Expand Down Expand Up @@ -189,11 +175,9 @@ func (b CSolutionBuilder) generateBuildFiles() (err error) {
log.Debug("error code received: " + errCodeStr)

if exitError.ExitCode() == 2 {
args = []string{"list", "layers", b.InputFile, "--load=all", "--update-idx", "--quiet"}
for _, context := range selectedContexts {
args = append(args, "--context="+context)
}
args = []string{"list", "layers", b.InputFile, "--context-set", "--load=all", "--update-idx", "--quiet"}
_, listCmdErr := b.runCSolution(args, false)
log.Debug("csolution command: csolution " + strings.Join(args, " "))
if listCmdErr != nil {
err = listCmdErr
} else {
Expand Down
7 changes: 7 additions & 0 deletions pkg/builder/csolution/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ func TestBuild(t *testing.T) {
},
}

t.Run("test setup", func(t *testing.T) {
b.Setup = true
err := b.Build()
assert.Error(err)
b.Setup = false
})

t.Run("test build csolution without context", func(t *testing.T) {
err := b.Build()
assert.Error(err)
Expand Down

0 comments on commit 33b6a0b

Please sign in to comment.