Skip to content

Commit

Permalink
Restore build script/build expression types merge.
Browse files Browse the repository at this point in the history
This reverts commit e5cb1e0.
  • Loading branch information
mitchell-as committed Oct 10, 2023
1 parent e5cb1e0 commit 203f1c8
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 292 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
24 changes: 24 additions & 0 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
}

// Print the result
if (operation == bpModel.OperationAdded || operation == bpModel.OperationUpdated) && !model.IsExactVersion(version) {
// Print the exact version installed if the user specified a version string.
if requirements, err := expr.Requirements(); err == nil {
for _, req := range requirements {
if req.Name != name {
continue
}
for _, versionReq := range req.VersionRequirement {
comp, ok := versionReq["version"]
if !ok || comp != bpModel.ComparatorEQ {
continue
}
installedVersion, ok := versionReq["version"]
if !ok {
multilog.Error("Malformed buildexpression requirement for %s: %v", req.Name, versionReq)
break
}
requirementVersion = installedVersion
}
}
} else {
multilog.Error("Could not get buildexpression requirements after install: %v", errs.JoinMessage(err))
}
}
message := locale.Tr(fmt.Sprintf("%s_version_%s", ns.Type(), operation), requirementName, requirementVersion)
if requirementVersion == "" {
message = locale.Tr(fmt.Sprintf("%s_%s", ns.Type(), operation), requirementName)
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
4 changes: 2 additions & 2 deletions pkg/platform/model/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func processBuildPlannerError(bpErr error, fallbackMessage string) error {

var versionRe = regexp.MustCompile(`^\d+(\.\d+)*$`)

func isExactVersion(version string) bool {
func IsExactVersion(version string) bool {
return versionRe.MatchString(version)
}

Expand All @@ -400,7 +400,7 @@ func isWildcardVersion(version string) bool {
}

func VersionStringToRequirements(version string) ([]bpModel.VersionRequirement, error) {
if isExactVersion(version) {
if IsExactVersion(version) {
return []bpModel.VersionRequirement{{
bpModel.VersionRequirementComparatorKey: "eq",
bpModel.VersionRequirementVersionKey: version,
Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/runtime/buildexpression/buildexpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ func newValue(path []string, valueInterface interface{}) (*Value, error) {
case float64:
value.Float = ptr.To(v)

case nil:
// An empty value is interpreted as JSON null.
value.Null = &Null{}

default:
logging.Debug("Unknown type: %T at path %s", v, strings.Join(path, "."))
// An empty value is interpreted as JSON null.
Expand Down
228 changes: 0 additions & 228 deletions pkg/platform/runtime/buildscript/buildexpression.go

This file was deleted.

Loading

0 comments on commit 203f1c8

Please sign in to comment.