Skip to contentSkip to conversation

toolchain/helpers.mk: fixup check_gcc_version.

PATCH Superseded Guo Ren 4 participants 9 messages Feb 21, 2017 – Feb 22, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guo Ren

author
#0 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

some gcc --version ouput like this:

$ csky-linux-gcc --version
csky-linux-gcc (C-SKY Tools V2.8.08(Beta1)(Glibc,Linux 4.8.4), ABIV1,
B20161118) 4.5.1

current script just find first ')', but we need find last ')' to get correct version number.

---
 toolchain/helpers.mk | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
toolchain/helpers.mk +13 -5
index 72e7292..2d695ed 100644
@@ -136,18 +136,26 @@ check_kernel_headers_version = \
 # - 1!d
 #   - delete if not line 1
 #
-# - s/^[^)]+\) ([^[:space:]]+).*/\1/
-#   - eat all until the first ')' character followed by a space
-#   - match as many non-space chars as possible
-#   - eat all the remaining chars on the line
+# - s/^.+\)[[:space:]]*([^[:space:]]+)/\1/
+#   - eat all until the last ')' character
+#   - match the first non-space sequence
 #   - replace by the matched expression
 #
+# The GCC version string is built up as follows:
+# GCC (PKGVERSION) BASEVER DATESTAMP DEVPHASE REVISION
+# PKGVERSION can be anything, it's a string provided at configure time.
+# BASEVER is what we need.
+# DATESTAMP is YYYYMMDD or empty
+# DEVPHASE is experimental, pre-release or empty
+# REVISION is [svn revision info] or empty
+# Therefore, we need the first non-space sequence after the last ')' character
+#
 check_gcc_version = \
 	expected_version="$(strip $2)" ; \
 	if [ -z "$${expected_version}" ]; then \
 		exit 0 ; \
 	fi; \
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \
 	if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \
 		printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
 			"$${expected_version}" "$${real_version}" ; \
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Hello,

toolchain/helpers.mk check_kernel_headers_version = \ · line 158

Quoted 2 lines · Guo Ren
toolchain/helpers.mk +1 -1
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \

At some point, isn't something like:

	echo "__GNUC__.__GNUC_MINOR__" | gcc -P -E - | sed 's/ //g'

simpler, more readable and probably more robust?

Bonus points if you find a way to not have the spaces around the "." in the output generated by the preprocessor, which would avoid the need to call sed.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
author
#2 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Thx Thomas,

Cool Idea! but it need be retested.

I couldn't find a proper way to avoid the spaces around the ".", and i think sed is ok :)

Best Regards

guoren

Quoted 19 lines · Thomas Petazzoni

Hello,

toolchain/helpers.mk check_kernel_headers_version = \ · line 158

Quoted 2 lines · Guo Ren
toolchain/helpers.mk +1 -1
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \

At some point, isn't something like:

	echo "__GNUC__.__GNUC_MINOR__" | gcc -P -E - | sed 's/ //g'

simpler, more readable and probably more robust?

Bonus points if you find a way to not have the spaces around the "." in the output generated by the preprocessor, which would avoid the need to call sed.

Best regards,

Thomas

#3 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"ren" == ren guo <[email protected]> writes:

Thx Thomas,
Cool Idea! but it need be retested.

I couldn't find a proper way to avoid the spaces around the ".", and i think sed is ok :)

Alternatively we could drop the . and use the shell or awk or whatever to convert from space separated to .-separated:

echo "__GNUC__ __GNUC_MINOR__" | gcc -P -E - | \
     { read MAJOR MINOR; echo $MAJOR.$MINOR ; }

Not that this is so much prettier.

Signature · 1 line
Bye, Peter Korsgaard
author
#4 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Quoted 6 lines · Peter Korsgaard
Quoted 5 lines

Thx Thomas,
Cool Idea! but it need be retested.

I couldn't find a proper way to avoid the spaces around the ".", and i think sed is ok :)

Quoted 8 lines

Alternatively we could drop the . and use the shell or awk or whatever to convert from space separated to .-separated:

echo "__GNUC__ __GNUC_MINOR__" | gcc -P -E - | \
      { read MAJOR MINOR; echo $MAJOR.$MINOR ; }

Not that this is so much prettier.

Thx Peter,

"bash read" seems not bad :) ... But I like 'sed' a little more?

Best Regards

guoren

#5 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

In reply to Thomas Petazzoni
Quoted 4 lines · Thomas Petazzoni

Hello,

On Tue, 21 Feb 2017 17:04:36 +0800, Guo Ren wrote:

Quoted 8 lines

toolchain/helpers.mk check_kernel_headers_version = \ · line 158

Quoted 2 lines
toolchain/helpers.mk +1 -1
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \

At some point, isn't something like:

	echo "__GNUC__.__GNUC_MINOR__" | gcc -P -E - | sed 's/ //g'

simpler, more readable and probably more robust?

Sounds good to me. I ran that on my 300 toolchains and it seems to work. One
thing however: some of them generate a few empty lines at the beginning, so the sed expression should also have /^$/d.

Regards,
Arnout

Quoted 9 lines

Bonus points if you find a way to not have the spaces around the "." in the output generated by the preprocessor, which would avoid the need to call sed.

Best regards,

Thomas

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
author
#6 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Hi Arnout,

Quoted 7 lines

Sounds good to me. I ran that on my 300 toolchains and it seems to work. One
thing however: some of them generate a few empty lines at the beginning, so the sed expression should also have /^$/d.

Regards,
Arnout

Good Test! Do you need I patch mail ? Or just fixup by yourself?

Best Regards

guoren

#7 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

In reply to Guo Ren

Hi guoren,

We like to have a version log in the patch. Under the Signed-off-by, add a line
with --- and then a log of what changed compared to your first submission. Also put "[PATCH v2]" in the Subject (which you can do with
"git format-patch -v2").

Quoted 9 lines · Guo Ren

some gcc --version ouput like this:

$ csky-linux-gcc --version
csky-linux-gcc (C-SKY Tools V2.8.08(Beta1)(Glibc,Linux 4.8.4), ABIV1,
B20161118) 4.5.1

current script just find first ')', but we need find last ')' to get correct version number.

I've tested this on about 300 gcc binaries I have available, and it gives the
same results as before on all of them (I don't have anything like the C-SKY version string). However, not exactly the same, see below.

However, this made me realize that there is still a potential issue, see below.

Quoted 9 lines
---
 toolchain/helpers.mk | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
toolchain/helpers.mk +0 -0
index 72e7292..2d695ed 100644

toolchain/helpers.mk check_kernel_headers_version = \ · line 142

Quoted 7 lines
toolchain/helpers.mk +0 -4
@@ -136,18 +136,26 @@ check_kernel_headers_version = \
 # - 1!d
 #   - delete if not line 1
 #
-# - s/^[^)]+\) ([^[:space:]]+).*/\1/
-#   - eat all until the first ')' character followed by a space
-#   - match as many non-space chars as possible
-#   - eat all the remaining chars on the line

Why did you remove this part of the regex? I think the regex should be:

toolchain/helpers.mk check_kernel_headers_version = \ · line 139

Quoted 1 line
toolchain/helpers.mk +1 -0
+# - s/^.+\)[[:space:]]*([^[:space:]]+)/\1/
       s/^.+\)[[:space:]]*([^[:space:]]+).*/\1/

so keep on eating the part that comes after BASEVER.

toolchain/helpers.mk check_kernel_headers_version = \ · line 141

Quoted 2 lines
toolchain/helpers.mk +2 -0
+#   - eat all until the last ')' character
+#   - match the first non-space sequence

You removed the "eat spaces" part. So:

#   - eat all until the last ')' character
#   - eat any following spaces
#   - match the following non-space sequence
#   - replace by the matched expression

toolchain/helpers.mk check_kernel_headers_version = \ · line 149

Quoted 8 lines
toolchain/helpers.mk +6 -0
 #   - replace by the matched expression
 #
+# The GCC version string is built up as follows:
+# GCC (PKGVERSION) BASEVER DATESTAMP DEVPHASE REVISION
+# PKGVERSION can be anything, it's a string provided at configure time.
+# BASEVER is what we need.
+# DATESTAMP is YYYYMMDD or empty
+# DEVPHASE is experimental, pre-release or empty

Turns out that this is wrong. It should be:

# DEVPHASE is (experimental), (prerelease) or empty

Which brings us to the first potential problem that I found in these 300
toolchains: your new pattern will extract the wrong version when DEVPHASE is non-empty and REVISION is also non-empty. It worked for the toolchains I have, because they had an empty REVISION and the regex requires a non-space character after the last ). But it may not always work.

So this patch fixes one practical case and breaks another theoretical case -
still a net improvement I'd say, so I'm OK with leaving it as is.

To improve this, we could probably require the match part to start with a
digit. However, I don't have any toolchain with non-empty REVISION so I'm not sure if that one doesn't start with a digit either. From the code, it *looks* like the REVISION part always starts with [ but I can't be 100% sure.

toolchain/helpers.mk check_kernel_headers_version = \ · line 159

Quoted 11 lines
toolchain/helpers.mk +4 -1
+# REVISION is [svn revision info] or empty
+# Therefore, we need the first non-space sequence after the last ')' character
+#
 check_gcc_version = \
 	expected_version="$(strip $2)" ; \
 	if [ -z "$${expected_version}" ]; then \
 		exit 0 ; \
 	fi; \
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \
 	if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \

By not eating the DATESTAMP DEVPHASE REVISION part, nothing really changes
because it will still match this pattern. Still, it's cleaner to have the actual BASEVER in real_version and not the entire version string.

Here is the second problem I found while going through all my toolchains: I
have some toolchains that report BASEVER as 4.8 instead of 4.8.x. This will NOT match the expected_version because of the missing . after it. Not sure how to fix that, and if we really need to fix it - it was an Android toolchain :-)

But anyway, that would be for a separate patch.

Regards,
Arnout

Quoted 3 lines
toolchain/helpers.mk +0 -0
 		printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
 			"$${expected_version}" "$${real_version}" ; \
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
author
#8 lore raw

PATCH 1/1 toolchain/helpers.mk: fixup check_gcc_version.

Hi Arnout,

Another path is done, pls have a check.

my patch v2 is ok?

Best Regards

guoren

Quoted 110 lines · Arnout Vandecappelle

Hi guoren,

We like to have a version log in the patch. Under the Signed-off-by, add a line
with --- and then a log of what changed compared to your first submission. Also put "[PATCH v2]" in the Subject (which you can do with
"git format-patch -v2").

Quoted 9 lines · Guo Ren

some gcc --version ouput like this:

$ csky-linux-gcc --version
csky-linux-gcc (C-SKY Tools V2.8.08(Beta1)(Glibc,Linux 4.8.4), ABIV1,
B20161118) 4.5.1

current script just find first ')', but we need find last ')' to get correct version number.

I've tested this on about 300 gcc binaries I have available, and it gives the
same results as before on all of them (I don't have anything like the C-SKY version string). However, not exactly the same, see below.

However, this made me realize that there is still a potential issue, see below.

Quoted 9 lines
---
  toolchain/helpers.mk | 18 +++++++++++++-----
  1 file changed, 13 insertions(+), 5 deletions(-)
toolchain/helpers.mk +0 -0
index 72e7292..2d695ed 100644

toolchain/helpers.mk check_kernel_headers_version = \ · line 142

Quoted 7 lines
toolchain/helpers.mk +0 -4
@@ -136,18 +136,26 @@ check_kernel_headers_version = \
  # - 1!d
  #   - delete if not line 1
  #
-# - s/^[^)]+\) ([^[:space:]]+).*/\1/
-#   - eat all until the first ')' character followed by a space
-#   - match as many non-space chars as possible
-#   - eat all the remaining chars on the line

Why did you remove this part of the regex? I think the regex should be:

toolchain/helpers.mk check_kernel_headers_version = \ · line 139

Quoted 1 line
toolchain/helpers.mk +1 -0
+# - s/^.+\)[[:space:]]*([^[:space:]]+)/\1/
        s/^.+\)[[:space:]]*([^[:space:]]+).*/\1/

so keep on eating the part that comes after BASEVER.

toolchain/helpers.mk check_kernel_headers_version = \ · line 141

Quoted 2 lines
toolchain/helpers.mk +2 -0
+#   - eat all until the last ')' character
+#   - match the first non-space sequence

You removed the "eat spaces" part. So:

#   - eat all until the last ')' character
#   - eat any following spaces
#   - match the following non-space sequence
#   - replace by the matched expression

toolchain/helpers.mk check_kernel_headers_version = \ · line 149

Quoted 8 lines
toolchain/helpers.mk +6 -0
  #   - replace by the matched expression
  #
+# The GCC version string is built up as follows:
+# GCC (PKGVERSION) BASEVER DATESTAMP DEVPHASE REVISION
+# PKGVERSION can be anything, it's a string provided at configure time.
+# BASEVER is what we need.
+# DATESTAMP is YYYYMMDD or empty
+# DEVPHASE is experimental, pre-release or empty

Turns out that this is wrong. It should be:

# DEVPHASE is (experimental), (prerelease) or empty

Which brings us to the first potential problem that I found in these 300
toolchains: your new pattern will extract the wrong version when DEVPHASE is non-empty and REVISION is also non-empty. It worked for the toolchains I have, because they had an empty REVISION and the regex requires a non-space character after the last ). But it may not always work.

So this patch fixes one practical case and breaks another theoretical case -
still a net improvement I'd say, so I'm OK with leaving it as is.

To improve this, we could probably require the match part to start with a
digit. However, I don't have any toolchain with non-empty REVISION so I'm not sure if that one doesn't start with a digit either. From the code, it *looks* like the REVISION part always starts with [ but I can't be 100% sure.

toolchain/helpers.mk check_kernel_headers_version = \ · line 159

Quoted 11 lines
toolchain/helpers.mk +4 -1
+# REVISION is [svn revision info] or empty
+# Therefore, we need the first non-space sequence after the last ')' character
+#
  check_gcc_version = \
  	expected_version="$(strip $2)" ; \
  	if [ -z "$${expected_version}" ]; then \
  		exit 0 ; \
  	fi; \
-	real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \
+	real_version=`$(1) --version | sed -r -e '1!d; s/^.+\)[[:space:]]*([^[:space:]]+)/\1/;'` ; \
  	if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \

By not eating the DATESTAMP DEVPHASE REVISION part, nothing really changes
because it will still match this pattern. Still, it's cleaner to have the actual BASEVER in real_version and not the entire version string.

Here is the second problem I found while going through all my toolchains: I
have some toolchains that report BASEVER as 4.8 instead of 4.8.x. This will NOT match the expected_version because of the missing . after it. Not sure how to fix that, and if we really need to fix it - it was an Android toolchain :-)

But anyway, that would be for a separate patch.

Regards,
Arnout

Quoted 3 lines
toolchain/helpers.mk +0 -0
  		printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
  			"$${expected_version}" "$${real_version}" ; \