Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
e3-require
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESS EPICS Environment
wrappers
e3-require
Commits
bcf4faa5
Commit
bcf4faa5
authored
2 years ago
by
Simon Rose
Browse files
Options
Downloads
Patches
Plain Diff
Add revision number comparison to test versions
parent
75db90f3
No related branches found
No related tags found
1 merge request
!115
E3-1058: Add revision number parsing to test versions
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
require-ess/src/require.c
+30
-25
30 additions, 25 deletions
require-ess/src/require.c
require-ess/src/version.c
+7
-4
7 additions, 4 deletions
require-ess/src/version.c
tests/test_versions.py
+6
-0
6 additions, 0 deletions
tests/test_versions.py
with
43 additions
and
29 deletions
require-ess/src/require.c
+
30
−
25
View file @
bcf4faa5
...
...
@@ -617,8 +617,7 @@ static int compareDigit(int found, int requested, const char *name) {
return
MATCH
;
}
static
int
compareNumericVersion
(
semver_t
*
sv_found
,
semver_t
*
sv_request
,
int
already_matched
)
{
static
int
compareNumericVersion
(
semver_t
*
sv_found
,
semver_t
*
sv_request
)
{
int
match
;
match
=
compareDigit
(
sv_found
->
major
,
sv_request
->
major
,
"major"
);
...
...
@@ -629,25 +628,7 @@ static int compareNumericVersion(semver_t *sv_found, semver_t *sv_request,
if
(
match
!=
MATCH
)
{
return
match
;
}
match
=
compareDigit
(
sv_found
->
patch
,
sv_request
->
patch
,
"patch"
);
if
(
match
!=
MATCH
)
{
return
match
;
}
if
(
sv_request
->
revision
==
-
1
)
{
if
(
already_matched
)
{
debug
(
"require: compareVersions: No revision number requested. Returning "
"HIGHER
\n
"
);
return
HIGHER
;
}
else
{
debug
(
"require: compareVersions: No revision number requested. Returning "
"MATCH
\n
"
);
return
MATCH
;
}
}
return
compareDigit
(
sv_found
->
revision
,
sv_request
->
revision
,
"revision"
);
return
compareDigit
(
sv_found
->
patch
,
sv_request
->
patch
,
"patch"
);
}
/*
...
...
@@ -672,16 +653,20 @@ static int compareVersions(const char *found, const char *request,
sv_found
=
(
semver_t
*
)
calloc
(
1
,
sizeof
(
semver_t
));
sv_request
=
(
semver_t
*
)
calloc
(
1
,
sizeof
(
semver_t
));
// TODO: maybe don't do this. This is only in the case that
// we have found an installed version with no revision number.
if
(
already_matched
&&
sv_request
->
revision
==
-
1
)
sv_request
->
revision
=
0
;
parse_semver
(
found
,
sv_found
);
parse_semver
(
request
,
sv_request
);
// test version, look for exact.
if
(
strlen
(
sv_request
->
test_str
)
>
0
)
{
if
(
strcmp
(
found
,
request
)
==
0
)
{
if
(
strcmp
(
sv_
found
->
test_str
,
sv_request
->
test_str
)
==
0
)
{
debug
(
"require: compareVersions: Test version requested and found, "
"matches
exactly
\n
"
);
match
=
EXACT
;
"matches
\n
"
);
match
=
MATCH
;
}
else
if
(
strlen
(
sv_found
->
test_str
)
>
0
)
{
debug
(
"require: compareVersions: Test versions requested and found, no "
...
...
@@ -699,7 +684,27 @@ static int compareVersions(const char *found, const char *request,
"found
\n
"
);
match
=
MISMATCH
;
}
else
{
match
=
compareNumericVersion
(
sv_found
,
sv_request
,
already_matched
);
match
=
compareNumericVersion
(
sv_found
,
sv_request
);
}
// Finally, check revision numbers
if
(
match
==
MATCH
)
{
if
(
sv_request
->
revision
==
-
1
)
{
if
(
already_matched
)
{
debug
(
"require: compareVersions: No revision number for already found "
"version. Returning HIGHER
\n
"
);
match
=
HIGHER
;
}
else
{
debug
(
"require: compareVersions: No revision number requested. Returning "
"MATCH
\n
"
);
match
=
MATCH
;
}
}
else
{
match
=
compareDigit
(
sv_found
->
revision
,
sv_request
->
revision
,
"revision"
);
}
}
cleanup_semver
(
sv_found
);
cleanup_semver
(
sv_request
);
...
...
This diff is collapsed.
Click to expand it.
require-ess/src/version.c
+
7
−
4
View file @
bcf4faa5
...
...
@@ -35,13 +35,13 @@ static void fetch_part(char *version_str, const regmatch_t *groups,
int
parse_semver
(
const
char
*
version
,
semver_t
*
s
)
{
static
const
char
*
version_regex
=
"^(([0-9]+)
\\
.([0-9]+)
\\
.([0-9]+)(
\\
+([0-9]+))?
)?(.*)
$"
;
"^(([0-9]+)
\\
.([0-9]+)
\\
.([0-9]+)
)?([^+]*)
(
\\
+([0-9]+))?$"
;
static
const
unsigned
int
max_regex_groups
=
7
+
1
;
static
const
unsigned
int
major_ix
=
2
;
static
const
unsigned
int
minor_ix
=
3
;
static
const
unsigned
int
patch_ix
=
4
;
static
const
unsigned
int
revision
_ix
=
6
;
static
const
unsigned
int
test
_ix
=
7
;
static
const
unsigned
int
test_label
_ix
=
5
;
static
const
unsigned
int
revision
_ix
=
7
;
regex_t
compiled
;
regmatch_t
groups
[
max_regex_groups
];
...
...
@@ -60,10 +60,13 @@ int parse_semver(const char *version, semver_t *s) {
fetch_part
(
s
->
version_str
,
groups
,
major_ix
,
&
s
->
major
);
fetch_part
(
s
->
version_str
,
groups
,
minor_ix
,
&
s
->
minor
);
fetch_part
(
s
->
version_str
,
groups
,
patch_ix
,
&
s
->
patch
);
if
(
groups
[
test_label_ix
].
rm_so
!=
groups
[
test_label_ix
].
rm_eo
)
{
s
->
test_str
=
s
->
version_str
;
}
if
(
groups
[
revision_ix
].
rm_so
!=
(
regoff_t
)
-
1
)
{
fetch_part
(
s
->
version_str
,
groups
,
revision_ix
,
&
s
->
revision
);
s
->
version_str
[
groups
[
revision_ix
].
rm_so
-
1
]
=
0
;
}
s
->
test_str
=
s
->
version_str
+
groups
[
test_ix
].
rm_so
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
tests/test_versions.py
+
6
−
0
View file @
bcf4faa5
...
...
@@ -32,6 +32,12 @@ RE_MODULE_NOT_LOADED = "Module {module} (not available|version {required} not av
(
""
,
"
0.0.1+0
"
,
[
"
0.0.1+0
"
,
"
1.0
"
]),
# Numeric version should be prioritised over "higher" test version
(
""
,
"
0.1.0+0
"
,
[
"
0.1.0+0
"
,
"
1.0.0-rc1
"
]),
# Pick the latest test version based on revision number
(
"
test
"
,
"
test+2
"
,
[
"
test+0
"
,
"
test+2
"
]),
# Don't install an incorrect test version
(
"
foo
"
,
""
,
[
"
bar
"
]),
# Mix of test and numeric
(
"
1.2.3-test
"
,
"
1.2.3-test+2
"
,
[
"
1.2.3-test
"
,
"
1.2.3-test+0
"
,
"
1.2.3-test+2
"
]),
],
)
def
test_version
(
wrapper
:
Wrapper
,
requested
,
expected
,
installed
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment