Skip to content

Commit c18b4c8

Browse files
authored
Merge pull request #3750 from ActiveState/jeremyp/loose-version
loosen version verification
2 parents 4fa93d7 + 110d75d commit c18b4c8

File tree

3 files changed

+39
-43
lines changed

3 files changed

+39
-43
lines changed

internal/runners/install/install.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package install
33
import (
44
"errors"
55
"fmt"
6-
"regexp"
76
"strings"
87
"time"
98

@@ -269,8 +268,6 @@ func (i *Install) resolveRequirements(packages captain.PackagesValue, ts time.Ti
269268
return reqs, nil
270269
}
271270

272-
var versionRe = regexp.MustCompile(`^\d(\.\d+)*$`)
273-
274271
func resolveVersion(req *requirement) error {
275272
version := req.Requested.Version
276273

@@ -283,7 +280,7 @@ func resolveVersion(req *requirement) error {
283280
// Verify that the version provided can be resolved
284281
// Note: if the requirement does not have an ingredient, it is being dynamically imported, so
285282
// we cannot resolve its versions yet.
286-
if versionRe.MatchString(version) && req.Resolved.ingredient != nil {
283+
if req.Resolved.ingredient != nil {
287284
match := false
288285
for _, knownVersion := range req.Resolved.ingredient.Versions {
289286
if knownVersion.Version == version {

pkg/platform/model/buildplanner/build.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package buildplanner
33
import (
44
"encoding/json"
55
"errors"
6-
"regexp"
76
"strconv"
87
"strings"
98
"time"
@@ -172,25 +171,16 @@ func processBuildPlannerError(bpErr error, fallbackMessage string) error {
172171
return &response.BuildPlannerError{Err: locale.NewExternalError("err_buildplanner", "{{.V0}}: Encountered unexpected error: {{.V1}}", fallbackMessage, bpErr.Error())}
173172
}
174173

175-
var versionRe = regexp.MustCompile(`^\d+(\.\d+)*$`)
176-
177-
func isExactVersion(version string) bool {
178-
return versionRe.MatchString(version)
174+
func isRangeVersion(version string) bool {
175+
return strings.Contains(version, "=") || strings.Contains(version, "<") || strings.Contains(version, ">")
179176
}
180177

181178
func isWildcardVersion(version string) bool {
182179
return strings.Contains(version, ".x") || strings.Contains(version, ".X")
183180
}
184181

185182
func VersionStringToRequirements(version string) ([]types.VersionRequirement, error) {
186-
if isExactVersion(version) {
187-
return []types.VersionRequirement{{
188-
types.VersionRequirementComparatorKey: "eq",
189-
types.VersionRequirementVersionKey: version,
190-
}}, nil
191-
}
192-
193-
if !isWildcardVersion(version) {
183+
if isRangeVersion(version) {
194184
// Ask the Platform to translate a string like ">=1.2,<1.3" into a list of requirements.
195185
// Note that:
196186
// - The given requirement name does not matter; it is not looked up.
@@ -210,33 +200,41 @@ func VersionStringToRequirements(version string) ([]types.VersionRequirement, er
210200
return requirements, nil
211201
}
212202

213-
// Construct version constraints to be >= given version, and < given version's last part + 1.
214-
// For example, given a version number of 3.10.x, constraints should be >= 3.10, < 3.11.
215-
// Given 2.x, constraints should be >= 2, < 3.
216-
requirements := []types.VersionRequirement{}
217-
parts := strings.Split(version, ".")
218-
for i, part := range parts {
219-
if part != "x" && part != "X" {
220-
continue
221-
}
222-
if i == 0 {
223-
return nil, locale.NewInputError("err_version_wildcard_start", "A version number cannot start with a wildcard")
224-
}
225-
requirements = append(requirements, types.VersionRequirement{
226-
types.VersionRequirementComparatorKey: types.ComparatorGTE,
227-
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
228-
})
229-
previousPart, err := strconv.Atoi(parts[i-1])
230-
if err != nil {
231-
return nil, locale.WrapInputError(err, "err_version_number_expected", "Version parts are expected to be numeric")
203+
if isWildcardVersion(version) {
204+
// Construct version constraints to be >= given version, and < given version's last part + 1.
205+
// For example, given a version number of 3.10.x, constraints should be >= 3.10, < 3.11.
206+
// Given 2.x, constraints should be >= 2, < 3.
207+
requirements := []types.VersionRequirement{}
208+
parts := strings.Split(version, ".")
209+
for i, part := range parts {
210+
if part != "x" && part != "X" {
211+
continue
212+
}
213+
if i == 0 {
214+
return nil, locale.NewInputError("err_version_wildcard_start", "A version number cannot start with a wildcard")
215+
}
216+
requirements = append(requirements, types.VersionRequirement{
217+
types.VersionRequirementComparatorKey: types.ComparatorGTE,
218+
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
219+
})
220+
previousPart, err := strconv.Atoi(parts[i-1])
221+
if err != nil {
222+
return nil, locale.WrapInputError(err, "err_version_number_expected", "Version parts are expected to be numeric")
223+
}
224+
parts[i-1] = strconv.Itoa(previousPart + 1)
225+
requirements = append(requirements, types.VersionRequirement{
226+
types.VersionRequirementComparatorKey: types.ComparatorLT,
227+
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
228+
})
232229
}
233-
parts[i-1] = strconv.Itoa(previousPart + 1)
234-
requirements = append(requirements, types.VersionRequirement{
235-
types.VersionRequirementComparatorKey: types.ComparatorLT,
236-
types.VersionRequirementVersionKey: strings.Join(parts[:i], "."),
237-
})
230+
return requirements, nil
238231
}
239-
return requirements, nil
232+
233+
return []types.VersionRequirement{{
234+
types.VersionRequirementComparatorKey: "eq",
235+
types.VersionRequirementVersionKey: version,
236+
}}, nil
237+
240238
}
241239

242240
// pollBuildPlanned polls the buildplan until it has passed the planning stage (ie. it's either planned or further along).

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ For usage information please refer to the [State Tool Documentation](http://docs
3535

3636
### Building & Testing
3737

38-
First run `state run install-deps` followed by `state run preprocess` if you are building for the first time.
38+
First run `state run install-deps-dev` followed by `state run preprocess` if you are building for the first time.
3939

4040
* **Building:** `state run build`
4141
* The built executable will be stored in the `build` directory
4242
* If you modified assets or switched branches, you need to re-run `state run preprocess` first
43+
* The first time you are building, or if you modified modules outside the primary state binary, run `state run build-all`
4344
* **Testing:**
4445
* **Unit tests\*:** `state run test`
4546
* **Integration tests:** `state run integration-tests`

0 commit comments

Comments
 (0)