Skip to content

Commit

Permalink
Build scripts should use buildexpression types.
Browse files Browse the repository at this point in the history
Initially build scripts and build expressions were developed in parallel. Now they should use common types.
  • Loading branch information
mitchell-as committed Sep 27, 2023
1 parent 5ea71d1 commit c437fb6
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 295 deletions.
7 changes: 1 addition & 6 deletions internal/runbits/buildscript/buildscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ func Sync(proj *project.Project, commitID *strfmt.UUID, out output.Outputer, aut
return false, nil // nothing to do
}
logging.Debug("Merging changes")
expr, err = script.ToBuildExpression()
if err != nil {
return false, errs.Wrap(err, "Unable to translate local build script to build expression")
}

out.Notice(locale.Tl("buildscript_update", "Updating project to reflect build script changes..."))

localCommitID, err := localcommit.Get(proj.Dir())
Expand All @@ -74,7 +69,7 @@ func Sync(proj *project.Project, commitID *strfmt.UUID, out output.Outputer, aut
Owner: proj.Owner(),
Project: proj.Name(),
ParentCommit: localCommitID.String(),
Expression: expr,
Expression: script.Expr,
})
if err != nil {
return false, errs.Wrap(err, "Could not update project to reflect build script changes.")
Expand Down
11 changes: 9 additions & 2 deletions internal/runbits/buildscript/buildscript_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package buildscript

import (
"encoding/json"
"testing"

"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/pkg/platform/runtime/buildexpression"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -29,11 +31,16 @@ in:
runtime`))
require.NoError(t, err)

expr, err := script.ToBuildExpression()
// Make a copy of the original expression.
bytes, err := json.Marshal(script.Expr)
require.NoError(t, err)
expr, err := buildexpression.New(bytes)
require.NoError(t, err)

(*script.Let.Assignments[0].Value.FuncCall.Arguments[0].Assignment.Value.List)[0].Str = ptr.To(`"77777"`)
// Modify the build script.
(*script.Expr.Let.Assignments[0].Value.Ap.Arguments[0].Assignment.Value.List)[0].Str = ptr.To(`77777`)

// Generate the difference between the modified script and the original expression.
result, err := generateDiff(script, expr)
require.NoError(t, err)
assert.Equal(t, `let:
Expand Down
5 changes: 1 addition & 4 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteC
}

// Get the local and remote build expressions to merge.
exprA, err := script.ToBuildExpression()
if err != nil {
return errs.Wrap(err, "Unable to transform local buildscript into buildexpression")
}
exprA := script.Expr
bp := model.NewBuildPlannerModel(p.auth)
exprB, err := bp.GetBuildExpression(p.project.Owner(), p.project.Name(), remoteCommit.String())
if err != nil {
Expand Down
11 changes: 1 addition & 10 deletions pkg/platform/runtime/buildexpression/buildexpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,6 @@ func (e *BuildExpression) getSolveNode() (*Ap, error) {
continue
}

if a.Assignment.Name == "" || a.Assignment.Name != "runtime" {
continue
}

if a.Assignment.Value == nil {
continue
}
Expand All @@ -613,8 +609,7 @@ func (e *BuildExpression) getSolveNode() (*Ap, error) {
}

// recurseLets recursively searches for the solve node in the let statements.
// The solve node is specified by the name "runtime" and the function name "solve"
// or "solve_legacy".
// The solve node is specified by the function name "solve" or "solve_legacy".
func recurseLets(let *Let) (*Ap, error) {
for _, a := range let.Assignments {
if a.Value == nil {
Expand All @@ -625,10 +620,6 @@ func recurseLets(let *Let) (*Ap, error) {
continue
}

if a.Name == "" || a.Name != "runtime" {
continue
}

if a.Value.Ap.Name == SolveFuncName || a.Value.Ap.Name == SolveLegacyFuncName {
return a.Value.Ap, nil
}
Expand Down
228 changes: 0 additions & 228 deletions pkg/platform/runtime/buildscript/buildexpression.go

This file was deleted.

Loading

0 comments on commit c437fb6

Please sign in to comment.