Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/runbits/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func Update(
}
buildPlan = commit.BuildPlan()

// Log build plan status
logging.Debug("Build plan status: %s", buildPlan.Status())

solveSpinner.Stop(locale.T("progress_success"))
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/buildplan/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (b *BuildPlan) IsBuildInProgress() bool {
return b.raw.Status == raw.Started || b.raw.Status == raw.Planned
}

func (b *BuildPlan) Status() string {
return b.raw.Status
}

// RequestedIngredients returns the resolved requirements of the buildplan as ingredients
func (b *BuildPlan) RequestedIngredients() Ingredients {
ingredients := Ingredients{}
Expand Down
41 changes: 33 additions & 8 deletions pkg/platform/model/buildplanner/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,45 @@ func isWildcardVersion(version string) bool {
return strings.Contains(version, ".x") || strings.Contains(version, ".X")
}

func normalizeLeadingV(version string) string {
if version == "" {
return version
}
if version[0] == 'v' || version[0] == 'V' {
return version[1:]
}
return version
}

func VersionStringToRequirements(version string) ([]types.VersionRequirement, error) {
if isExactVersion(version) {
original := version
normalized := normalizeLeadingV(version)
originalHasV := len(original) > 0 && (original[0] == 'v' || original[0] == 'V')
if isExactVersion(normalized) {
return []types.VersionRequirement{{
types.VersionRequirementComparatorKey: "eq",
types.VersionRequirementVersionKey: version,
types.VersionRequirementVersionKey: original,
}}, nil
}

if !isWildcardVersion(version) {
if !isWildcardVersion(normalized) {
// Ask the Platform to translate a string like ">=1.2,<1.3" into a list of requirements.
// Note that:
// - The given requirement name does not matter; it is not looked up.
changeset, err := reqsimport.Init().Changeset([]byte("name "+version), "", "", "")
changeset, err := reqsimport.Init().Changeset([]byte("name "+normalized), "", "", "")
if err != nil {
return nil, locale.WrapInputError(err, "err_invalid_version_string", "Invalid version string")
}
requirements := []types.VersionRequirement{}
for _, change := range changeset {
for _, constraint := range change.VersionConstraints {
vr := constraint.Version
if originalHasV && vr != "" && vr[0] != 'v' && vr[0] != 'V' {
vr = "v" + vr
}
requirements = append(requirements, types.VersionRequirement{
types.VersionRequirementComparatorKey: constraint.Comparator,
types.VersionRequirementVersionKey: constraint.Version,
types.VersionRequirementVersionKey: vr,
})
}
}
Expand All @@ -214,26 +231,34 @@ func VersionStringToRequirements(version string) ([]types.VersionRequirement, er
// For example, given a version number of 3.10.x, constraints should be >= 3.10, < 3.11.
// Given 2.x, constraints should be >= 2, < 3.
requirements := []types.VersionRequirement{}
parts := strings.Split(version, ".")
parts := strings.Split(normalized, ".")
for i, part := range parts {
if part != "x" && part != "X" {
continue
}
if i == 0 {
return nil, locale.NewInputError("err_version_wildcard_start", "A version number cannot start with a wildcard")
}
gte := strings.Join(parts[:i], ".")
if originalHasV {
gte = "v" + gte
}
requirements = append(requirements, types.VersionRequirement{
types.VersionRequirementComparatorKey: types.ComparatorGTE,
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
types.VersionRequirementVersionKey: gte,
})
previousPart, err := strconv.Atoi(parts[i-1])
if err != nil {
return nil, locale.WrapInputError(err, "err_version_number_expected", "Version parts are expected to be numeric")
}
parts[i-1] = strconv.Itoa(previousPart + 1)
lt := strings.Join(parts[:i], ".")
if originalHasV {
lt = "v" + lt
}
requirements = append(requirements, types.VersionRequirement{
types.VersionRequirementComparatorKey: types.ComparatorLT,
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
types.VersionRequirementVersionKey: lt,
})
}
return requirements, nil
Expand Down
Loading