* [PATCH] Introduce rust_at_least helper proc
@ 2023-03-01 20:25 Tom Tromey
2023-03-03 18:38 ` Tom Tromey
2023-03-10 16:20 ` Tom de Vries
0 siblings, 2 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-01 20:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This adds a 'rust_at_least' helper proc, for checking the version of
the Rust compiler in use. It then changes various tests to use this
with 'require'.
---
gdb/testsuite/gdb.rust/rawids.exp | 8 +-------
gdb/testsuite/gdb.rust/unicode.exp | 8 +-------
gdb/testsuite/gdb.rust/unsized.exp | 5 +----
gdb/testsuite/lib/rust-support.exp | 11 +++++++++++
4 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/gdb/testsuite/gdb.rust/rawids.exp b/gdb/testsuite/gdb.rust/rawids.exp
index 976b723833e..8b7db877328 100644
--- a/gdb/testsuite/gdb.rust/rawids.exp
+++ b/gdb/testsuite/gdb.rust/rawids.exp
@@ -16,13 +16,7 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
- untested "raw identifiers require rust 1.30 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1 30}
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
diff --git a/gdb/testsuite/gdb.rust/unicode.exp b/gdb/testsuite/gdb.rust/unicode.exp
index 2b4766b5553..c2bc0ef960f 100644
--- a/gdb/testsuite/gdb.rust/unicode.exp
+++ b/gdb/testsuite/gdb.rust/unicode.exp
@@ -16,14 +16,8 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
# Non-ASCII identifiers were allowed starting in 1.53.
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 53} {
- untested "this test requires rust 1.53 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1 53}
# Enable basic use of UTF-8. LC_ALL gets reset for each testfile.
setenv LC_ALL C.UTF-8
diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/unsized.exp
index f81be8a3078..b3bd2d7d1c5 100644
--- a/gdb/testsuite/gdb.rust/unsized.exp
+++ b/gdb/testsuite/gdb.rust/unsized.exp
@@ -31,10 +31,7 @@ if {![runto ${srcfile}:$line]} {
gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
-set v [split [rust_compiler_version] .]
-# The necessary debuginfo generation landed in 1.60, but had a bug
-# that was fixed in 1.61.
-if {[lindex $v 0] > 1 || [lindex $v 1] >= 61} {
+if {[rust_at_least 1 61]} {
gdb_test "print us2" " = .*Box<.*> \\\[1, 2, 3\\\]"
gdb_test "ptype us2" "type = .*"
}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index df517647ce9..c4a403732dc 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -112,3 +112,14 @@ gdb_caching_proc rust_compiler_version {
}
return 0.0
}
+
+# A helper that checks that the rust compiler is at least MAJOR.MINOR.
+# This is handy for use with 'require'.
+proc rust_at_least {major minor} {
+ set v [split [rust_compiler_version] .]
+ if {[lindex $v 0] < $major
+ || ([lindex $v 0] == $major && [lindex $v 1] < $minor)} {
+ return 0
+ }
+ return 1
+}
--
2.39.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Introduce rust_at_least helper proc
2023-03-01 20:25 [PATCH] Introduce rust_at_least helper proc Tom Tromey
@ 2023-03-03 18:38 ` Tom Tromey
2023-03-10 16:20 ` Tom de Vries
1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-03 18:38 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:
Tom> This adds a 'rust_at_least' helper proc, for checking the version of
Tom> the Rust compiler in use. It then changes various tests to use this
Tom> with 'require'.
I decided later that it would be nicer to just pass a version number,
rather than a list. So, here is v2.
Tom
commit 4c3abcc38a02d89b27b8bc1b9a82a0112930ec7d
Author: Tom Tromey <tromey@adacore.com>
Date: Mon Feb 27 13:23:35 2023 -0700
Introduce rust_at_least helper proc
This adds a 'rust_at_least' helper proc, for checking the version of
the Rust compiler in use. It then changes various tests to use this
with 'require'.
diff --git a/gdb/testsuite/gdb.rust/rawids.exp b/gdb/testsuite/gdb.rust/rawids.exp
index 976b723833e..3c65efb30c0 100644
--- a/gdb/testsuite/gdb.rust/rawids.exp
+++ b/gdb/testsuite/gdb.rust/rawids.exp
@@ -16,13 +16,7 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
- untested "raw identifiers require rust 1.30 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1.30}
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
diff --git a/gdb/testsuite/gdb.rust/unicode.exp b/gdb/testsuite/gdb.rust/unicode.exp
index 2b4766b5553..3de8fefdcc0 100644
--- a/gdb/testsuite/gdb.rust/unicode.exp
+++ b/gdb/testsuite/gdb.rust/unicode.exp
@@ -16,14 +16,8 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
# Non-ASCII identifiers were allowed starting in 1.53.
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 53} {
- untested "this test requires rust 1.53 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1.53}
# Enable basic use of UTF-8. LC_ALL gets reset for each testfile.
setenv LC_ALL C.UTF-8
diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/unsized.exp
index f81be8a3078..c81a93a9303 100644
--- a/gdb/testsuite/gdb.rust/unsized.exp
+++ b/gdb/testsuite/gdb.rust/unsized.exp
@@ -31,10 +31,7 @@ if {![runto ${srcfile}:$line]} {
gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
-set v [split [rust_compiler_version] .]
-# The necessary debuginfo generation landed in 1.60, but had a bug
-# that was fixed in 1.61.
-if {[lindex $v 0] > 1 || [lindex $v 1] >= 61} {
+if {[rust_at_least 1.61]} {
gdb_test "print us2" " = .*Box<.*> \\\[1, 2, 3\\\]"
gdb_test "ptype us2" "type = .*"
}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index df517647ce9..85adbb9bb8f 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -112,3 +112,28 @@ gdb_caching_proc rust_compiler_version {
}
return 0.0
}
+
+# A helper that checks that the rust compiler is at least the given
+# version. This is handy for use with 'require'.
+proc rust_at_least {atleast} {
+ foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] {
+ if {$n1 == ""} {
+ # Have 1.2, wanted 1.2.1.
+ return 0
+ }
+ if {$n2 == ""} {
+ # Have 1.2.1, wanted 1.2.
+ return 1
+ }
+ if {$n1 > $n2} {
+ # Have 1.3, wanted 1.2.
+ return 1
+ }
+ if {$n1 < $n2} {
+ # Have 1.1, wanted 1.2.
+ return 0
+ }
+ }
+ # Completely equal.
+ return 1
+}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Introduce rust_at_least helper proc
2023-03-01 20:25 [PATCH] Introduce rust_at_least helper proc Tom Tromey
2023-03-03 18:38 ` Tom Tromey
@ 2023-03-10 16:20 ` Tom de Vries
2023-03-10 16:56 ` Tom Tromey
2023-03-14 14:01 ` Tom Tromey
1 sibling, 2 replies; 5+ messages in thread
From: Tom de Vries @ 2023-03-10 16:20 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 770 bytes --]
On 3/1/23 21:25, Tom Tromey via Gdb-patches wrote:
> This adds a 'rust_at_least' helper proc, for checking the version of
> the Rust compiler in use. It then changes various tests to use this
> with 'require'.
Hi,
just an idea, this could also be implemented without introducing a new
proc, using proc version_compare, so instead of:
...
require {rust_at_least 1 30}
...
we'd do:
...
require {version_compare [rust_compiler_version] >= {1 30 0}}
...
I needed the additional 0 because my rustc version is:
...
$ rustc --version
rustc 1.67.1 (d5a82bbd2 2023-02-07) (built from a source tarball)
...
and version_compare currently requires comparing version-lists with the
same length, but I suppose we could also change that to just assume a 0.
WDYT?
Thanks,
- Tom
[-- Attachment #2: tmp.patch --]
[-- Type: text/x-patch, Size: 3063 bytes --]
diff --git a/gdb/testsuite/gdb.rust/rawids.exp b/gdb/testsuite/gdb.rust/rawids.exp
index 976b723833e..ec613048bf0 100644
--- a/gdb/testsuite/gdb.rust/rawids.exp
+++ b/gdb/testsuite/gdb.rust/rawids.exp
@@ -17,12 +17,7 @@
load_lib rust-support.exp
require allow_rust_tests
-
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
- untested "raw identifiers require rust 1.30 or greater"
- return -1
-}
+require {version_compare [rust_compiler_version] >= {1 30 0}}
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
diff --git a/gdb/testsuite/gdb.rust/unicode.exp b/gdb/testsuite/gdb.rust/unicode.exp
index 2b4766b5553..9f27fddcad4 100644
--- a/gdb/testsuite/gdb.rust/unicode.exp
+++ b/gdb/testsuite/gdb.rust/unicode.exp
@@ -16,14 +16,9 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
# Non-ASCII identifiers were allowed starting in 1.53.
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 53} {
- untested "this test requires rust 1.53 or greater"
- return -1
-}
+require allow_rust_tests
+require {version_compare [rust_compiler_version] >= {1 53 0}}
# Enable basic use of UTF-8. LC_ALL gets reset for each testfile.
setenv LC_ALL C.UTF-8
diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/unsized.exp
index f81be8a3078..07f6c2e7a21 100644
--- a/gdb/testsuite/gdb.rust/unsized.exp
+++ b/gdb/testsuite/gdb.rust/unsized.exp
@@ -31,10 +31,7 @@ if {![runto ${srcfile}:$line]} {
gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
-set v [split [rust_compiler_version] .]
-# The necessary debuginfo generation landed in 1.60, but had a bug
-# that was fixed in 1.61.
-if {[lindex $v 0] > 1 || [lindex $v 1] >= 61} {
+if {[version_compare [rust_compiler_version] >= {1 61 0}]} {
gdb_test "print us2" " = .*Box<.*> \\\[1, 2, 3\\\]"
gdb_test "ptype us2" "type = .*"
}
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index fb5c953a6c4..371c7a86fc2 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -115,6 +115,7 @@ proc version_compare { l1 op l2 } {
"<" {}
"<=" { return [expr [version_compare $l1 < $l2] \
|| [version_compare $l1 == $l2]]}
+ ">=" { return [expr [version_compare $l2 <= $l1]] }
default { error "unsupported op: $op" }
}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index f3739e2ce02..187087a47cb 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -105,10 +105,11 @@ gdb_caching_proc rust_compiler_version {} {
set output [lindex [remote_exec host "$rustc --version --verbose"] 1]
foreach line [split $output \n] {
if {[regexp "rustc (\[0-9.\]+).*\$" $output ignore version]} {
+ set version [split $version .]
return $version
}
}
verbose "could not match rustc version output: $output"
}
- return 0.0
+ return [list 0 0]
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Introduce rust_at_least helper proc
2023-03-10 16:20 ` Tom de Vries
@ 2023-03-10 16:56 ` Tom Tromey
2023-03-14 14:01 ` Tom Tromey
1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-10 16:56 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> just an idea, this could also be implemented without introducing a new
Tom> proc, using proc version_compare, so instead of:
Tom> ...
Tom> require {rust_at_least 1 30}
Tom> ...
Tom> we'd do:
Tom> ...
Tom> require {version_compare [rust_compiler_version] >= {1 30 0}}
Tom> ...
Having the proc seems simpler on the whole. Changing the implementation
seems ok though.
Tom> I needed the additional 0 because my rustc version is:
Tom> ...
Tom> $ rustc --version
Tom> rustc 1.67.1 (d5a82bbd2 2023-02-07) (built from a source tarball)
Tom> ...
Tom> and version_compare currently requires comparing version-lists with
Tom> the same length, but I suppose we could also change that to just
Tom> assume a 0.
Maybe I'll change version_compare not to require equal-length lists.
That seems fragile in a way, like what if rustc adds some extra '.'.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Introduce rust_at_least helper proc
2023-03-10 16:20 ` Tom de Vries
2023-03-10 16:56 ` Tom Tromey
@ 2023-03-14 14:01 ` Tom Tromey
1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-14 14:01 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches
Tom> I needed the additional 0 because my rustc version is:
Tom> ...
Tom> $ rustc --version
Tom> rustc 1.67.1 (d5a82bbd2 2023-02-07) (built from a source tarball)
Tom> ...
Tom> and version_compare currently requires comparing version-lists with
Tom> the same length, but I suppose we could also change that to just
Tom> assume a 0.
Tom> WDYT?
I've added on some patches to redo version_compare to take lists of
different lengths, and another to remove version_at_least. I'll send
them momentarily.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-14 14:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 20:25 [PATCH] Introduce rust_at_least helper proc Tom Tromey
2023-03-03 18:38 ` Tom Tromey
2023-03-10 16:20 ` Tom de Vries
2023-03-10 16:56 ` Tom Tromey
2023-03-14 14:01 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).